fix: address Copilot review round 19 — empty-string const in the web required gate
hasMissingRequiredFields treated every empty string as missing, so a required field the schema pins to `""` — rendered read-only, and seeded with the only value it accepts — left Execute and Open App permanently disabled. It now matches the TUI check: an empty string counts as supplied when the property's own `const` pins it there, and an ordinary blank required string still does not. Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
parent
36cf58fe6c
commit
44b2ccd257
2 changed files with 29 additions and 1 deletions
|
|
@ -488,6 +488,28 @@ describe("root composition (#2123)", () => {
|
|||
).toBe(values);
|
||||
});
|
||||
|
||||
it("accepts an empty string a const pins the field to", () => {
|
||||
// Rendered read-only, so treating the seeded value as missing would
|
||||
// disable submit on a value the user cannot change.
|
||||
const pinnedEmpty: InspectorFormSchema = {
|
||||
type: "object",
|
||||
properties: { kind: { type: "string", const: "" } },
|
||||
required: ["kind"],
|
||||
};
|
||||
expect(hasMissingRequiredFields(pinnedEmpty, { kind: "" })).toBe(false);
|
||||
// An ordinary required string is still missing when left blank.
|
||||
expect(
|
||||
hasMissingRequiredFields(
|
||||
{
|
||||
type: "object",
|
||||
properties: { kind: { type: "string" } },
|
||||
required: ["kind"],
|
||||
},
|
||||
{ kind: "" },
|
||||
),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("blocks submission while no branch is satisfied", () => {
|
||||
expect(hasMissingRequiredFields(UNION, {})).toBe(true);
|
||||
expect(hasMissingRequiredFields(UNION, { kind: "email" })).toBe(true);
|
||||
|
|
|
|||
|
|
@ -292,7 +292,13 @@ function hasMissingIn(
|
|||
const fieldSchema = properties[field];
|
||||
return fieldSchema === undefined ? true : !admitsNull(fieldSchema);
|
||||
}
|
||||
return value === undefined || value === "";
|
||||
if (value === "") {
|
||||
// A schema may pin a field to the empty string, and the form renders such
|
||||
// a field read-only — so reporting the seeded value as missing would
|
||||
// disable submit on a value the user cannot change (#2123).
|
||||
return properties[field]?.const !== "";
|
||||
}
|
||||
return value === undefined;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue