test(browser): cover scrollintoview

This commit is contained in:
Peter Steinberger
2026-01-12 21:56:10 +00:00
parent 6857f16609
commit fcaeee7073
2 changed files with 29 additions and 0 deletions

View File

@@ -396,6 +396,22 @@ describe("pw-tools-core", () => {
expect(res.truncated).toBe(true);
});
it("scrolls a ref into view (default timeout)", async () => {
const scrollIntoViewIfNeeded = vi.fn(async () => {});
currentRefLocator = { scrollIntoViewIfNeeded };
currentPage = {};
const mod = await importModule();
await mod.scrollIntoViewViaPlaywright({
cdpUrl: "http://127.0.0.1:18792",
targetId: "T1",
ref: "1",
});
expect(sessionMocks.refLocator).toHaveBeenCalledWith(currentPage, "1");
expect(scrollIntoViewIfNeeded).toHaveBeenCalledWith({ timeout: 20_000 });
});
it("rewrites strict mode violations into snapshot hints", async () => {
const click = vi.fn(async () => {
throw new Error(

View File

@@ -34,6 +34,7 @@ const pwMocks = vi.hoisted(() => ({
fillFormViaPlaywright: vi.fn(async () => {}),
getConsoleMessagesViaPlaywright: vi.fn(async () => []),
hoverViaPlaywright: vi.fn(async () => {}),
scrollIntoViewViaPlaywright: vi.fn(async () => {}),
navigateViaPlaywright: vi.fn(async () => ({ url: "https://example.com" })),
pdfViaPlaywright: vi.fn(async () => ({ buffer: Buffer.from("pdf") })),
pressKeyViaPlaywright: vi.fn(async () => {}),
@@ -416,6 +417,18 @@ describe("browser control server", () => {
ref: "2",
});
const scroll = (await realFetch(`${base}/act`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ kind: "scrollIntoView", ref: "2" }),
}).then((r) => r.json())) as { ok: boolean };
expect(scroll.ok).toBe(true);
expect(pwMocks.scrollIntoViewViaPlaywright).toHaveBeenCalledWith({
cdpUrl: cdpBaseUrl,
targetId: "abcd1234",
ref: "2",
});
const drag = (await realFetch(`${base}/act`, {
method: "POST",
headers: { "Content-Type": "application/json" },