1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from "react";
6 import { shallow, configure } from "enzyme";
7 import { DropdownMenu } from "./dropdown-menu";
8 import Adapter from 'enzyme-adapter-react-16';
9 import { MenuItem, IconButton, Menu } from "@material-ui/core";
10 import { PaginationRightArrowIcon } from "../icon/icon";
12 configure({ adapter: new Adapter() });
14 describe("<DropdownMenu />", () => {
15 it("renders menu icon", () => {
16 const dropdownMenu = shallow(<DropdownMenu id="test-menu" icon={<PaginationRightArrowIcon />} />);
17 expect(dropdownMenu.find(PaginationRightArrowIcon)).toHaveLength(1);
20 it("render menu items", () => {
21 const dropdownMenu = shallow(
22 <DropdownMenu id="test-menu" icon={<PaginationRightArrowIcon />}>
23 <MenuItem>Item 1</MenuItem>
24 <MenuItem>Item 2</MenuItem>
27 expect(dropdownMenu.find(MenuItem)).toHaveLength(2);
30 it("opens on menu icon click", () => {
31 const dropdownMenu = shallow(<DropdownMenu id="test-menu" icon={<PaginationRightArrowIcon />} />);
32 dropdownMenu.find(IconButton).simulate("click", {currentTarget: {}});
33 expect((dropdownMenu.state() as any).anchorEl).toBeDefined();
36 it("closes on menu click", () => {
37 const dropdownMenu = shallow(<DropdownMenu id="test-menu" icon={<PaginationRightArrowIcon />} />);
38 dropdownMenu.find(Menu).simulate("click", {currentTarget: {}});
39 expect((dropdownMenu.state() as any).anchorEl).toBeUndefined();