import * as React from "react";
import * as ReactDOM from "react-dom";
import CheckBox from "../components/Checkbox/index";
import { render, cleanup, Simulate } from "react-testing-library";

beforeEach(cleanup);

describe("Checkbox working correctly", () => {
    it("rtc", () => {
        const clicked = jest.fn();
        const id = "123";
        const { getByTestId, container, rerender } = render(
            <CheckBox value={false} onChange={clicked} uniqueID={id} />
        );
        expect(getByTestId("input").checked).toBeFalsy();
        rerender(<CheckBox value={true} onChange={clicked} uniqueID={id} />);
        expect(getByTestId("input").checked).toBeTruthy();
    });

    it("check", () => {
        const clicked = jest.fn();
        const { getByTestId } = render(
            <CheckBox value={true} uniqueID={"123"} onChange={clicked} />
        );
        Simulate.change(getByTestId("input"));
        expect(clicked).toHaveBeenCalled();
    });

    it("checkbox snapshot", () => {
        const clicked = jest.fn();
        const { container } = render(
            <CheckBox value={true} onChange={clicked} uniqueID={"123"} />
        );
        expect(container).toMatchSnapshot();
    });
});
