|
| 1 | +import { CheckboxInput, CheckboxDisabledClass } from "./checkbox-input"; |
| 2 | +import faker from "faker"; |
1 | 3 | import React from "react"; |
| 4 | +import { render, fireEvent, wait } from "@testing-library/react"; |
2 | 5 |
|
3 | 6 | describe("CheckboxInput", () => { |
4 | | - test.skip("TODO - https://github.com/AndcultureCode/AndcultureCode.JavaScript.React.Components/issues/6", () => {}); |
| 7 | + test("when default props, renders checkbox", () => { |
| 8 | + // Arrange |
| 9 | + const expected = faker.random.words(); |
| 10 | + |
| 11 | + // Act |
| 12 | + const { getByText } = render( |
| 13 | + <CheckboxInput |
| 14 | + onChange={() => {}} |
| 15 | + label={expected} |
| 16 | + checked={false} |
| 17 | + /> |
| 18 | + ); |
| 19 | + |
| 20 | + // Assert |
| 21 | + expect(getByText(expected)).not.toBeNil(); |
| 22 | + }); |
| 23 | + |
| 24 | + test(`when disabled prop set to true, renders with ${CheckboxDisabledClass} class`, () => { |
| 25 | + // Arrange |
| 26 | + const expected = faker.random.words(); |
| 27 | + |
| 28 | + // Act |
| 29 | + const { container } = render( |
| 30 | + <CheckboxInput |
| 31 | + onChange={() => {}} |
| 32 | + label={expected} |
| 33 | + checked={false} |
| 34 | + disabled={true} |
| 35 | + /> |
| 36 | + ); |
| 37 | + const result = container.querySelector("." + CheckboxDisabledClass); |
| 38 | + |
| 39 | + // Assert |
| 40 | + expect(result).not.toBeNil(); |
| 41 | + }); |
| 42 | + |
| 43 | + test("when onChange set, calls handler upon change", async () => { |
| 44 | + // Arrange |
| 45 | + let isChecked = false; |
| 46 | + const handleChange = () => (isChecked = true); |
| 47 | + const label = faker.random.word(); |
| 48 | + |
| 49 | + // Act |
| 50 | + const { getByLabelText } = render( |
| 51 | + <CheckboxInput |
| 52 | + onChange={handleChange} |
| 53 | + label={label} |
| 54 | + checked={isChecked} |
| 55 | + /> |
| 56 | + ); |
| 57 | + |
| 58 | + fireEvent.click(getByLabelText(label)); |
| 59 | + |
| 60 | + // Assert |
| 61 | + expect(isChecked).toBeTrue(); |
| 62 | + }); |
5 | 63 | }); |
0 commit comments