import { isRequired } from "ra-core"; import { createFormHelpers } from "../createFormHelpers"; const schema = { entities: { User: { login: { type: "String", required: true } as const, address: { type: "String" } as const, active: { type: "Boolean", default: true } as const, }, }, relationsDefinitions: [], }; describe("FormHelper", () => { const formHelpers = createFormHelpers(schema); describe("getInputProps", () => { it("returns first argument as source property", () => { const props = formHelpers.User.getInputProps("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); }); it("returns an 'initialValue' property when the attribute has a default value", () => { const props = formHelpers.User.getInputProps("active"); expect(props.initialValue).toBe(true); }); it("returns no 'initialValue' property when the attribute has no default value", () => { const props = formHelpers.User.getInputProps("active"); expect(props.initialValue).toBe(true); }); }); });