import * as React from "react";
import { render, click, focus, press } from "reakit-test-utils";
import { Clickable, ClickableProps } from "../Clickable";
test("render", () => {
const { getByText } = render(clickable);
expect(getByText("clickable")).toMatchInlineSnapshot(`
`);
});
test("render disabled", () => {
const { getByText } = render(clickable);
expect(getByText("clickable")).toMatchInlineSnapshot(`
`);
});
test("render disabled focusable", () => {
const { getByText } = render(
clickable
);
expect(getByText("clickable")).toMatchInlineSnapshot(`
`);
});
test("click", () => {
const fn = jest.fn();
const { getByText } = render(clickable);
const clickable = getByText("clickable");
expect(fn).toHaveBeenCalledTimes(0);
click(clickable);
expect(fn).toHaveBeenCalledTimes(1);
});
test("click disabled", () => {
const fn = jest.fn();
const { getByText } = render(
clickable
);
const clickable = getByText("clickable");
click(clickable);
expect(fn).toHaveBeenCalledTimes(0);
});
test("click enabled after disabled", () => {
const fn = jest.fn();
const { getByText, rerender } = render(
clickable
);
const clickable = getByText("clickable");
rerender(clickable);
click(clickable);
expect(fn).toHaveBeenCalledTimes(1);
});
test("click disabled focusable", () => {
const fn = jest.fn();
const { getByText } = render(
clickable
);
const clickable = getByText("clickable");
click(clickable);
expect(fn).toHaveBeenCalledTimes(0);
});
test("focus", () => {
const { getByText } = render(clickable);
const clickable = getByText("clickable");
expect(clickable).not.toHaveFocus();
focus(clickable);
expect(clickable).toHaveFocus();
});
test("focus disabled", () => {
const { getByText } = render(clickable);
const clickable = getByText("clickable");
expect(clickable).not.toHaveFocus();
focus(clickable);
expect(clickable).not.toHaveFocus();
});
test("focus disabled focusable", () => {
const { getByText } = render(
clickable
);
const clickable = getByText("clickable");
expect(clickable).not.toHaveFocus();
focus(clickable);
expect(clickable).toHaveFocus();
});
test("non-native button click", () => {
const fn = jest.fn();
const { getByText } = render(
clickable
);
const clickable = getByText("clickable");
expect(fn).toHaveBeenCalledTimes(0);
click(clickable);
expect(fn).toHaveBeenCalledTimes(1);
});
test("non-native button click disabled", () => {
const fn = jest.fn();
const { getByText } = render(
clickable
);
const clickable = getByText("clickable");
click(clickable);
expect(fn).toHaveBeenCalledTimes(0);
});
test("non-native button click disabled focusable", () => {
const fn = jest.fn();
const { getByText } = render(
clickable
);
const clickable = getByText("clickable");
click(clickable);
expect(fn).toHaveBeenCalledTimes(0);
});
test("non-native button focus", () => {
const { getByText } = render(clickable);
const clickable = getByText("clickable");
expect(clickable).not.toHaveFocus();
focus(clickable);
expect(clickable).toHaveFocus();
});
test("non-native button focus disabled", () => {
const { getByText } = render(
clickable
);
const clickable = getByText("clickable");
expect(clickable).not.toHaveFocus();
focus(clickable);
expect(clickable).not.toHaveFocus();
});
test("non-native button focus disabled focusable", () => {
const { getByText } = render(
clickable
);
const clickable = getByText("clickable");
expect(clickable).not.toHaveFocus();
focus(clickable);
expect(clickable).toHaveFocus();
});
test("non-native button space/enter", () => {
const fn = jest.fn();
const { getByText } = render(
clickable
);
const clickable = getByText("clickable");
press.Enter(clickable);
expect(fn).toHaveBeenCalledTimes(1);
press.Space(clickable);
expect(fn).toHaveBeenCalledTimes(2);
});
test("non-native button space/enter disabled", () => {
const fn = jest.fn();
const { getByText } = render(
clickable
);
const clickable = getByText("clickable");
press.Enter(clickable);
press.Space(clickable);
expect(fn).toHaveBeenCalledTimes(0);
});
test("non-native button space/enter metaKey", () => {
const fn = jest.fn();
const { getByText } = render(
clickable
);
const clickable = getByText("clickable");
press.Enter(clickable, { metaKey: true });
press.Space(clickable, { metaKey: true });
expect(fn).toHaveBeenCalledTimes(0);
});
test("non-native button space/enter disabled focusable", () => {
const fn = jest.fn();
const { getByText } = render(
clickable
);
const clickable = getByText("clickable");
press.Enter(clickable);
press.Space(clickable);
expect(fn).toHaveBeenCalledTimes(0);
});
test("press enter on Clickable as another non-native Clickable", () => {
const onClick = jest.fn();
const NonNativeClickable = React.forwardRef(
(props, ref) =>
);
const { getByText } = render(
clickable
);
const clickable = getByText("clickable");
press.Enter(clickable);
expect(onClick).toHaveBeenCalledTimes(1);
});