aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/link-preview-test.js31
1 files changed, 29 insertions, 2 deletions
diff --git a/tools/link-preview-test.js b/tools/link-preview-test.js
index fb83dae..3b2aad3 100644
--- a/tools/link-preview-test.js
+++ b/tools/link-preview-test.js
@@ -20,6 +20,7 @@ const POSTS = [
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),
+ finalizeEvent({ kind: 1, created_at: now - 150, tags: [], content: 'on repeat https://paff.club/song/abc123' }, AUTHOR),
];
const PROFILE = finalizeEvent({ kind: 0, created_at: now - 100, tags: [], content: JSON.stringify({ name: 'Linker', picture: 'http://localhost:5311/face.png' }) }, AUTHOR);
@@ -33,6 +34,8 @@ const server = Bun.serve({ port: 5311, fetch: (req) => {
? { 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.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' }
+ : target === 'https://paff.club/song/abc123'
+ ? { url: target, title: 'Halcyon · Orbital', description: 'Orbital 2 · 1993', image: 'http://localhost:5311/cover.png', site: 'PAFF' }
: {};
return new Response(JSON.stringify(meta), { headers: { 'content-type': 'application/json', 'access-control-allow-origin': '*' } });
}
@@ -159,10 +162,34 @@ try {
for (let i = 0; i < 20 && !paffLog.includes('play'); i++) await sleep(150);
check('...and carries on when it comes back', paffLog.join() === 'pause,play', JSON.stringify(paffLog));
await page.evaluate(() => { document.getElementById('pad')?.remove(); scrollTo(0, 0); });
+ // a PAFF song plays in the bar above the nav, and keeps playing as you go
+ const song = await page.evaluate(() => {
+ const c = document.querySelector('.paff-song');
+ return c && { title: c.querySelector('.paff-song-title')?.textContent, cover: !!c.querySelector('img.paff-song-cover'), frame: !!c.querySelector('iframe') };
+ });
+ check('a PAFF song link is a card with its cover and title', !!song && song.cover && song.title === 'Halcyon · Orbital' && !song.frame, JSON.stringify(song));
+ await page.evaluate(() => { const c = document.querySelector('.paff-song'); c.scrollIntoView({ block: 'center' }); c.click(); });
+ await sleep(300);
+ const bar = await page.evaluate(() => {
+ const b = document.querySelector('.music-bar'), f = b?.querySelector('iframe'), nav = document.querySelector('.app-bottom-nav');
+ const r = b?.getBoundingClientRect(), n = nav?.getBoundingClientRect();
+ return b && { src: f?.getAttribute('src'), above: !n || r.bottom <= n.top + 1, playing: document.querySelector('.paff-song')?.textContent.includes('Playing below') };
+ });
+ check('a tap plays it in the bar above the nav', !!bar && bar.src === 'https://paff.club/embed/song/abc123?bar=1' && bar.above, JSON.stringify(bar));
+ check('...and the card says it is playing', !!bar?.playing);
+ if (process.env.SHOT) await page.screenshot({ path: process.env.SHOT });
+ await page.evaluate(() => document.querySelector('.app-nav-button[aria-label="Wallet"]')?.click());
+ await sleep(500);
+ const still = await page.evaluate(() => document.querySelector('.music-bar iframe')?.getAttribute('src'));
+ check('the song carries on on another page', still === 'https://paff.club/embed/song/abc123?bar=1', still);
+ await page.evaluate(() => document.querySelector('.music-close').click());
+ check('× stops and closes it', await page.evaluate(() => !document.querySelector('.music-bar') && !document.body.classList.contains('music-open')));
+ await page.evaluate(() => document.querySelector('.app-nav-button[aria-label="Feed"]').click());
+ await sleep(500);
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 < 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
+ for (let i = 0; i < 12 && kept < 3; i++) { kept = await page.evaluate(() => JSON.parse((window.coinosCache || localStorage).getItem('coinos-link-previews') || '[]').length); if (kept < 3) await sleep(300); }
+ check('the cards are remembered for next time', kept === 3, kept + ' kept'); // the story's, the film's and the song'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; });