added-functionality-for-creating-projects
[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
13 configure({ adapter: new Adapter() });
14
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);
19     });
20
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>
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={ChevronRightIcon} />);
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={ChevronRightIcon} />);
39         dropdownMenu.find(Menu).simulate("click", {currentTarget: {}});
40         expect(dropdownMenu.state().anchorEl).toBeUndefined();
41     });
42
43 });