Skip to content
Snippets Groups Projects
Commit 5651596f0201 authored by Frank Bessou's avatar Frank Bessou :spider_web:
Browse files

test: test required attribute handling

parent f0affba87273
No related branches found
No related tags found
1 merge request!14test: test required attribute handling
Pipeline #39549 passed
import { isRequired } from "ra-core";
import { createFormHelpers } from "../createFormHelpers"; import { createFormHelpers } from "../createFormHelpers";
const schema = { const schema = {
entities: { entities: {
User: { User: {
...@@ -1,9 +3,10 @@ ...@@ -1,9 +3,10 @@
import { createFormHelpers } from "../createFormHelpers"; import { createFormHelpers } from "../createFormHelpers";
const schema = { const schema = {
entities: { entities: {
User: { User: {
login: { type: "String" } as const, login: { type: "String", required: true } as const,
address: { type: "String" } as const,
}, },
}, },
relationsDefinitions: [], relationsDefinitions: [],
...@@ -16,5 +19,15 @@ ...@@ -16,5 +19,15 @@
const props = formHelpers.User.getInputProps("login"); const props = formHelpers.User.getInputProps("login");
expect(props.source).toBe("login"); expect(props.source).toBe("login");
}); });
it("returns validate props for which isRequired returns false when attribute is not required", () => {
const props = formHelpers.User.getInputProps("address");
expect(isRequired(props.validate)).toBe(false);
});
it("returns validate props for which isRequired returns true when attribute is required", () => {
const props = formHelpers.User.getInputProps("login");
expect(isRequired(props.validate)).toBe(true);
});
}); });
}); });
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment