// Copyright (C) The Arvados Authors. All rights reserved.
//
// SPDX-License-Identifier: AGPL-3.0
import React from "react";
import { mount, configure } from "enzyme";
import Adapter from "enzyme-adapter-react-16";
import { Popover, DefaultTrigger } from "./popover";
import Button, { ButtonProps } from "@material-ui/core/Button";
configure({ adapter: new Adapter() });
describe("", () => {
it("opens on default trigger click", () => {
const popover = mount();
popover.find(DefaultTrigger).simulate("click");
expect((popover.state() as any).anchorEl).toBeDefined();
});
it("renders custom trigger", () => {
const popover = mount();
expect(popover.find(Button).text()).toBe("Open popover");
});
it("opens on custom trigger click", () => {
const popover = mount();
popover.find(CustomTrigger).simulate("click");
expect((popover.state() as any).anchorEl).toBeDefined();
});
it("renders children when opened", () => {
const popover = mount(
);
popover.find(DefaultTrigger).simulate("click");
expect(popover.find(CustomTrigger)).toHaveLength(1);
});
it("does not close if closeOnContentClick is not set", () => {
const popover = mount(
);
popover.find(DefaultTrigger).simulate("click");
popover.find(CustomTrigger).simulate("click");
expect((popover.state() as any).anchorEl).toBeDefined();
});
it("closes on content click if closeOnContentClick is set", () => {
const popover = mount(
);
popover.find(DefaultTrigger).simulate("click");
popover.find(CustomTrigger).simulate("click");
expect((popover.state() as any).anchorEl).toBeUndefined();
});
});
const CustomTrigger: React.SFC = (props) => (
);