fix: close final draft authoring review gaps
This commit is contained in:
@@ -126,6 +126,29 @@ const LeafControl = ({
|
||||
id,
|
||||
};
|
||||
if (field.kind === "boolean") {
|
||||
if (field.required && !field.hasDefault) {
|
||||
const selectedValue = value === true ? "true" : value === false ? "false" : "";
|
||||
return (
|
||||
<select
|
||||
{...common}
|
||||
aria-label={label}
|
||||
onChange={(event) => {
|
||||
onValueChange(
|
||||
event.target.value === "true"
|
||||
? true
|
||||
: event.target.value === "false"
|
||||
? false
|
||||
: undefined,
|
||||
);
|
||||
}}
|
||||
value={selectedValue}
|
||||
>
|
||||
<option value="">Choose true or false</option>
|
||||
<option value="true">true</option>
|
||||
<option value="false">false</option>
|
||||
</select>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<input
|
||||
{...common}
|
||||
|
||||
@@ -160,6 +160,49 @@ describe("SchemaForm", () => {
|
||||
expect(explicit[0]?.value).toEqual({ enabled: false });
|
||||
});
|
||||
|
||||
it("offers an unset, true, and false choice for a required boolean without a default", async () => {
|
||||
const user = userEvent.setup();
|
||||
const submissions: SchemaSerializationResult[] = [];
|
||||
render(
|
||||
<SchemaForm
|
||||
onSubmit={(result) => submissions.push(result)}
|
||||
schema={{
|
||||
type: "object",
|
||||
properties: { enabled: { type: "boolean" } },
|
||||
required: ["enabled"],
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
|
||||
const enabled = screen.getByRole("combobox", { name: "Enabled" });
|
||||
expect(enabled).toHaveValue("");
|
||||
expect(screen.getByRole("option", { name: "Choose true or false" })).toBeInTheDocument();
|
||||
await user.selectOptions(enabled, "false");
|
||||
await user.click(screen.getByRole("button", { name: "Save form" }));
|
||||
expect(submissions[0]?.value).toEqual({ enabled: false });
|
||||
expect(submissions[0]?.issues).toEqual([]);
|
||||
});
|
||||
|
||||
it("serializes the true choice for a required boolean without a default", async () => {
|
||||
const user = userEvent.setup();
|
||||
const submissions: SchemaSerializationResult[] = [];
|
||||
render(
|
||||
<SchemaForm
|
||||
onSubmit={(result) => submissions.push(result)}
|
||||
schema={{
|
||||
type: "object",
|
||||
properties: { enabled: { type: "boolean" } },
|
||||
required: ["enabled"],
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
|
||||
await user.selectOptions(screen.getByRole("combobox", { name: "Enabled" }), "true");
|
||||
await user.click(screen.getByRole("button", { name: "Save form" }));
|
||||
expect(submissions[0]?.value).toEqual({ enabled: true });
|
||||
expect(submissions[0]?.issues).toEqual([]);
|
||||
});
|
||||
|
||||
it("routes nested diagnostics only to their owning field", () => {
|
||||
render(
|
||||
<SchemaForm
|
||||
|
||||
@@ -235,6 +235,26 @@ describe("serializeSchemaValues", () => {
|
||||
expect(serializeSchemaValues(field, { enabled: false }).value).toEqual({ enabled: false });
|
||||
});
|
||||
|
||||
it("requires an explicit true or false value for a required boolean without a default", () => {
|
||||
const field = normalizeSchema({
|
||||
type: "object",
|
||||
properties: { enabled: { type: "boolean" } },
|
||||
required: ["enabled"],
|
||||
});
|
||||
|
||||
expect(serializeSchemaValues(field, { enabled: undefined }).issues).toEqual([
|
||||
{ path: ["enabled"], message: "Choose true or false." },
|
||||
]);
|
||||
expect(serializeSchemaValues(field, { enabled: true })).toMatchObject({
|
||||
value: { enabled: true },
|
||||
issues: [],
|
||||
});
|
||||
expect(serializeSchemaValues(field, { enabled: false })).toMatchObject({
|
||||
value: { enabled: false },
|
||||
issues: [],
|
||||
});
|
||||
});
|
||||
|
||||
it("reports and preserves missing required string and JSON values", () => {
|
||||
const field = normalizeSchema({
|
||||
type: "object",
|
||||
|
||||
Reference in New Issue
Block a user