test(browser): expand scrollintoview coverage
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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" },
|
||||
|
||||
Reference in New Issue
Block a user