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

@@ -2,10 +2,24 @@ import { describe, expect, it } from "vitest";
import { readFields } from "./shared.js";
describe("readFields", () => {
it("defaults missing type to text", async () => {
await expect(readFields({ fields: '[{"ref":"7","value":"world"}]' })).resolves.toEqual([
{ ref: "7", type: "text", value: "world" },
]);
it.each([
{
name: "keeps explicit type",
fields: '[{"ref":"6","type":"textbox","value":"hello"}]',
expected: [{ ref: "6", type: "textbox", value: "hello" }],
},
{
name: "defaults missing type to text",
fields: '[{"ref":"7","value":"world"}]',
expected: [{ ref: "7", type: "text", value: "world" }],
},
{
name: "defaults blank type to text",
fields: '[{"ref":"8","type":" ","value":"blank"}]',
expected: [{ ref: "8", type: "text", value: "blank" }],
},
])("$name", async ({ fields, expected }) => {
await expect(readFields({ fields })).resolves.toEqual(expected);
});
it("requires ref", async () => {