Skip to content

Commit

Permalink
- Added the same additional Array tests that were added in #2576
Browse files Browse the repository at this point in the history
  • Loading branch information
heath-freenome committed Sep 3, 2022
1 parent c4d5442 commit 350bbcf
Show file tree
Hide file tree
Showing 13 changed files with 2,688 additions and 260 deletions.
36 changes: 35 additions & 1 deletion packages/bootstrap-4/test/Array.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { RJSFSchema } from "@rjsf/utils";
import { RJSFSchema, ErrorSchema } from "@rjsf/utils";
import validator from "@rjsf/validator-ajv6";
import renderer from "react-test-renderer";

Expand Down Expand Up @@ -63,4 +63,38 @@ describe("array fields", () => {
.toJSON();
expect(tree).toMatchSnapshot();
});
test("no errors", () => {
const schema: RJSFSchema = {
type: "object",
properties: {
name: {
type: "string",
},
},
};
const tree = renderer
.create(<Form schema={schema} validator={validator} />)
.toJSON();
expect(tree).toMatchSnapshot();
});
test("empty errors array", () => {
const schema: RJSFSchema = {
type: "object",
properties: {
name: {
type: "string",
},
},
};
const errors: any[] = [];
const extraErrors = {
name: { __errors: errors },
} as unknown as ErrorSchema;
const tree = renderer
.create(
<Form schema={schema} validator={validator} extraErrors={extraErrors} />
)
.toJSON();
expect(tree).toMatchSnapshot();
});
});
156 changes: 156 additions & 0 deletions packages/bootstrap-4/test/__snapshots__/Array.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,84 @@ exports[`array fields checkboxes 1`] = `
</form>
`;

exports[`array fields empty errors array 1`] = `
<form
className="rjsf"
noValidate={false}
onSubmit={[Function]}
>
<div
className="form-group field field-object"
>
<div
className="form-group"
>
<div
className="p-0 container-fluid"
>
<div
className="row"
style={
Object {
"marginBottom": "10px",
}
}
>
<div
className="col-12"
>
<div
className="form-group field field-string"
>
<div
className="form-group"
>
<div
className="mb-0 form-group"
>
<label
className="form-label"
htmlFor="root_name"
>
name
</label>
<input
autoFocus={false}
className="form-control"
disabled={false}
id="root_name"
onBlur={[Function]}
onChange={[Function]}
onFocus={[Function]}
placeholder=""
readOnly={false}
required={false}
type="text"
value=""
/>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<button
className="btn btn-primary"
disabled={false}
type="submit"
>
Submit
</button>
</div>
</form>
`;

exports[`array fields fixed array 1`] = `
<form
className="rjsf"
Expand Down Expand Up @@ -709,3 +787,81 @@ exports[`array fields fixed array 1`] = `
</div>
</form>
`;

exports[`array fields no errors 1`] = `
<form
className="rjsf"
noValidate={false}
onSubmit={[Function]}
>
<div
className="form-group field field-object"
>
<div
className="form-group"
>
<div
className="p-0 container-fluid"
>
<div
className="row"
style={
Object {
"marginBottom": "10px",
}
}
>
<div
className="col-12"
>
<div
className="form-group field field-string"
>
<div
className="form-group"
>
<div
className="mb-0 form-group"
>
<label
className="form-label"
htmlFor="root_name"
>
name
</label>
<input
autoFocus={false}
className="form-control"
disabled={false}
id="root_name"
onBlur={[Function]}
onChange={[Function]}
onFocus={[Function]}
placeholder=""
readOnly={false}
required={false}
type="text"
value=""
/>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<button
className="btn btn-primary"
disabled={false}
type="submit"
>
Submit
</button>
</div>
</form>
`;
36 changes: 35 additions & 1 deletion packages/chakra-ui/test/Array.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @jsx jsx */
import { jsx } from "@emotion/react";
import { RJSFSchema } from "@rjsf/utils";
import { RJSFSchema, ErrorSchema } from "@rjsf/utils";
import validator from "@rjsf/validator-ajv6";
import renderer from "react-test-renderer";

Expand Down Expand Up @@ -64,4 +64,38 @@ describe("array fields", () => {
.toJSON();
expect(tree).toMatchSnapshot();
});
test("no errors", () => {
const schema: RJSFSchema = {
type: "object",
properties: {
name: {
type: "string",
},
},
};
const tree = renderer
.create(<Form schema={schema} validator={validator} />)
.toJSON();
expect(tree).toMatchSnapshot();
});
test("empty errors array", () => {
const schema: RJSFSchema = {
type: "object",
properties: {
name: {
type: "string",
},
},
};
const errors: any[] = [];
const extraErrors = {
name: { __errors: errors },
} as unknown as ErrorSchema;
const tree = renderer
.create(
<Form schema={schema} validator={validator} extraErrors={extraErrors} />
)
.toJSON();
expect(tree).toMatchSnapshot();
});
});
Loading

0 comments on commit 350bbcf

Please sign in to comment.