Extract generic context-menu component
[arvados-workbench2.git] / src / components / context-menu / context-menu.test.tsx
similarity index 50%
rename from src/components/data-explorer/context-menu.test.tsx
rename to src/components/context-menu/context-menu.test.tsx
index 892180890efe1e11efa6404216d08fb219552b88..9e4a9a4758a22c4c8aee29d794689327ba9826a8 100644 (file)
@@ -5,7 +5,7 @@
 import * as React from "react";
 import { mount, configure, shallow } from "enzyme";
 import * as Adapter from "enzyme-adapter-react-16";
-import { ContextMenu } from "./context-menu";
+import ContextMenu from "./context-menu";
 import { ListItem } from "@material-ui/core";
 
 configure({ adapter: new Adapter() });
@@ -19,15 +19,20 @@ describe("<ContextMenu />", () => {
         type: ""
     };
 
-    const actions = {
-        onAddToFavourite: jest.fn(),
-        onCopy: jest.fn(),
-        onDownload: jest.fn(),
-        onMoveTo: jest.fn(),
-        onRemove: jest.fn(),
-        onRename: jest.fn(),
-        onShare: jest.fn()
-    };
+    const actions = [[{
+        icon: "",
+        name: "Action 1.1",
+        onClick: jest.fn()
+    },
+    {
+        icon: "",
+        name: "Action 1.2",
+        onClick: jest.fn()
+    },], [{
+        icon: "",
+        name: "Action 2.1",
+        onClick: jest.fn()
+    }]];
 
     it("calls provided actions with provided item", () => {
         const contextMenu = mount(<ContextMenu
@@ -35,12 +40,12 @@ describe("<ContextMenu />", () => {
             onClose={jest.fn()}
             {...{ actions, item }} />);
 
-        for (let index = 0; index < Object.keys(actions).length; index++) {
-            contextMenu.find(ListItem).at(index).simulate("click");
-        }
+        contextMenu.find(ListItem).at(0).simulate("click");
+        contextMenu.find(ListItem).at(1).simulate("click");
+        contextMenu.find(ListItem).at(2).simulate("click");
 
-        Object.keys(actions).forEach(key => {
-            expect(actions[key]).toHaveBeenCalledWith(item);
-        });
+        expect(actions[0][0].onClick).toHaveBeenCalledWith(item);
+        expect(actions[0][1].onClick).toHaveBeenCalledWith(item);
+        expect(actions[1][0].onClick).toHaveBeenCalledWith(item);
     });
 });
\ No newline at end of file