Extract generic context-menu component
[arvados-workbench2.git] / src / components / context-menu / 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         icon: "",
24         name: "Action 1.1",
25         onClick: jest.fn()
26     },
27     {
28         icon: "",
29         name: "Action 1.2",
30         onClick: jest.fn()
31     },], [{
32         icon: "",
33         name: "Action 2.1",
34         onClick: jest.fn()
35     }]];
36
37     it("calls provided actions with provided item", () => {
38         const contextMenu = mount(<ContextMenu
39             anchorEl={document.createElement("div")}
40             onClose={jest.fn()}
41             {...{ actions, item }} />);
42
43         contextMenu.find(ListItem).at(0).simulate("click");
44         contextMenu.find(ListItem).at(1).simulate("click");
45         contextMenu.find(ListItem).at(2).simulate("click");
46
47         expect(actions[0][0].onClick).toHaveBeenCalledWith(item);
48         expect(actions[0][1].onClick).toHaveBeenCalledWith(item);
49         expect(actions[1][0].onClick).toHaveBeenCalledWith(item);
50     });
51 });