aboutsummaryrefslogtreecommitdiffstats
path: root/tools/feed-pager-ahead-test.js
diff options
context:
space:
mode:
Diffstat (limited to 'tools/feed-pager-ahead-test.js')
-rw-r--r--tools/feed-pager-ahead-test.js19
1 files changed, 15 insertions, 4 deletions
diff --git a/tools/feed-pager-ahead-test.js b/tools/feed-pager-ahead-test.js
index b5a20ba..504c122 100644
--- a/tools/feed-pager-ahead-test.js
+++ b/tools/feed-pager-ahead-test.js
@@ -1,5 +1,5 @@
// Swiping through the feed's pictures (or clips) in the pager is scrolling
-// the feed: with three slides or fewer left past the one on screen, the
+// the feed: with four slides or fewer left past the one on screen (six for clips), the
// feed pages on, and the pager grows — past a run of posts with nothing to
// show, too — so the reader never meets the end while there is more.
// Run: bun tools/feed-pager-ahead-test.js
@@ -28,7 +28,7 @@ const U = (n) => server.url.origin + '/p' + n + '.png';
const seeded = [];
let ago = 100, pic = 0;
for (let i = 0; i < 12; i++) seeded.push(post('picture number ' + pic + ' ' + U(pic++), ago += 60));
-for (let i = 0; i < 15; i++) seeded.push(post('just words ' + i + ' ' + 'lorem ipsum dolor sit amet. '.repeat(3), ago += 60));
+for (let i = 0; i < 15; i++) seeded.push(post('just words ' + i + ' ' + 'lorem ipsum dolor sit amet. '.repeat(i % 3 ? 3 : 90), ago += 60)); // some of them long: rows of very different heights
for (let i = 0; i < 14; i++) seeded.push(post('picture number ' + pic + ' ' + U(pic++), ago += 60));
const TOTAL = pic;
@@ -126,9 +126,9 @@ try {
for (let step = 0; step < TOTAL + 4; step++) {
const n = await slides(), i = await curIdx();
maxSlides = Math.max(maxSlides, n);
- if (i >= 0 && n - 1 - i <= 3) {
+ if (i >= 0 && n - 1 - i <= 4) {
// give the look-ahead a moment: it should get past three ahead again (or the feed's end)
- await waitFor((k) => { const sc = document.querySelector('.mp-scroll'); const j = [...sc.children].findIndex((x) => Math.abs(x.offsetTop - sc.scrollTop) < 4); return sc.children.length - 1 - j > 3 || sc.children.length >= k; }, TOTAL, 6000);
+ await waitFor((k) => { const sc = document.querySelector('.mp-scroll'); const j = [...sc.children].findIndex((x) => Math.abs(x.offsetTop - sc.scrollTop) < 4); return sc.children.length - 1 - j > 4 || sc.children.length >= k; }, TOTAL, 6000);
}
const before = await curIdx();
await page.keyboard.press('ArrowDown');
@@ -139,6 +139,17 @@ try {
check('every picture in the feed became reachable', (await slides()) === TOTAL, (await slides()) + ' of ' + TOTAL);
check('…past fifteen posts with none', (await curName()) === 'p' + (TOTAL - 1) + '.png', await curName());
check('…in the feed\'s order', await page.evaluate((t) => [...document.querySelector('.mp-scroll').children].every((s, i) => s.getAttribute('data-k').endsWith('/p' + i + '.png')), TOTAL));
+
+ console.log('\n[closing lands the feed on the last picture\'s post]');
+ await page.keyboard.press('ArrowUp');
+ await waitFor((n) => { const sc = document.querySelector('.mp-scroll'); const s = [...sc.children].find((x) => Math.abs(x.offsetTop - sc.scrollTop) < 4); return s && s.getAttribute('data-k').endsWith('/p' + n + '.png'); }, TOTAL - 2, 3000);
+ const want = 'picture number ' + (TOTAL - 2) + ' ';
+ await page.keyboard.press('Escape');
+ check('the pager closes', await waitFor(() => !document.querySelector('.media-pager') && !!document.querySelector('.notes-feed'), null, 3000));
+ const top = () => page.evaluate((w) => { const r = [...document.querySelectorAll('.notes-feed > [data-key]')].find((n) => n.textContent.includes(w)); return r ? Math.round(r.getBoundingClientRect().top) : null; }, want);
+ await sleep(2500); // the pictures above it load meanwhile
+ const t = await top();
+ check('…the feed sits on the post of the picture last looked at', t !== null && t >= -10 && t < 120, 'row top ' + t);
check('no page errors', errs.length === 0, errs.slice(0, 2).join(' | '));
} finally { await browser.close(); server.stop(true); }
console.log(ok ? '\n✅ the pager pages the feed on ahead of the reader' : '\n❌ failed');