Create test for context menu
[arvados-workbench2.git] / src / components / data-explorer / context-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 { mount, configure, shallow } from "enzyme";
7 import * as Adapter from "enzyme-adapter-react-16";
8 import { ContextMenu } from "./context-menu";
9 import { ListItem } from "@material-ui/core";
10
11 configure({ adapter: new Adapter() });
12
13 describe("<ContextMenu />", () => {
14
15     const item = {
16         name: "",
17         owner: "",
18         lastModified: "",
19         type: ""
20     };
21
22     const actions = {
23         onAddToFavourite: jest.fn(),
24         onCopy: jest.fn(),
25         onDownload: jest.fn(),
26         onMoveTo: jest.fn(),
27         onRemove: jest.fn(),
28         onRename: jest.fn(),
29         onShare: jest.fn()
30     };
31
32     it("calls provided actions with provided item", () => {
33         const contextMenu = mount(<ContextMenu
34             anchorEl={document.createElement("div")}
35             onClose={jest.fn()}
36             {...{ actions, item }} />);
37
38         for (let index = 0; index < Object.keys(actions).length; index++) {
39             contextMenu.find(ListItem).at(index).simulate("click");
40         }
41
42         Object.keys(actions).forEach(key => {
43             expect(actions[key]).toHaveBeenCalledWith(item);
44         });
45     });
46 });