ci: added test for the DynamicJsonForm

This commit is contained in:
Mats Julius Funke 2025-08-04 09:32:24 +02:00
commit fda879ccc1
No known key found for this signature in database
2 changed files with 21 additions and 1 deletions

View file

@ -191,7 +191,13 @@ const DynamicJsonForm = ({
const isRequired = const isRequired =
parentSchema?.required?.includes(propertyName || "") ?? false; parentSchema?.required?.includes(propertyName || "") ?? false;
switch (propSchema.type) { let fieldType = propSchema.type;
if (Array.isArray(fieldType)) {
// Of the possible types, find the first non-null type to determine the control to render
fieldType = fieldType.find((t) => t !== "null") ?? fieldType[0];
}
switch (fieldType) {
case "string": { case "string": {
if ( if (
propSchema.oneOf && propSchema.oneOf &&
@ -347,6 +353,8 @@ const DynamicJsonForm = ({
required={isRequired} required={isRequired}
/> />
); );
case "null":
return null;
case "object": case "object":
if (!propSchema.properties) { if (!propSchema.properties) {
return ( return (

View file

@ -35,6 +35,18 @@ describe("DynamicJsonForm String Fields", () => {
const input = screen.getByRole("textbox"); const input = screen.getByRole("textbox");
expect(input).toHaveProperty("type", "text"); expect(input).toHaveProperty("type", "text");
}); });
it("should handle a union type of string and null", () => {
const schema: JsonSchemaType = {
type: ["string", "null"],
description: "Test string or null field",
};
render(
<DynamicJsonForm schema={schema} value={null} onChange={jest.fn()} />,
);
const input = screen.getByRole("textbox");
expect(input).toHaveProperty("type", "text");
});
}); });
describe("Format Support", () => { describe("Format Support", () => {