import React from "react";
import "@testing-library/jest-dom/extend-expect";
import { render, fireEvent, act } from "@testing-library/react";
import Popover from "../popover";
test("should open base popover", () => {
const { queryByTestId } = render(
Click me} placement={undefined}>
Content
);
expect(queryByTestId("click-id")).toBeTruthy();
expect(queryByTestId("honeyui-popover")).toBeTruthy();
expect(queryByTestId("honeyui-popover")).not.toHaveClass("show");
fireEvent.click(queryByTestId("click-id"));
expect(queryByTestId("honeyui-popover")).toHaveClass("show");
fireEvent.click(document.body);
expect(queryByTestId("honeyui-popover")).not.toHaveClass("show");
});
test("should have custom className", () => {
const { queryByTestId } = render(
Click me}
placement="bottom"
>
Content
);
expect(queryByTestId("popover-id")).toBeTruthy();
expect(queryByTestId("popover-id")).toHaveClass("test-class");
});
test("should have correct placement", () => {
const popover1 = render(
Click me}
>
Content
);
expect(popover1.queryByTestId("popover-id")).toBeTruthy();
expect(popover1.queryByTestId("popover-id")).toHaveClass("bs-popover-top");
expect(popover1.queryByTestId("popover-id")).toHaveClass("bs-popover-end");
});
test("should have content", () => {
const popover1 = render(
Content}
reference={Click me}
/>
);
expect(popover1.queryByTestId("popover-content3")).toBeTruthy();
});
test("should have support external close", () => {
const actionsRef = React.createRef<{ close: () => void }>();
const popover = render(
Content}
reference={}
/>
);
expect(popover.queryByTestId("popover-id")).not.toHaveClass("show");
fireEvent.click(popover.queryByTestId("click-id"));
expect(popover.queryByTestId("popover-id")).toHaveClass("show");
act(() => {
actionsRef.current.close();
});
expect(popover.queryByTestId("popover-id")).not.toHaveClass("show");
});