import * as React from "react";
import { render, click, press } from "reakit-test-utils";
import { Checkbox, CheckboxOptions, CheckboxHTMLProps } from "../Checkbox";
test("render", () => {
const { baseElement } = render();
expect(baseElement).toMatchInlineSnapshot(`
`);
});
test("render disabled", () => {
const { baseElement } = render();
expect(baseElement).toMatchInlineSnapshot(`
`);
});
test("render disabled focusable", () => {
const { baseElement } = render();
expect(baseElement).toMatchInlineSnapshot(`
`);
});
test("render checked", () => {
const { baseElement } = render();
expect(baseElement).toMatchInlineSnapshot(`
`);
});
test("click", () => {
const fn = jest.fn();
const { getByLabelText } = render(
);
const checkbox = getByLabelText("checkbox");
expect(fn).toHaveBeenCalledTimes(0);
click(checkbox);
expect(fn).toHaveBeenCalledTimes(1);
});
test("click disabled", () => {
const fn = jest.fn();
const { getByLabelText } = render(
);
const checkbox = getByLabelText("checkbox");
click(checkbox);
expect(fn).toHaveBeenCalledTimes(0);
});
test("click disabled focusable", () => {
const fn = jest.fn();
const { getByLabelText } = render(
);
const checkbox = getByLabelText("checkbox");
click(checkbox);
expect(fn).toHaveBeenCalledTimes(0);
});
test("focus", () => {
const { getByLabelText } = render(
);
const checkbox = getByLabelText("checkbox");
expect(checkbox).not.toHaveFocus();
checkbox.focus();
expect(checkbox).toHaveFocus();
});
test("focus disabled", () => {
const { getByLabelText } = render(
);
const checkbox = getByLabelText("checkbox");
expect(checkbox).not.toHaveFocus();
checkbox.focus();
expect(checkbox).not.toHaveFocus();
});
test("focus disabled focusable", () => {
const { getByLabelText } = render(
);
const checkbox = getByLabelText("checkbox");
expect(checkbox).not.toHaveFocus();
checkbox.focus();
expect(checkbox).toHaveFocus();
});
test("non-native checkbox click", () => {
const fn = jest.fn();
const { getByLabelText } = render(
);
const checkbox = getByLabelText("checkbox");
expect(fn).toHaveBeenCalledTimes(0);
click(checkbox);
expect(fn).toHaveBeenCalledTimes(1);
});
test("non-native checkbox click disabled", () => {
const fn = jest.fn();
const { getByLabelText } = render(
);
const checkbox = getByLabelText("checkbox");
click(checkbox);
expect(fn).toHaveBeenCalledTimes(0);
});
test("non-native checkbox click disabled focusable", () => {
const fn = jest.fn();
const { getByLabelText } = render(
);
const checkbox = getByLabelText("checkbox");
click(checkbox);
expect(fn).toHaveBeenCalledTimes(0);
});
test("non-native checkbox focus", () => {
const { getByLabelText } = render(
);
const checkbox = getByLabelText("checkbox");
expect(checkbox).not.toHaveFocus();
checkbox.focus();
expect(checkbox).toHaveFocus();
});
test("non-native checkbox focus disabled", () => {
const { getByLabelText } = render(
);
const checkbox = getByLabelText("checkbox");
expect(checkbox).not.toHaveFocus();
checkbox.focus();
expect(checkbox).not.toHaveFocus();
});
test("non-native checkbox focus disabled focusable", () => {
const { getByLabelText } = render(
);
const checkbox = getByLabelText("checkbox");
expect(checkbox).not.toHaveFocus();
checkbox.focus();
expect(checkbox).toHaveFocus();
});
test("non-native checkbox space", () => {
const fn = jest.fn();
const { getByLabelText } = render(
);
const checkbox = getByLabelText("checkbox");
press.Space(checkbox);
expect(fn).toHaveBeenCalledTimes(1);
});
test("non-native checkbox space disabled", () => {
const fn = jest.fn();
const { getByLabelText } = render(
);
const checkbox = getByLabelText("checkbox");
press.Space(checkbox);
expect(fn).toHaveBeenCalledTimes(0);
});
test("non-native checkbox space disabled focusable", () => {
const fn = jest.fn();
const { getByLabelText } = render(
);
const checkbox = getByLabelText("checkbox");
press.Space(checkbox);
expect(fn).toHaveBeenCalledTimes(0);
});
test("indeterminate", () => {
const Comp = (props: CheckboxOptions & CheckboxHTMLProps) => (
);
const { getByLabelText, rerender } = render();
const checkbox = getByLabelText("checkbox");
expect(checkbox).toHaveAttribute("aria-checked", "false");
rerender();
expect(checkbox).toHaveAttribute("aria-checked", "mixed");
rerender();
expect(checkbox).toHaveAttribute("aria-checked", "true");
});