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