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