test(tagging): wait for in-flight pages before reading the loaded range

The scroll-position test read the loaded count right after scrolling the
continuation out of view, while a listing page the continuation had
already requested could still be in flight. When it landed the count
grew (80 -> 120 in CI) and the stability poll failed. The test now waits
a frame for any scheduled load to start and then for every listing
request to finish before it reads the count.
This commit is contained in:
Vito Sansevero
2026-10-24 17:14:19 -07:00
parent 1dcebd640c
commit cd6fad6c60
+7
View File
@@ -602,6 +602,10 @@ test('a save under a Tags filter re-reads the listing: the selection stays while
test('a save under a search keeps the scroll position and the loaded range', async ({ page, request }) => {
await expect(await request.post('/__test__/tagging/reset', { data: { extra_images: 140 } })).toBeOK();
// Listing pages still in flight: one that lands after the scroll below would grow the loaded range.
const inFlight = new Set();
page.on('request', item => { if (item.url().includes('/images/output?')) inFlight.add(item); });
for (const done of ['requestfinished', 'requestfailed']) page.on(done, item => inFlight.delete(item));
await page.goto(images);
const searched = listingOf(page, query => query.get('q') === 'bulk');
await page.getByRole('searchbox', { name: 'Search workspace', exact: true }).fill('bulk');
@@ -615,6 +619,9 @@ test('a save under a search keeps the scroll position and the loaded range', asy
await expect.poll(async () => { await continuation.scrollIntoViewIfNeeded(); return loadedCount(); }).toBeGreaterThanOrEqual(80);
await page.evaluate(() => window.scrollTo(0, Math.round(document.documentElement.scrollHeight / 3)));
await expect(continuation).not.toBeInViewport();
// A load the continuation scheduled for the next frame has started by now; wait for every page to land.
await page.evaluate(() => new Promise(done => requestAnimationFrame(() => requestAnimationFrame(done))));
await expect.poll(() => inFlight.size).toBe(0);
const loaded = await continuation.textContent();
await expect.poll(() => continuation.textContent()).toBe(loaded);
const y = await page.evaluate(() => window.scrollY);