Files
clean-architecture-frontend…/tests/e2e/scroll-restoration.spec.ts
T
DongHyeonkaandClaude Opus 5.5 dbe6b769bf fix(presentation): keep back-navigation scroll and open hash targets (08-08)
A direct link to /page#target stayed at the top: the target renders with the
lazy page, after the router scrolled up. PageHeader now scrolls to it below
the sticky header, focus never scrolls, and POP no longer scrolls to top.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 01:01:52 +09:00

40 lines
1.5 KiB
TypeScript

import { expect, test, type Page } from "../support/browser/strict-browser-test.ts";
const scrollY = (page: Page) => page.evaluate(() => Math.round(window.scrollY));
// 08-08. Back restores where the user was; a new route starts at the top.
test("restores the scroll position when navigating back", async ({ page }) => {
const heading = page.getByRole("heading", { level: 1 });
await page.goto("/examples/ui");
await expect(heading).toHaveText("UI 구성요소");
await page.evaluate(() => window.scrollTo(0, 900));
await expect.poll(() => scrollY(page)).toBe(900);
await page
.getByRole("navigation", { name: "주요 탐색" })
.getByRole("link", { name: "화면 상태" })
.click();
await expect(heading).toHaveText("화면 상태");
await expect.poll(() => scrollY(page)).toBe(0);
await page.goBack();
await expect(heading).toHaveText("UI 구성요소");
await expect.poll(() => scrollY(page)).toBe(900);
});
test("opens a hash link at its target below the sticky header", async ({
page,
}) => {
await page.goto("/examples/ui#tokens-title");
const target = page.locator("#tokens-title");
await expect(target).toBeInViewport();
const top = await target.evaluate((element) =>
Math.round(element.getBoundingClientRect().top),
);
const headerBottom = await page
.locator(".app-shell__header")
.evaluate((element) => Math.round(element.getBoundingClientRect().bottom));
expect(top).toBeGreaterThanOrEqual(headerBottom);
expect(await scrollY(page)).toBeGreaterThan(0);
});