mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
at rm-proxy 134 lines 5.1 kB view raw
1import {extractHtmlMeta} from '../../src/lib/link-meta/html' 2import {exampleComHtml} from './__mocks__/exampleComHtml' 3import {youtubeHTML} from './__mocks__/youtubeHtml' 4import {tiktokHtml} from './__mocks__/tiktokHtml' 5import {youtubeChannelHtml} from './__mocks__/youtubeChannelHtml' 6 7describe('extractHtmlMeta', () => { 8 const cases = [ 9 ['', {}], 10 ['nothing', {}], 11 ['<title>title</title>', {title: 'title'}], 12 ['<title> aSd!@#AC </title>', {title: 'aSd!@#AC'}], 13 ['<title>\n title\n </title>', {title: 'title'}], 14 ['<meta name="title" content="meta title">', {title: 'meta title'}], 15 [ 16 '<meta name="description" content="meta description">', 17 {description: 'meta description'}, 18 ], 19 ['<meta property="og:title" content="og title">', {title: 'og title'}], 20 [ 21 '<meta property="og:description" content="og description">', 22 {description: 'og description'}, 23 ], 24 [ 25 '<meta property="og:image" content="https://ogimage.com/foo.png">', 26 {image: 'https://ogimage.com/foo.png'}, 27 ], 28 [ 29 '<meta property="twitter:title" content="twitter title">', 30 {title: 'twitter title'}, 31 ], 32 [ 33 '<meta property="twitter:description" content="twitter description">', 34 {description: 'twitter description'}, 35 ], 36 [ 37 '<meta property="twitter:image" content="https://twitterimage.com/foo.png">', 38 {image: 'https://twitterimage.com/foo.png'}, 39 ], 40 ['<meta\n name="title"\n content="meta title"\n>', {title: 'meta title'}], 41 ] 42 43 it.each(cases)( 44 'given the html tag %p, returns %p', 45 // @ts-ignore not worth fixing -prf 46 (input, expectedResult) => { 47 const output = extractHtmlMeta({html: input as string, hostname: ''}) 48 expect(output).toEqual(expectedResult) 49 }, 50 ) 51 52 it('extracts title and description from a generic HTML page', () => { 53 const input = exampleComHtml 54 const expectedOutput = { 55 title: 'Example Domain', 56 description: 'An example website', 57 } 58 const output = extractHtmlMeta({html: input, hostname: 'example.com'}) 59 expect(output).toEqual(expectedOutput) 60 }) 61 62 it('extracts title and description from a Tiktok HTML page', () => { 63 const input = tiktokHtml 64 const expectedOutput = { 65 title: 66 'Coca-Cola and Mentos! Super Reaction! #cocacola #mentos #reaction #bal... | TikTok', 67 description: 68 '5.5M Likes, 20.8K Comments. TikTok video from Power Vision Tests (@_powervision_): &quot;Coca-Cola and Mentos! Super Reaction! #cocacola #mentos #reaction #balloon #sciencemoment #scienceexperiment #experiment #test #amazing #pvexp&quot;. оригинальный звук - Power Vision Tests.', 69 } 70 const output = extractHtmlMeta({html: input, hostname: 'tiktok.com'}) 71 expect(output).toEqual(expectedOutput) 72 }) 73 74 it('extracts title and description from a generic youtube page', () => { 75 const input = youtubeHTML 76 const expectedOutput = { 77 title: 'HD Video (1080p) with Relaxing Music of Native American Shamans', 78 description: 79 'Stunning HD Video ( 1080p ) of Patagonian Nature with Relaxing Native American Shamanic Music. HD footage used from ', 80 image: 'https://i.ytimg.com/vi/x6UITRjhijI/sddefault.jpg', 81 } 82 const output = extractHtmlMeta({html: input, hostname: 'youtube.com'}) 83 expect(output).toEqual(expectedOutput) 84 }) 85 86 it('extracts avatar from a youtube channel', () => { 87 const input = youtubeChannelHtml 88 const expectedOutput = { 89 title: 'penguinz0', 90 description: 91 'Clips channel: https://www.youtube.com/channel/UC4EQHfzIbkL_Skit_iKt1aA\n\nTwitter: https://twitter.com/MoistCr1TiKaL\n\nInstagram: https://www.instagram.com/bigmoistcr1tikal/?hl=en\n\nTwitch: https://www.twitch.tv/moistcr1tikal\n\nSnapchat: Hugecharles\n\nTik Tok: Hugecharles\n\nI don&#39;t have any other public accounts.', 92 image: 93 'https://yt3.googleusercontent.com/ytc/AL5GRJWOhJOuUC6C2b7gP-5D2q6ypXbcOOckyAE1En4RUQ=s176-c-k-c0x00ffffff-no-rj', 94 } 95 const output = extractHtmlMeta({html: input, hostname: 'youtube.com'}) 96 expect(output).toEqual(expectedOutput) 97 }) 98 99 it('extracts username from the url a twitter profile page', () => { 100 const expectedOutput = { 101 title: '@bluesky on Twitter', 102 } 103 const output = extractHtmlMeta({ 104 html: '', 105 hostname: 'twitter.com', 106 pathname: '/bluesky', 107 }) 108 expect(output).toEqual(expectedOutput) 109 }) 110 111 it('extracts username from the url a tweet', () => { 112 const expectedOutput = { 113 title: 'Tweet by @bluesky', 114 } 115 const output = extractHtmlMeta({ 116 html: '', 117 hostname: 'twitter.com', 118 pathname: '/bluesky/status/1582437529969917953', 119 }) 120 expect(output).toEqual(expectedOutput) 121 }) 122 123 it("does not extract username from the url when it's not a tweet or profile page", () => { 124 const expectedOutput = { 125 title: 'Twitter', 126 } 127 const output = extractHtmlMeta({ 128 html: '', 129 hostname: 'twitter.com', 130 pathname: '/i/articles/follows/-1675653703?time_window=24', 131 }) 132 expect(output).toEqual(expectedOutput) 133 }) 134})