Create test for context menu
authorMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Tue, 19 Jun 2018 08:49:54 +0000 (10:49 +0200)
committerMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Tue, 19 Jun 2018 08:49:54 +0000 (10:49 +0200)
Feature #13634

Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski@contractors.roche.com>

src/components/data-explorer/context-menu.test.tsx [new file with mode: 0644]

diff --git a/src/components/data-explorer/context-menu.test.tsx b/src/components/data-explorer/context-menu.test.tsx
new file mode 100644 (file)
index 0000000..8921808
--- /dev/null
@@ -0,0 +1,46 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+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 { ListItem } from "@material-ui/core";
+
+configure({ adapter: new Adapter() });
+
+describe("<ContextMenu />", () => {
+
+    const item = {
+        name: "",
+        owner: "",
+        lastModified: "",
+        type: ""
+    };
+
+    const actions = {
+        onAddToFavourite: jest.fn(),
+        onCopy: jest.fn(),
+        onDownload: jest.fn(),
+        onMoveTo: jest.fn(),
+        onRemove: jest.fn(),
+        onRename: jest.fn(),
+        onShare: jest.fn()
+    };
+
+    it("calls provided actions with provided item", () => {
+        const contextMenu = mount(<ContextMenu
+            anchorEl={document.createElement("div")}
+            onClose={jest.fn()}
+            {...{ actions, item }} />);
+
+        for (let index = 0; index < Object.keys(actions).length; index++) {
+            contextMenu.find(ListItem).at(index).simulate("click");
+        }
+
+        Object.keys(actions).forEach(key => {
+            expect(actions[key]).toHaveBeenCalledWith(item);
+        });
+    });
+});
\ No newline at end of file