fix test
[arvados-workbench2.git] / src / components / dropdown-menu / dropdown-menu.test.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
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';
9
10 import * as Adapter from 'enzyme-adapter-react-16';
11 import { MenuItem, IconButton, Menu } from "@material-ui/core";
12 import IconBase, { IconTypes } from "../icon/icon";
13
14 configure({ adapter: new Adapter() });
15
16 describe("<DropdownMenu />", () => {
17     it("renders menu icon", () => {
18         const dropdownMenu = shallow(<DropdownMenu id="test-menu" icon={IconTypes.CHEVRON_RIGHT} />);
19         expect(dropdownMenu.find(IconBase)).toHaveLength(1);
20     });
21
22     it("render menu items", () => {
23         const dropdownMenu = shallow(
24             <DropdownMenu id="test-menu" icon={IconTypes.CHEVRON_RIGHT}>
25                 <MenuItem>Item 1</MenuItem>
26                 <MenuItem>Item 2</MenuItem>
27             </DropdownMenu>
28         );
29         expect(dropdownMenu.find(MenuItem)).toHaveLength(2);
30     });
31
32     it("opens on menu icon click", () => {
33         const dropdownMenu = shallow(<DropdownMenu id="test-menu" icon={IconTypes.CHEVRON_RIGHT} />);
34         dropdownMenu.find(IconButton).simulate("click", {currentTarget: {}});
35         expect(dropdownMenu.state().anchorEl).toBeDefined();
36     });
37     
38     it("closes on menu click", () => {
39         const dropdownMenu = shallow(<DropdownMenu id="test-menu" icon={IconTypes.CHEVRON_RIGHT} />);
40         dropdownMenu.find(Menu).simulate("click", {currentTarget: {}});
41         expect(dropdownMenu.state().anchorEl).toBeUndefined();
42     });
43
44 });