aboutsummaryrefslogtreecommitdiffstats
path: root/tools/quote-card-test.js
diff options
context:
space:
mode:
Diffstat (limited to 'tools/quote-card-test.js')
-rw-r--r--tools/quote-card-test.js38
1 files changed, 32 insertions, 6 deletions
diff --git a/tools/quote-card-test.js b/tools/quote-card-test.js
index 27a1b22..d2d7d7e 100644
--- a/tools/quote-card-test.js
+++ b/tools/quote-card-test.js
@@ -25,11 +25,24 @@ const found = await pool.querySync(['wss://relay.primal.net', 'wss://nos.lol'],
const target = (found || []).filter((e) => e.content && e.content.length > 20)[0];
if (!target) { console.log(' ✗ no note to quote (relays quiet)'); process.exit(1); }
const nevent = neventOf(target.id, target.pubkey);
+const FAR = 'nevent1qvzqqqqqqypzqntcggz30qhq60ltqdx32zku9d46unhrkjtcv7fml7jx3dh4h94nqqsqchs0pz4hnqm6jurakjwcd6wcrph7wyy80j0ljup68p4hynvsz3q3nhre2';
const html = await buildHtml({ minify: true, pwa: false });
const server = Bun.serve({ port: 5269, fetch: () => 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();
+// --slow: the relays miss the quoted note the first time it is asked for
+// (ours was down for an evening once), so the row freezes with the fallback
+// link; the next ask, half a minute on, finds it.
+const SLOW_MS = 32000;
+await page.evaluateOnNewDocument((id) => {
+ const send = WebSocket.prototype.send;
+ const t0 = Date.now();
+ WebSocket.prototype.send = function (d) {
+ if (localStorage.getItem('__slowQuote') && typeof d === 'string' && d.includes(id) && d.startsWith('["REQ"') && Date.now() - t0 < 20000) return;
+ return send.call(this, d);
+ };
+}, target.id);
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)).toLowerCase().includes(x)) return true; await sleep(250); } return false; };
try {
@@ -47,18 +60,26 @@ try {
await waitText('receive', 20000);
const base = cacheKeyFor(mn + '\n');
const A = 'a'.repeat(63) + '9';
- await page.evaluate(([k, pk, ref]) => {
+ await page.evaluate(([k, pk, ref, FAR]) => {
localStorage.setItem(k + ':follows', JSON.stringify({ tags: [['p', pk]], c: '', at: Math.floor(Date.now()/1000) }));
localStorage.setItem(k + ':feedNotes', JSON.stringify([
{ id: 'd'.repeat(64), pubkey: pk, kind: 1, created_at: Math.floor(Date.now()/1000), content: 'what he said nostr:' + ref, tags: [] },
+ // quotes a note that sits only on nostr.mom — not in the reference, not in its author's relay list
+ { id: 'e'.repeat(64), pubkey: pk, kind: 1, created_at: Math.floor(Date.now()/1000) - 60, content: 'I remember this.\n\nnostr:' + FAR, tags: [] },
]));
- }, [base, A, nevent]);
+ localStorage.setItem(k + ':profiles', JSON.stringify({ [pk]: { name: 'Quoter', t: Date.now() } }));
+ }, [base, A, nevent, FAR]);
+ if (process.argv.includes('--slow')) await page.evaluate(() => localStorage.setItem('__slowQuote', '1'));
await page.reload({ waitUntil: 'domcontentloaded' });
await waitText('receive', 20000);
- await page.evaluate(() => { const b = [...document.querySelectorAll('button')].find((e) => /message/i.test(e.getAttribute('aria-label') || '')); if (b) b.click(); });
- await sleep(1000);
- await page.evaluate(() => { const e = [...document.querySelectorAll('.item')].find((n) => /feed/i.test(n.textContent)); if (e) e.click(); });
+ await page.evaluate(() => document.querySelector('.app-bottom-nav .app-nav-button').click());
await sleep(7000);
+ if (process.argv.includes('--slow')) {
+ for (let i = 0; i < 40 && !(await page.evaluate(() => !!document.querySelector('.quote-card'))); i++) await sleep(250);
+ check('a late quote first paints as a placeholder card, not a link', await page.evaluate(() => !document.body.innerText.includes('view note')
+ && [...document.querySelectorAll('.quote-card')].some((q) => /Couldn.t find|Fetching note/.test(q.innerText))));
+ await sleep(SLOW_MS + 4000);
+ }
const card = await page.evaluate(() => {
const q = document.querySelector('.quote-card');
@@ -70,7 +91,12 @@ try {
check('...with whose note it is', !!(card && card.hasAvatar), card ? card.text.slice(0, 50) : '');
const body = target.content.replace(/\s+/g, ' ').slice(0, 24);
check('...and what it actually said', !!(card && card.text.replace(/\s+/g, ' ').includes(body.slice(0, 18))), body);
- check('no "view note" link left in the post', !(await page.evaluate(() => document.body.innerText)).includes('view note'));
+ if (!process.argv.includes('--slow')) {
+ const far = await page.evaluate(() => { const r = [...document.querySelectorAll('.notes-feed [data-key]')].find((n) => n.innerText.includes('Quoter') && n.innerText.includes('I remember this')); return r && r.querySelector('.quote-card')?.innerText; });
+ check('a quote found only on a far relay still shows as its card', !!far && !/Couldn.t find|Fetching/.test(far), JSON.stringify((far || '').slice(0, 60)));
+ }
+ // (a quote inside a quote stays a link on purpose: one level of cards)
+ check('no "view note" link left in the post', !(await page.evaluate(() => [...document.querySelectorAll('.notes-feed a')].some((a) => a.textContent === 'view note' && !a.closest('.quote-card')))));
// the outer post keeps its actions; the quote has none of its own
const acts = await page.evaluate(() => ({
outer: document.querySelectorAll('.notes-feed > .row .note-acts').length,