-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: CheckBoxWithLabelForm fit into Question Schema
- Loading branch information
1 parent
882dc6f
commit b61a0fb
Showing
5 changed files
with
82 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { CheckBoxWithLabelForm } from "../CheckBoxWithLabelForm"; | ||
import "@testing-library/jest-dom"; | ||
import { fireEvent, render, screen } from "@testing-library/react"; | ||
|
||
describe("FormElements", () => { | ||
describe("<CheckBoxWithLabelForm/>", () => { | ||
const formState = { | ||
"test-question-text": [], | ||
}; | ||
const setFormState = jest.fn(); | ||
|
||
beforeEach(() => { | ||
render( | ||
<CheckBoxWithLabelForm | ||
questionText={"test-question-text"} | ||
options={["options1", "options2", "options3"]} | ||
formState={formState} | ||
setFormState={setFormState} | ||
/>, | ||
); | ||
}); | ||
|
||
test("should render Container properly", () => { | ||
expect(screen.getByTestId("checkbox-with-label-form")).toBeInTheDocument(); | ||
}); | ||
|
||
test("should render each options properly", () => { | ||
expect(screen.getByText("options1")).toBeInTheDocument(); | ||
expect(screen.getByText("options2")).toBeInTheDocument(); | ||
expect(screen.getByText("options3")).toBeInTheDocument(); | ||
}); | ||
|
||
test("should call setFormState once when checkbox is clicked", async () => { | ||
const checkbox = await screen.findByTestId("checkbox_options1"); | ||
expect(checkbox.getAttribute("data-state")).toBe("unchecked"); | ||
|
||
fireEvent.click(checkbox); | ||
expect(setFormState).toHaveBeenCalledTimes(2); | ||
}); | ||
}); | ||
}); |
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