refactor(browser): unify fill field normalization

This commit is contained in:
Peter Steinberger
2026-02-26 22:17:58 +01:00
parent 69b2f8cd8b
commit eaa9e1c661
6 changed files with 94 additions and 53 deletions

View File

@@ -58,27 +58,35 @@ describe("browser control server", () => {
values: ["a", "b"],
});
const fill = await postJson<{ ok: boolean }>(`${base}/act`, {
kind: "fill",
fields: [{ ref: "6", type: "textbox", value: "hello" }],
});
expect(fill.ok).toBe(true);
expect(pwMocks.fillFormViaPlaywright).toHaveBeenCalledWith({
cdpUrl: state.cdpBaseUrl,
targetId: "abcd1234",
fields: [{ ref: "6", type: "textbox", value: "hello" }],
});
const fillWithoutType = await postJson<{ ok: boolean }>(`${base}/act`, {
kind: "fill",
fields: [{ ref: "7", value: "world" }],
});
expect(fillWithoutType.ok).toBe(true);
expect(pwMocks.fillFormViaPlaywright).toHaveBeenCalledWith({
cdpUrl: state.cdpBaseUrl,
targetId: "abcd1234",
fields: [{ ref: "7", type: "text", value: "world" }],
});
const fillCases: Array<{
input: Record<string, unknown>;
expected: Record<string, unknown>;
}> = [
{
input: { ref: "6", type: "textbox", value: "hello" },
expected: { ref: "6", type: "textbox", value: "hello" },
},
{
input: { ref: "7", value: "world" },
expected: { ref: "7", type: "text", value: "world" },
},
{
input: { ref: "8", type: " ", value: "trimmed-default" },
expected: { ref: "8", type: "text", value: "trimmed-default" },
},
];
for (const { input, expected } of fillCases) {
const fill = await postJson<{ ok: boolean }>(`${base}/act`, {
kind: "fill",
fields: [input],
});
expect(fill.ok).toBe(true);
expect(pwMocks.fillFormViaPlaywright).toHaveBeenCalledWith({
cdpUrl: state.cdpBaseUrl,
targetId: "abcd1234",
fields: [expected],
});
}
const resize = await postJson<{ ok: boolean }>(`${base}/act`, {
kind: "resize",