-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(useCheckboxFieldProps): extend to support BooleanField as input
fixes #33
- Loading branch information
1 parent
97d50b3
commit c3c59c0
Showing
4 changed files
with
70 additions
and
5 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
38 changes: 38 additions & 0 deletions
38
src/hooks/use-checkbox-field-props/useCheckboxFieldProps.test.tsx
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,38 @@ | ||
import { render, renderHook, screen } from "@testing-library/react"; | ||
import { userEvent } from "@testing-library/user-event"; | ||
import { describe, expect, test } from "vitest"; | ||
|
||
import { useCheckboxFieldProps } from "./useCheckboxFieldProps"; | ||
import { booleanField, checkboxField } from "../../fields"; | ||
|
||
describe("useCheckboxFieldProps()", () => { | ||
describe("with booleanField()", () => { | ||
test("initial value prop is false", () => { | ||
const field = booleanField(); | ||
|
||
const checkboxProps = renderHook(() => useCheckboxFieldProps(field)); | ||
|
||
expect(checkboxProps.result.current.checked).toBe(false); | ||
}); | ||
}); | ||
|
||
test("it reads the checked event property", async () => { | ||
const field = checkboxField(); | ||
|
||
const checkboxProps = renderHook(() => useCheckboxFieldProps(field)); | ||
|
||
render( | ||
<input | ||
type="checkbox" | ||
data-testid="input-checkbox" | ||
{...checkboxProps.result.current} | ||
/>, | ||
); | ||
|
||
expect(checkboxProps.result.current.checked).toBe(false); | ||
|
||
await userEvent.click(screen.getByTestId("input-checkbox")); | ||
|
||
expect(checkboxProps.result.current.checked).toBe(true); | ||
}); | ||
}); |
11 changes: 7 additions & 4 deletions
11
src/hooks/use-checkbox-field-props/useCheckboxFieldProps.ts
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