diff options
Diffstat (limited to 'tools/link-preview-test.js')
| -rw-r--r-- | tools/link-preview-test.js | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/tools/link-preview-test.js b/tools/link-preview-test.js index bf68bbc..a780c73 100644 --- a/tools/link-preview-test.js +++ b/tools/link-preview-test.js @@ -19,6 +19,7 @@ const POSTS = [ finalizeEvent({ kind: 1, created_at: now - 30, tags: [], content: 'Well, yeah https://news.example/story/1' }, AUTHOR), finalizeEvent({ kind: 1, created_at: now - 60, tags: [], content: 'nothing here https://blank.example/page' }, AUTHOR), finalizeEvent({ kind: 1, created_at: now - 90, tags: [], content: 'a picture http://localhost:5311/pic.png' }, AUTHOR), + finalizeEvent({ kind: 1, created_at: now - 120, tags: [], content: 'film night https://paff.club/movie/1382-hackers-1995/play?q=1080p&t=4910' }, AUTHOR), ]; const PROFILE = finalizeEvent({ kind: 0, created_at: now - 100, tags: [], content: JSON.stringify({ name: 'Linker', picture: 'http://localhost:5311/face.png' }) }, AUTHOR); @@ -30,7 +31,7 @@ const server = Bun.serve({ port: 5311, fetch: (req) => { const target = u.searchParams.get('url'); previewHits.push(target); const meta = target === 'https://news.example/story/1' ? { url: target, title: 'Lawmakers doubt the plan', description: 'A story in one line.', image: 'http://localhost:5311/card.png', site: 'News Example' } - : target === 'https://movies.example/movie/1382/play?t=4910' + : target === 'https://movies.example/movie/1382/play?t=4910' || target.startsWith('https://paff.club/movie/1382') ? { url: target, title: 'Hackers (1995) · from 1:21:50', description: 'Teenage hackers.', image: 'http://localhost:5311/movie.png', site: 'PAFF' } : {}; return new Response(JSON.stringify(meta), { headers: { 'content-type': 'application/json', 'access-control-allow-origin': '*' } }); @@ -115,10 +116,25 @@ try { check('...and its picture, already decoded', !!story?.thumb && story.thumbShown, JSON.stringify({ thumb: story?.thumb, shown: story?.thumbShown })); check('a page with nothing to show stays a bare link', !!blank && blank.bareLink && !blank.card, JSON.stringify(blank)); check('a picture link is still a picture, not a card', !!pic && pic.img && !pic.card, JSON.stringify(pic)); + // a PAFF film link plays in the post, PAFF's bare player loaded only on a tap + const paff = await page.evaluate(() => { + const r = [...document.querySelectorAll('.notes-feed > .row')].find((n) => /film night/.test(n.textContent)); + const b = r && r.querySelector('.paff-embed'); + return b && { title: b.querySelector('.paff-title')?.textContent, poster: !!b.querySelector('img.yt-poster'), frame: !!b.querySelector('iframe') }; + }); + check('a PAFF film link shows as a player with its backdrop and title', !!paff && paff.poster && /Hackers/.test(paff.title || '') && !paff.frame, JSON.stringify(paff)); + const src = await page.evaluate(() => { + const b = [...document.querySelectorAll('.paff-embed')][0]; + b.querySelector('.yt-play').click(); + const f = b.querySelector('iframe'), s = f && f.getAttribute('src'); + if (f) f.src = 'about:blank'; // (the test doesn't stream the film) + return s; + }); + check('...and a tap loads PAFF\'s embed player there, the link\'s query kept', src === 'https://paff.club/embed/movie/1382-hackers-1995?q=1080p&t=4910', src); check('the registrar was asked once per link', previewHits.filter((u) => u === 'https://news.example/story/1').length === 1 && !previewHits.some((u) => u.endsWith('.png')), JSON.stringify(previewHits)); let kept = 0; // written behind, a second after the card was learned - for (let i = 0; i < 12 && !kept; i++) { kept = await page.evaluate(() => JSON.parse((window.coinosCache || localStorage).getItem('coinos-link-previews') || '[]').length); if (!kept) await sleep(300); } - check('the card is remembered for next time', kept === 1, kept + ' kept'); + for (let i = 0; i < 12 && kept < 2; i++) { kept = await page.evaluate(() => JSON.parse((window.coinosCache || localStorage).getItem('coinos-link-previews') || '[]').length); if (kept < 2) await sleep(300); } + check('the cards are remembered for next time', kept === 2, kept + ' kept'); // the story's and the film's // a draft's preview shows the card too (Adam, 2026-11-17: a paff.club // movie link stayed a bare URL in Preview), once the typing settles const opened = await page.evaluate(() => { const b = [...document.querySelectorAll('button')].find((n) => (n.getAttribute('aria-label') || n.textContent).trim().toLowerCase() === 'new post'); if (b) { b.click(); return true; } return false; }); |
