test(e2e): fix the nearby-schools journey clicking a card it scrolled past #152

Merged
tudor merged 1 commits from fix/nearby-scroll-journey-clicks-offscreen-card into main 2026-09-22 13:50:26 +00:00
Showing only changes of commit f530a912bc - Show all commits
+13 -2
View File
@@ -2784,12 +2784,23 @@ test('nearby schools link on to other schools and into compare', async ({ page }
// The compare hand-off, and the row must not jump back to the start when the
// footer re-renders underneath it.
//
// Click the LAST card's button, not the first. Playwright scrolls a target
// into view before clicking it, so clicking card one while the row is paged
// to the end scrolls the container back to the start — and the assertion
// below then measures Playwright's own scrolling rather than the app's.
// That is what this test did on its first staging run: 537 → 2, reproduced
// afterwards on a static page with no React on it at all.
//
// A few pixels of snap or sub-pixel adjustment are fine; a reset to the
// start is not, which is the whole point of the check.
const offsetBefore = await scroller.evaluate((node: HTMLElement) => node.scrollLeft);
await section.getByRole('button', { name: /Add to compare/ }).first().click();
await section.getByRole('button', { name: /Add to compare/ }).last().click();
await expect(
section.getByRole('button', { name: /Added to compare/ }).first(),
).toBeVisible();
expect(await scroller.evaluate((node: HTMLElement) => node.scrollLeft)).toBe(offsetBefore);
const offsetAfter = await scroller.evaluate((node: HTMLElement) => node.scrollLeft);
expect(Math.abs(offsetAfter - offsetBefore)).toBeLessThanOrEqual(8);
});
/**