X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/eede2d8dc696f24552414b2425bb5d3a745280cc..9e4b7889a99ff2f76d8029aef3a85c4620178ba3:/src/components/dropdown-menu/dropdown-menu.test.tsx

diff --git a/src/components/dropdown-menu/dropdown-menu.test.tsx b/src/components/dropdown-menu/dropdown-menu.test.tsx
new file mode 100644
index 00000000..19924ad7
--- /dev/null
+++ b/src/components/dropdown-menu/dropdown-menu.test.tsx
@@ -0,0 +1,43 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import * as React from "react";
+import { shallow, configure } from "enzyme";
+import DropdownMenu from "./dropdown-menu";
+import ChevronRightIcon from '@material-ui/icons/ChevronRight';
+
+import * as Adapter from 'enzyme-adapter-react-16';
+import { MenuItem, IconButton, Menu } from "@material-ui/core";
+
+configure({ adapter: new Adapter() });
+
+describe("<DropdownMenu />", () => {
+    it("renders menu icon", () => {
+        const dropdownMenu = shallow(<DropdownMenu id="test-menu" icon={ChevronRightIcon} />);
+        expect(dropdownMenu.find(ChevronRightIcon)).toHaveLength(1);
+    });
+
+    it("render menu items", () => {
+        const dropdownMenu = shallow(
+            <DropdownMenu id="test-menu" icon={ChevronRightIcon}>
+                <MenuItem>Item 1</MenuItem>
+                <MenuItem>Item 2</MenuItem>
+            </DropdownMenu>
+        );
+        expect(dropdownMenu.find(MenuItem)).toHaveLength(2);
+    });
+
+    it("opens on menu icon click", () => {
+        const dropdownMenu = shallow(<DropdownMenu id="test-menu" icon={ChevronRightIcon} />);
+        dropdownMenu.find(IconButton).simulate("click", {currentTarget: {}});
+        expect(dropdownMenu.state().anchorEl).toBeDefined();
+    });
+    
+    it("closes on menu click", () => {
+        const dropdownMenu = shallow(<DropdownMenu id="test-menu" icon={ChevronRightIcon} />);
+        dropdownMenu.find(Menu).simulate("click", {currentTarget: {}});
+        expect(dropdownMenu.state().anchorEl).toBeUndefined();
+    });
+
+});
\ No newline at end of file
