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() });
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
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