From f530a912bc9c0035a1b075e9f4f542908846c38f Mon Sep 17 00:00:00 2001 From: Tudor Date: Tue, 22 Sep 2026 14:19:00 +0100 Subject: [PATCH] test(e2e): stop the nearby-schools journey clicking a card it scrolled past MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The assertion that adding to compare does not reset the carousel failed on staging: 537 → 2. The app was not at fault. Playwright scrolls a target into view before clicking, and the test clicked the FIRST card's button after paging the row to the end — so Playwright scrolled the container back to the start, and the assertion measured that. Reproduced on a static page with no React on it: a snap scroller at 615, Playwright clicks the off-screen first card, scrollLeft becomes 2. Scroll-snap was ruled out first — mandatory, proximity and no-snap all behave identically when the button mutates in place. Now clicks the last card's button, which is visible at the end of the travel, and allows a few pixels for snap and sub-pixel adjustment while still failing on a reset to the start. The property was never actually under test before; it is now. Co-Authored-By: Claude Opus 5 --- e2e/tests/journeys.spec.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/e2e/tests/journeys.spec.ts b/e2e/tests/journeys.spec.ts index 4de2c6f..1ee65e5 100644 --- a/e2e/tests/journeys.spec.ts +++ b/e2e/tests/journeys.spec.ts @@ -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); }); /**