import React from "react";
import { render, screen, fireEvent } from "../utilities/test-utils";
import { Button, PbReactPopover } from "playbook-ui";
const testId = "popover-kit";
//Test default popover
const PopoverTest = () => {
const [mockState, setMockState] = React.useState(false)
const togglePopover = () => {
setMockState(!mockState)
}
const popoverReference = (
);
return (
{"Click Anywhere"}
)
};
//Test popover with z-index
const PopoverTestZIndex = () => {
const [mockState, setMockState] = React.useState(false)
const togglePopover = () => {
setMockState(!mockState)
}
const popoverReference = (
);
return (
{"Click Anywhere"}
)
};
//Test popover with max-height and max-width
const PopoverTestHeight = () => {
const [mockState, setMockState] = React.useState(false)
const togglePopover = () => {
setMockState(!mockState)
}
const popoverReference = (
);
return (
{"Click Anywhere"}
)
};
//Test Popover with click to close 'anywhere'
const PopoverTestClicktoClose = () => {
const [mockState, setMockState] = React.useState(false)
const togglePopover = () => {
setMockState(!mockState)
}
const handleShouldClosePopover = (shouldClosePopover) => {
setMockState(!shouldClosePopover)
}
const popoverReference = (
);
return (
{"Click Anywhere"}
)
};
//Test Popover with click to close 'inside'
const PopoverTestClicktoClose2 = () => {
const [mockState, setMockState] = React.useState(false)
const togglePopover = () => {
setMockState(!mockState)
}
const handleShouldClosePopover = (shouldClosePopover) => {
setMockState(!shouldClosePopover)
}
const popoverReference = (
);
return (
{"Click Inside"}
)
};
//Test Popover with click to close 'outside'
const PopoverTestClicktoClose3 = () => {
const [mockState, setMockState] = React.useState(false)
const togglePopover = () => {
setMockState(!mockState)
}
const handleShouldClosePopover = (shouldClosePopover) => {
setMockState(!shouldClosePopover)
}
const popoverReference = (
);
return (
{"Click Outside"}
)
};
test("renders Popover", () => {
render()
const btn = screen.getByText(/click me/i)
fireEvent.click(btn);
const kit = screen.getByText("Click Anywhere");
expect(kit).toBeInTheDocument();
});
test("renders Popover with z index", () => {
render()
const btn = screen.getByText(/click me/i)
fireEvent.click(btn);
const kit = screen.getByText("Click Anywhere");
expect(kit).toHaveClass("pb_popover_body z_index_3");
});
test("renders Popover with max height and max width", () => {
render()
const btn = screen.getByText(/click me/i)
fireEvent.click(btn);
const kit = screen.getByText("Click Anywhere");
expect(kit).toHaveClass("pb_popover_body max_width_240px overflow_handling");
});
test("closes Popover on click anywhere", async () => {
render()
const btn = screen.getByText(/click me/i)
fireEvent.click(btn);
const kit = screen.getByText("Click Anywhere");
expect(kit).toBeInTheDocument();
fireEvent.click(document.body);
expect(kit).not.toBeInTheDocument;
});
test("closes Popover on click inside", async () => {
render()
const btn = screen.getByText(/click me/i)
fireEvent.click(btn);
const kit = screen.getByText("Click Inside");
expect(kit).toBeInTheDocument();
fireEvent.click(kit);
expect(kit).not.toBeInTheDocument;
});
test("closes Popover on click outside", async () => {
render()
const btn = screen.getByText(/click me/i)
fireEvent.click(btn);
const kit = screen.getByText("Click Outside");
expect(kit).toBeInTheDocument();
fireEvent.click(kit);
expect(kit).toBeInTheDocument();
fireEvent.click(btn);
expect(kit).not.toBeInTheDocument;
});