5ced213a3fb69435f42b1d3a8ba9bc9e93610df9
[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 import { ShareIcon } from "../icon/icon";
11
12 configure({ adapter: new Adapter() });
13
14 describe("<ContextMenu />", () => {
15     const items = [[{
16         icon: ShareIcon,
17         name: "Action 1.1"
18     }, {
19         icon: ShareIcon,
20         name: "Action 1.2"
21     },], [{
22         icon: ShareIcon,
23         name: "Action 2.1"
24     }]];
25
26     it("calls onItemClick with clicked action", () => {
27         const onItemClick = jest.fn();
28         const contextMenu = mount(<ContextMenu
29             anchorEl={document.createElement("div")}
30             open={true}
31             onClose={jest.fn()}
32             onItemClick={onItemClick}
33             items={items} />);
34         contextMenu.find(ListItem).at(2).simulate("click");
35         expect(onItemClick).toHaveBeenCalledWith(items[1][0]);
36     });
37 });