-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up code, improve test coverage
- Loading branch information
1 parent
961daf2
commit eb672fc
Showing
11 changed files
with
180 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import React from "react"; | ||
|
||
import { render } from "@testing-library/react"; | ||
import { renderHook } from "@testing-library/react-hooks"; | ||
|
||
import { useForm } from "react-hook-form"; | ||
|
||
import { MuiRhfForm } from "../"; | ||
|
||
describe("Form render", () => { | ||
it("render basic form", () => { | ||
const { result } = renderHook(() => useForm()); | ||
const { control, errors /**, loading */ } = result.current; | ||
render( | ||
<MuiRhfForm | ||
control={control} | ||
errors={errors} | ||
fields={[ | ||
[{ name: "firstName" }, { name: "lastName" }], | ||
[{ name: "email" }], | ||
[{ name: "rememberMe", type: "checkbox" }], | ||
]} | ||
/> | ||
); | ||
}); | ||
|
||
it("render complex form", () => { | ||
const { result } = renderHook(() => useForm()); | ||
const { control, errors /**, loading */ } = result.current; | ||
render( | ||
<MuiRhfForm | ||
control={control} | ||
errors={errors} | ||
headers={[{ title: "Company section" }]} | ||
fields={[ | ||
[ | ||
{ | ||
type: "autocompleteSingle", | ||
name: "company", | ||
props: { | ||
autocompleteProps: { options: ["Company A", "Company B"] }, | ||
}, | ||
}, | ||
{ | ||
type: "autocompleteMultiple", | ||
name: "collaborator", | ||
props: { | ||
autocompleteProps: { | ||
options: ["Collaborator A", "Collaborator B"], | ||
}, | ||
}, | ||
}, | ||
], | ||
]} | ||
/> | ||
); | ||
}); | ||
|
||
it("render basic form with hideConditions", () => { | ||
const { result } = renderHook(() => useForm()); | ||
const { control, errors /**, loading */ } = result.current; | ||
render( | ||
<MuiRhfForm | ||
control={control} | ||
errors={errors} | ||
fields={[ | ||
[ | ||
{ name: "firstName" }, | ||
{ | ||
name: "lastName", | ||
// Do not display lastName field when user is John Doe | ||
hideCondition: { firstName: (value) => value === "John Doe" }, | ||
}, | ||
], | ||
]} | ||
/> | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.