mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-19 00:51:37 +00:00
test(browser): align existing-session document mock (#105398)
* test(browser): align existing-session document mock * test(browser): type document evaluator mock * test(browser): type document evaluator mock
This commit is contained in:
committed by
GitHub
parent
046bf2468d
commit
5b2ae5df9d
@@ -10,6 +10,7 @@ import { createBrowserRouteApp, createBrowserRouteResponse } from "./test-helper
|
||||
const routeState = existingSessionRouteState;
|
||||
|
||||
const chromeMcpMocks = vi.hoisted(() => ({
|
||||
ChromeMcpDocumentUnavailableError: class ChromeMcpDocumentUnavailableError extends Error {},
|
||||
clickChromeMcpCoords: vi.fn(async () => {}),
|
||||
clickChromeMcpElement: vi.fn(async () => {}),
|
||||
evaluateChromeMcpScript: vi.fn(
|
||||
@@ -24,6 +25,10 @@ const chromeMcpMocks = vi.hoisted(() => ({
|
||||
name: "Example",
|
||||
children: [{ id: "btn-1", role: "button", name: "Continue" }],
|
||||
})),
|
||||
withChromeMcpDocument: vi.fn(
|
||||
async (_params: unknown, task: (document: { evaluate: (fn: string) => unknown }) => unknown) =>
|
||||
await task({ evaluate: async () => "https://example.com/" }),
|
||||
),
|
||||
}));
|
||||
|
||||
const navigationGuardMocks = vi.hoisted(() => ({
|
||||
@@ -33,6 +38,7 @@ const navigationGuardMocks = vi.hoisted(() => ({
|
||||
}));
|
||||
|
||||
vi.mock("../chrome-mcp.js", () => ({
|
||||
ChromeMcpDocumentUnavailableError: chromeMcpMocks.ChromeMcpDocumentUnavailableError,
|
||||
clickChromeMcpCoords: chromeMcpMocks.clickChromeMcpCoords,
|
||||
clickChromeMcpElement: chromeMcpMocks.clickChromeMcpElement,
|
||||
closeChromeMcpTab: vi.fn(async () => {}),
|
||||
@@ -46,6 +52,7 @@ vi.mock("../chrome-mcp.js", () => ({
|
||||
resizeChromeMcpPage: vi.fn(async () => {}),
|
||||
takeChromeMcpScreenshot: chromeMcpMocks.takeChromeMcpScreenshot,
|
||||
takeChromeMcpSnapshot: chromeMcpMocks.takeChromeMcpSnapshot,
|
||||
withChromeMcpDocument: chromeMcpMocks.withChromeMcpDocument,
|
||||
}));
|
||||
|
||||
vi.mock("../cdp.js", () => ({
|
||||
@@ -153,6 +160,7 @@ describe("existing-session browser routes", () => {
|
||||
chromeMcpMocks.navigateChromeMcpPage.mockClear();
|
||||
chromeMcpMocks.takeChromeMcpScreenshot.mockClear();
|
||||
chromeMcpMocks.takeChromeMcpSnapshot.mockClear();
|
||||
chromeMcpMocks.withChromeMcpDocument.mockClear();
|
||||
navigationGuardMocks.assertBrowserNavigationAllowed.mockClear();
|
||||
navigationGuardMocks.assertBrowserNavigationResultAllowed.mockClear();
|
||||
navigationGuardMocks.withBrowserNavigationPolicy.mockClear();
|
||||
@@ -454,10 +462,9 @@ describe("existing-session browser routes", () => {
|
||||
});
|
||||
|
||||
it("supports glob URL waits for existing-session profiles", async () => {
|
||||
chromeMcpMocks.evaluateChromeMcpScript.mockReset();
|
||||
chromeMcpMocks.evaluateChromeMcpScript.mockImplementation(
|
||||
async ({ fn }: { fn: string }) =>
|
||||
(fn === "() => window.location.href" ? "https://example.com/" : true) as never,
|
||||
const evaluate = vi.fn(async (_fn: string) => "https://example.com/");
|
||||
chromeMcpMocks.withChromeMcpDocument.mockImplementationOnce(
|
||||
async (_params, task) => await task({ evaluate }),
|
||||
);
|
||||
|
||||
const handler = getActPostHandler();
|
||||
@@ -475,15 +482,16 @@ describe("existing-session browser routes", () => {
|
||||
const body = requireRecord(response.body, "response body");
|
||||
expect(body.ok).toBe(true);
|
||||
expect(body.targetId).toBe("7");
|
||||
const evaluateParams = requireRecord(
|
||||
callArg(chromeMcpMocks.evaluateChromeMcpScript, 0, 0, "evaluate params"),
|
||||
"evaluate params",
|
||||
const documentParams = requireRecord(
|
||||
callArg(chromeMcpMocks.withChromeMcpDocument, 0, 0, "document params"),
|
||||
"document params",
|
||||
);
|
||||
expect(evaluateParams.profileName).toBe("chrome-live");
|
||||
expectExistingSessionProfile(evaluateParams.profile);
|
||||
expect(evaluateParams.userDataDir).toBeUndefined();
|
||||
expect(evaluateParams.targetId).toBe("7");
|
||||
expect(evaluateParams.fn).toBe("() => window.location.href");
|
||||
expect(documentParams.profileName).toBe("chrome-live");
|
||||
expectExistingSessionProfile(documentParams.profile);
|
||||
expect(documentParams.userDataDir).toBeUndefined();
|
||||
expect(documentParams.targetId).toBe("7");
|
||||
expect(evaluate).toHaveBeenCalledOnce();
|
||||
expect(String(evaluate.mock.calls[0]?.[0])).toContain("globalThis.location.href");
|
||||
});
|
||||
|
||||
it("forwards click timeoutMs to the existing-session click executor", async () => {
|
||||
|
||||
Reference in New Issue
Block a user