Skip to content

Commit fda879c

Browse files
committed
ci: added test for the DynamicJsonForm
1 parent cc3f9df commit fda879c

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

client/src/components/DynamicJsonForm.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,13 @@ const DynamicJsonForm = ({
191191
const isRequired =
192192
parentSchema?.required?.includes(propertyName || "") ?? false;
193193

194-
switch (propSchema.type) {
194+
let fieldType = propSchema.type;
195+
if (Array.isArray(fieldType)) {
196+
// Of the possible types, find the first non-null type to determine the control to render
197+
fieldType = fieldType.find((t) => t !== "null") ?? fieldType[0];
198+
}
199+
200+
switch (fieldType) {
195201
case "string": {
196202
if (
197203
propSchema.oneOf &&
@@ -347,6 +353,8 @@ const DynamicJsonForm = ({
347353
required={isRequired}
348354
/>
349355
);
356+
case "null":
357+
return null;
350358
case "object":
351359
if (!propSchema.properties) {
352360
return (

client/src/components/__tests__/DynamicJsonForm.test.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ describe("DynamicJsonForm String Fields", () => {
3535
const input = screen.getByRole("textbox");
3636
expect(input).toHaveProperty("type", "text");
3737
});
38+
39+
it("should handle a union type of string and null", () => {
40+
const schema: JsonSchemaType = {
41+
type: ["string", "null"],
42+
description: "Test string or null field",
43+
};
44+
render(
45+
<DynamicJsonForm schema={schema} value={null} onChange={jest.fn()} />,
46+
);
47+
const input = screen.getByRole("textbox");
48+
expect(input).toHaveProperty("type", "text");
49+
});
3850
});
3951

4052
describe("Format Support", () => {

0 commit comments

Comments
 (0)