import * as React from "react";
import {render, fireEvent, act} from "@testing-library/react";
import {Button} from "@heroui/button";
import {spy, shouldIgnoreReactWarning} from "@heroui/test-utils";
import {Tooltip} from "../src";
describe("Tooltip", () => {
afterEach(() => {
jest.clearAllMocks();
});
it("should throw error if no children is passed", () => {
const spy = jest.spyOn(console, "warn").mockImplementation(() => {});
render();
expect(spy).toHaveBeenCalled();
});
it("should render correctly", () => {
const wrapper = render(
,
);
expect(() => wrapper.unmount()).not.toThrow();
if (!shouldIgnoreReactWarning(spy)) {
expect(spy).toHaveBeenCalledTimes(0);
}
});
it("ref should be forwarded", () => {
const ref = React.createRef();
render(
,
);
expect(ref.current).not.toBeNull();
});
it("should hide the tooltip when pressing the escape key", async () => {
const onClose = jest.fn();
const wrapper = render(
tooltip
} onClose={onClose}>
,
);
const content = wrapper.getByTestId("content-test");
await act(async () => {
await fireEvent.keyDown(content, {key: "Escape"});
expect(onClose).toHaveBeenCalledTimes(1);
});
});
it("should still hide the tooltip when pressing the escape key if isDismissable is false", () => {
const onClose = jest.fn();
const wrapper = render(
tooltip}
isDismissable={false}
onClose={onClose}
>
,
);
const content = wrapper.getByTestId("content-test");
fireEvent.keyDown(content, {key: "Escape"});
expect(onClose).toHaveBeenCalledTimes(1);
});
});