1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from "react";
6 import { mount, configure } from "enzyme";
7 import * as Adapter from "enzyme-adapter-react-16";
9 import { Popover, DefaultTrigger } from "./popover";
10 import Button, { ButtonProps } from "@material-ui/core/Button";
12 configure({ adapter: new Adapter() });
14 describe("<Popover />", () => {
15 it("opens on default trigger click", () => {
16 const popover = mount(<Popover />);
17 popover.find(DefaultTrigger).simulate("click");
18 expect((popover.state() as any).anchorEl).toBeDefined();
21 it("renders custom trigger", () => {
22 const popover = mount(<Popover triggerComponent={CustomTrigger} />);
23 expect(popover.find(Button).text()).toBe("Open popover");
26 it("opens on custom trigger click", () => {
27 const popover = mount(<Popover triggerComponent={CustomTrigger} />);
28 popover.find(CustomTrigger).simulate("click");
29 expect((popover.state() as any).anchorEl).toBeDefined();
32 it("renders children when opened", () => {
33 const popover = mount(
38 popover.find(DefaultTrigger).simulate("click");
39 expect(popover.find(CustomTrigger)).toHaveLength(1);
42 it("does not close if closeOnContentClick is not set", () => {
43 const popover = mount(
48 popover.find(DefaultTrigger).simulate("click");
49 popover.find(CustomTrigger).simulate("click");
50 expect((popover.state() as any).anchorEl).toBeDefined();
52 it("closes on content click if closeOnContentClick is set", () => {
53 const popover = mount(
54 <Popover closeOnContentClick>
58 popover.find(DefaultTrigger).simulate("click");
59 popover.find(CustomTrigger).simulate("click");
60 expect((popover.state() as any).anchorEl).toBeUndefined();
65 const CustomTrigger: React.SFC<ButtonProps> = (props) => (