diff options
Diffstat (limited to 'tools/feed-long-note-test.js')
| -rw-r--r-- | tools/feed-long-note-test.js | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/tools/feed-long-note-test.js b/tools/feed-long-note-test.js new file mode 100644 index 0000000..cfac264 --- /dev/null +++ b/tools/feed-long-note-test.js @@ -0,0 +1,85 @@ +// A REALLY long note is collapsed in the feed with Show more under it. +// "could you collapse REALLY long notes, with a 'more...' link to expand if +// the user wants to read them. I follow ZeroHedge News ... and their notes +// are huge!" (npub1muckyme in the coinos community, 2026-11-30). A short note +// is left alone; Show more opens the long one in place (not its thread); +// the thread shows it whole. +// Run: bun tools/feed-long-note-test.js +import puppeteer, { seedWords, skipSeedCheck } from './puppeteer.js'; +import { cacheKeyFor } from '../src/wallet.js'; +import { generateSecretKey, getPublicKey, finalizeEvent } from 'nostr-tools/pure'; +import { buildHtml } from '../build.js'; +const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); +let ok = true; +const check = (n, c, d = '') => { console.log(` ${c ? '✓' : '✗'} ${n}${d ? ' — ' + d : ''}`); if (!c) ok = false; }; +const key = () => { const sk = generateSecretKey(); return { sk, pk: getPublicKey(sk) }; }; +const AUTHOR = key(), FRIEND = key(); +const now = Math.floor(Date.now() / 1000); +const para = (i) => `Paragraph ${i}: markets moved sharply today as traders digested a flood of new data, and analysts warned that volatility could persist well into next week.`; +const LONG = finalizeEvent({ kind: 1, created_at: now - 100, tags: [], content: 'LONGSTART ' + Array.from({ length: 14 }, (_, i) => para(i + 1)).join('\n\n') + ' LONGEND' }, AUTHOR.sk); +const SHORT = finalizeEvent({ kind: 1, created_at: now - 50, tags: [], content: 'a short one, gm' }, FRIEND.sk); +const html = await buildHtml({ minify: true, pwa: false }); +const server = Bun.serve({ port: 5351, fetch: (req) => { const p = new URL(req.url).pathname; if (p === '/verify-worker.js' || p.startsWith('/punks')) return new Response(Bun.file('dist' + p)); return new Response(html, { headers: { 'content-type': 'text/html' } }); } }); +const browser = await puppeteer.launch({ executablePath: '/usr/bin/google-chrome', headless: 'new', args: ['--no-sandbox'] }); +const page = await browser.newPage(); +await page.evaluateOnNewDocument(() => { + const Real = window.WebSocket; + window.WebSocket = function (...a) { const ws = new Real(...a); const send = ws.send.bind(ws); ws.send = (d) => { try { const m = JSON.parse(d); if (m[0] === 'REQ') { setTimeout(() => ws.dispatchEvent(new MessageEvent('message', { data: JSON.stringify(['EOSE', m[1]]) })), 0); return; } if (m[0] === 'EVENT') return; } catch {} return send(d); }; return ws; }; + window.WebSocket.prototype = Real.prototype; Object.assign(window.WebSocket, Real); +}); +const errs = []; +page.on('pageerror', (e) => errs.push(String(e))); +const click = (t) => page.evaluate((x) => { const e = [...document.querySelectorAll('button')].find((n) => n.textContent.trim().toLowerCase().includes(x)); if (e) { e.click(); return true; } return false; }, t); +const waitText = async (x, ms = 25000) => { for (let i = 0; i < ms / 250; i++) { if ((await page.evaluate(() => document.body.innerText)).includes(x)) return true; await sleep(250); } return false; }; +try { + await page.setViewport({ width: 390, height: 844 }); + await page.goto('http://localhost:5351/', { waitUntil: 'domcontentloaded' }); + await page.evaluate(() => localStorage.setItem('btc-wallet-network', 'regtest')); + await page.reload({ waitUntil: 'domcontentloaded' }); await sleep(400); + await click('create a new wallet'); await sleep(600); + await seedWords(page); + const mn = (await page.$$eval('.words .w .t', (l) => l.map((e) => e.textContent.trim()))).join(' '); + await skipSeedCheck(page); + await waitText('Receive', 20000); + const base = cacheKeyFor(mn + '\n'); + await page.evaluate(([k, a, f, ns]) => { + localStorage.setItem(k + ':follows', JSON.stringify({ tags: [['p', a], ['p', f]], c: '', at: Math.floor(Date.now() / 1000) })); + localStorage.setItem(k + ':feedNotes', JSON.stringify(ns)); + localStorage.setItem(k + ':profiles', JSON.stringify({ [a]: { name: 'Hedgie', t: Date.now() }, [f]: { name: 'Friendly', t: Date.now() } })); + localStorage.setItem('btc-wallet-feed:' + k, 'following'); + }, [base, AUTHOR.pk, FRIEND.pk, [SHORT, LONG]]); + await page.reload({ waitUntil: 'domcontentloaded' }); + await waitText('Receive', 20000); + await page.evaluate(() => document.querySelector('.app-nav-button[aria-label="Feed"]')?.click()); + check('the feed shows both posts', await waitText('a short one, gm', 15000) && await waitText('LONGSTART', 5000)); + const state = () => page.evaluate((id) => { + const row = document.querySelector(`[data-zap-post="${id}"]`); + const txt = row?.querySelector('.note-text'); + return { clamped: !!row?.querySelector('.note-clamped'), more: !!row?.querySelector('.note-more'), h: txt ? txt.getBoundingClientRect().height : 0, full: txt ? txt.scrollHeight : 0 }; + }, LONG.id); + const s1 = await state(); + check('the long note is collapsed', s1.clamped && s1.h < s1.full * 0.6, JSON.stringify(s1)); + check('...about ten lines tall', s1.h > 200 && s1.h < 300, String(s1.h)); + check('...with Show more under it', s1.more); + if (process.env.SHOT) { await page.evaluate((id) => document.querySelector(`[data-zap-post="${id}"]`).scrollIntoView(), LONG.id); await sleep(300); await page.screenshot({ path: process.env.SHOT }); } + const short = await page.evaluate((id) => !!document.querySelector(`[data-zap-post="${id}"] .note-clamped, [data-zap-post="${id}"] .note-more`), SHORT.id); + check('the short note is left alone', !short); + await page.evaluate((id) => document.querySelector(`[data-zap-post="${id}"] .note-more`).click(), LONG.id); + await sleep(700); + const s2 = await state(); + check('Show more opens it in place', !s2.clamped && !s2.more && s2.h >= s2.full - 2, JSON.stringify(s2)); + check('...without opening its thread', !(await page.evaluate(() => location.pathname)).includes('nevent'), await page.evaluate(() => location.pathname)); + // the thread: whole, no Show more + await page.reload({ waitUntil: 'domcontentloaded' }); + await waitText('Receive', 20000); + await page.evaluate(() => document.querySelector('.app-nav-button[aria-label="Feed"]')?.click()); + await waitText('LONGSTART', 15000); + check('collapsed again after a reload', (await state()).clamped); + await page.evaluate((id) => document.querySelector(`[data-zap-post="${id}"] .note-header`).click(), LONG.id); + await sleep(1500); + const inThread = await page.evaluate((id) => { const rows = [...document.querySelectorAll(`[data-zap-post="${id}"]`)]; const r = rows[rows.length - 1]; return { n: rows.length, clamped: !!r?.querySelector('.note-clamped'), path: location.pathname }; }, LONG.id); + check('its thread shows it whole', inThread.n > 0 && !inThread.clamped && inThread.path.includes('nevent') || inThread.path.includes('note1'), JSON.stringify(inThread)); + check('no page errors', errs.length === 0, errs.slice(0, 2).join(' | ')); +} finally { await browser.close(); server.stop(true); } +console.log(ok ? '\n✅ really long notes collapse' : '\n❌ failed'); +process.exit(ok ? 0 : 1); |
