You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
chajia/__tests__/workers/rpa/axel-place-prefetch.test.ts

45 lines
1.4 KiB

import { describe, expect, it, vi } from "vitest";
import type { Page } from "playwright";
import { AxelSelectionBridge } from "@/workers/rpa/axel-selection-bridge";
import { commitViaAxelPlacePrefetch } from "@/workers/rpa/axel-place-prefetch";
describe("commitViaAxelPlacePrefetch", () => {
it("GET 200 但 fill 回退不合成 commit", async () => {
const bridge = new AxelSelectionBridge();
const page = {
context: () => ({
cookies: vi.fn().mockResolvedValue([]),
request: {
get: vi.fn().mockResolvedValue({
status: () => 200,
ok: () => true,
json: async () => ({
placeId: "ChIJ_test_place_id_00",
city: "LA",
}),
}),
},
}),
evaluate: vi.fn().mockResolvedValue(false),
keyboard: { press: vi.fn().mockResolvedValue(undefined) },
waitForTimeout: vi.fn().mockResolvedValue(undefined),
} as unknown as Page;
const input = {
click: vi.fn().mockResolvedValue(undefined),
fill: vi.fn().mockResolvedValue(undefined),
};
const result = await commitViaAxelPlacePrefetch(
page,
bridge,
"ChIJ_test_place_id_00",
"1234 Warehouse Street, Los Angeles, CA, USA",
input as never,
);
expect(result.ok).toBe(false);
expect(result.location).toBeTruthy();
expect(bridge.hasPlaceCommit("ChIJ_test_place_id_00")).toBe(false);
});
});