08f5e0f8116e1f7730f0a9e253d2e1c410b989c7
[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 * as Adapter from 'enzyme-adapter-react-16';
9 import { MenuItem, IconButton, Menu } from "@material-ui/core";
10 import { PaginationRightArrowIcon } from "../icon/icon";
11 import ChevronRight from '@material-ui/icons/ChevronRight';
12
13 configure({ adapter: new Adapter() });
14
15 describe("<DropdownMenu />", () => {
16     it("renders menu icon", () => {
17         const dropdownMenu = shallow(<DropdownMenu id="test-menu" icon={PaginationRightArrowIcon()} />);
18         expect(dropdownMenu.find(ChevronRight)).toHaveLength(1);
19     });
20
21     it("render menu items", () => {
22         const dropdownMenu = shallow(
23             <DropdownMenu id="test-menu" icon={PaginationRightArrowIcon()}>
24                 <MenuItem>Item 1</MenuItem>
25                 <MenuItem>Item 2</MenuItem>
26             </DropdownMenu>
27         );
28         expect(dropdownMenu.find(MenuItem)).toHaveLength(2);
29     });
30
31     it("opens on menu icon click", () => {
32         const dropdownMenu = shallow(<DropdownMenu id="test-menu" icon={PaginationRightArrowIcon()} />);
33         dropdownMenu.find(IconButton).simulate("click", {currentTarget: {}});
34         expect(dropdownMenu.state().anchorEl).toBeDefined();
35     });
36     
37     it("closes on menu click", () => {
38         const dropdownMenu = shallow(<DropdownMenu id="test-menu" icon={PaginationRightArrowIcon()} />);
39         dropdownMenu.find(Menu).simulate("click", {currentTarget: {}});
40         expect(dropdownMenu.state().anchorEl).toBeUndefined();
41     });
42
43 });