test(browser): expand scrollintoview coverage

This commit is contained in:
Peter Steinberger
2026-01-12 22:08:43 +00:00
parent 29b7b2068a
commit 9da97d1a41
2 changed files with 82 additions and 0 deletions

View File

@@ -412,6 +412,74 @@ describe("pw-tools-core", () => {
expect(scrollIntoViewIfNeeded).toHaveBeenCalledWith({ timeout: 20_000 });
});
it("requires a ref for scrollIntoView", async () => {
currentRefLocator = { scrollIntoViewIfNeeded: vi.fn(async () => {}) };
currentPage = {};
const mod = await importModule();
await expect(
mod.scrollIntoViewViaPlaywright({
cdpUrl: "http://127.0.0.1:18792",
targetId: "T1",
ref: " ",
}),
).rejects.toThrow(/ref is required/i);
});
it("clamps timeoutMs for scrollIntoView", 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",
timeoutMs: 50,
});
expect(scrollIntoViewIfNeeded).toHaveBeenCalledWith({ timeout: 500 });
});
it("rewrites strict mode violations for scrollIntoView", async () => {
const scrollIntoViewIfNeeded = vi.fn(async () => {
throw new Error(
'Error: strict mode violation: locator("aria-ref=1") resolved to 2 elements',
);
});
currentRefLocator = { scrollIntoViewIfNeeded };
currentPage = {};
const mod = await importModule();
await expect(
mod.scrollIntoViewViaPlaywright({
cdpUrl: "http://127.0.0.1:18792",
targetId: "T1",
ref: "1",
}),
).rejects.toThrow(/Run a new snapshot/i);
});
it("rewrites not-visible timeouts for scrollIntoView", async () => {
const scrollIntoViewIfNeeded = vi.fn(async () => {
throw new Error(
'Timeout 5000ms exceeded. waiting for locator("aria-ref=1") to be visible',
);
});
currentRefLocator = { scrollIntoViewIfNeeded };
currentPage = {};
const mod = await importModule();
await expect(
mod.scrollIntoViewViaPlaywright({
cdpUrl: "http://127.0.0.1:18792",
targetId: "T1",
ref: "1",
}),
).rejects.toThrow(/not found or not visible/i);
});
it("rewrites strict mode violations into snapshot hints", async () => {
const click = vi.fn(async () => {
throw new Error(

View File

@@ -712,6 +712,20 @@ describe("browser control server", () => {
});
expect(clickMissingRef.status).toBe(400);
const scrollMissingRef = await realFetch(`${base}/act`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ kind: "scrollIntoView" }),
});
expect(scrollMissingRef.status).toBe(400);
const scrollSelectorUnsupported = await realFetch(`${base}/act`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ kind: "scrollIntoView", selector: "button.save" }),
});
expect(scrollSelectorUnsupported.status).toBe(400);
const clickBadButton = await realFetch(`${base}/act`, {
method: "POST",
headers: { "Content-Type": "application/json" },