diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/boot-signin-flash-test.js | 26 | ||||
| -rw-r--r-- | tools/thread-cache-test.js | 7 | ||||
| -rw-r--r-- | tools/thread-reply-test.js | 15 |
3 files changed, 46 insertions, 2 deletions
diff --git a/tools/boot-signin-flash-test.js b/tools/boot-signin-flash-test.js index b3460ca..6e22ebb 100644 --- a/tools/boot-signin-flash-test.js +++ b/tools/boot-signin-flash-test.js @@ -62,6 +62,32 @@ try { console.log(` ${clean ? '✓' : '✗'} reload ${i}: wallet at ${r.wallet}ms${r.signin != null ? `, sign-in page flashed at ${r.signin}ms` : ', no sign-in flash'}`); if (!clean) ok = false; } + const rootId = 'c'.repeat(64), replyId = 'd'.repeat(64), author = 'a'.repeat(64); + await page.evaluate(({ rootId, replyId, author }) => { + const root = { id: rootId, pubkey: author, kind: 1, content: 'Cached thread root', tags: [], created_at: 1 }; + const reply = { ...root, id: replyId, content: 'Cached thread reply', tags: [['e', rootId, '', 'root']], created_at: 2 }; + localStorage.setItem('btc-wallet-note-threads', JSON.stringify([{ rootId, root, replies: [reply], profiles: {}, counts: {} }])); + const nav = { ...history.state.nav, screen: 'wallet', noteThread: { rootId, focusId: replyId, seed: reply } }; + history.replaceState({ nav, i: 0 }, '', location.href); + }, { rootId, replyId, author }); + await page.evaluateOnNewDocument(() => { + window.__threadBoot = { homeFrames: 0, animatedFrames: 0, threadAt: null }; + const tick = () => { + const state = window.__threadBoot; + if (document.querySelector('.balance')) state.homeFrames++; + const thread = document.querySelector('.thread-page'); + if (thread?.classList.contains('anim-page')) state.animatedFrames++; + if (thread) state.threadAt ??= Math.round(performance.now()); + if (state.threadAt == null || performance.now() - state.threadAt < 500) requestAnimationFrame(tick); + }; + requestAnimationFrame(tick); + }); + await page.reload({ waitUntil: 'domcontentloaded' }); + await sleep(1200); + const thread = await page.evaluate(() => window.__threadBoot); + const steady = thread.threadAt != null && !thread.homeFrames && !thread.animatedFrames; + console.log(` ${steady ? '✓' : '✗'} thread reload: ${thread.homeFrames} home frames, ${thread.animatedFrames} page animation frames`); + if (!steady) ok = false; } finally { await browser.close(); server.stop(true); } console.log(ok ? '\n✅ no sign-in flash' : '\n❌ the sign-in page flashed'); process.exit(ok ? 0 : 1); diff --git a/tools/thread-cache-test.js b/tools/thread-cache-test.js index 14e5da6..485e874 100644 --- a/tools/thread-cache-test.js +++ b/tools/thread-cache-test.js @@ -19,7 +19,7 @@ check('a fresh store restores full content and tags by any viewed event', () => const long = { ...reply, content: 'x'.repeat(5000), tags: [...reply.tags, ['emoji', 'wave', 'https://example.com/wave.png']] }; store.save({ root, replies: [parent, long] }, long.id); const restored = createThreadStore(storage).find(long.id); - assert.deepEqual(restored, { rootId: root.id, root, profiles: {}, replies: [long, parent] }); + assert.deepEqual(restored, { rootId: root.id, root, profiles: {}, counts: {}, replies: [long, parent] }); assert.equal(store.find(parent.id).root.id, root.id); }); check('thread authors keep their names and local avatar thumbnails across reloads', () => { @@ -31,6 +31,11 @@ check('thread authors keep their names and local avatar thumbnails across reload assert.deepEqual(createThreadStore(storage).find(reply.id).profiles[root.pubkey], { ...face, t: 0 }); }); +check('thread action totals are present before relay refresh and survive a context save', () => { + store.save({ root, replies: [parent, reply] }, reply.id, {}, { [reply.id]: { likes: 29, boosts: 7, sats: 210 } }); + store.save({ root, replies: [parent, reply] }, reply.id); + assert.deepEqual(createThreadStore(storage).find(reply.id).counts[reply.id], { likes: 29, boosts: 7, sats: 210 }); +}); check('a large thread retains the selected reply and its ancestors', () => { const siblings = Array.from({ length: 200 }, (_, i) => note(1000 + i, [['e', root.id, '', 'root']])); store.save({ root, replies: [...siblings, parent, reply] }, reply.id); diff --git a/tools/thread-reply-test.js b/tools/thread-reply-test.js index 39f2894..3dba87f 100644 --- a/tools/thread-reply-test.js +++ b/tools/thread-reply-test.js @@ -28,7 +28,7 @@ window.test = { ui, reply, other, root, render, waiting, seedFace: () => createThreadStore().save({ root, replies: [reply] }, reply.id, { [author]: { name: 'Nostrich', picture: 'https://example.com/nostrich.webp', eventAt: 10, t: Date.now(), thumbFor: 'https://example.com/nostrich.webp', thumb: 'data:image/png;base64,iVBORw0KGgo=', thumbPx: 144 }, - }), + }, { [reply.id]: { likes: 29, boosts: 7, sats: 210 } }), release: () => { for (const q of waiting.splice(0)) q.resolve(q.filter.ids ? [root] : []); }, overlay: () => { ui.profilePk = author; ui.profOverThread = true; render(); @@ -101,6 +101,19 @@ try { const row = document.querySelector('.thread-page [data-zap-post]'); return row?.textContent.includes('Nostrich') && row.querySelector('.note-avatar.ava-img')?.style.backgroundImage.includes('data:image/png;base64'); })); + check('cached likes, boosts and sats paint before relay replies', await page.evaluate(() => { + const row = [...document.querySelectorAll('.thread-page [data-zap-post]')] + .find((el) => el.dataset.zapPost === test.reply.id); + const buttons = row?.querySelectorAll('.note-acts > button'); + return buttons?.[1].textContent === '7' && buttons?.[3].textContent === '29' && buttons?.[4].textContent === '210'; + })); + await new Promise((r) => setTimeout(r, 450)); + check('an incomplete relay tally cannot erase the cached numbers', await page.evaluate(() => { + const row = [...document.querySelectorAll('.thread-page [data-zap-post]')] + .find((el) => el.dataset.zapPost === test.reply.id); + const buttons = row?.querySelectorAll('.note-acts > button'); + return buttons?.[1].textContent === '7' && buttons?.[3].textContent === '29' && buttons?.[4].textContent === '210'; + })); assert.deepEqual(errors, []); console.log('✓ no browser errors'); } finally { await browser.close(); server.stop(true); } |
