1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from "react";
6 import { mount, configure } from "enzyme";
7 import * as Adapter from 'enzyme-adapter-react-16';
9 import DataExplorer from "./data-explorer";
10 import ContextMenu from "../context-menu/context-menu";
11 import ColumnSelector from "../column-selector/column-selector";
12 import DataTable from "../data-table/data-table";
14 configure({ adapter: new Adapter() });
16 describe("<DataExplorer />", () => {
17 it("communicates with <ContextMenu/>", () => {
18 const onContextAction = jest.fn();
19 const dataExplorer = mount(<DataExplorer
21 onContextAction={onContextAction}
23 columns={[{ name: "Column 1", render: jest.fn(), selected: true }]}
24 onColumnToggle={jest.fn()}
25 onFiltersChange={jest.fn()}
26 onRowClick={jest.fn()}
27 onSortToggle={jest.fn()} />);
29 expect(dataExplorer.find(ContextMenu).prop("actions")).toEqual([]);
30 dataExplorer.setState({ contextMenu: { item: "Item 1" } });
31 dataExplorer.find(ContextMenu).prop("onActionClick")({ name: "Action 1", icon: "" });
32 expect(onContextAction).toHaveBeenCalledWith({ name: "Action 1", icon: "" }, "Item 1");
35 it("communicates with <ColumnSelector/>", () => {
36 const onColumnToggle = jest.fn();
37 const columns = [{ name: "Column 1", render: jest.fn(), selected: true }];
38 const dataExplorer = mount(<DataExplorer
40 onColumnToggle={onColumnToggle}
42 onContextAction={jest.fn()}
44 onFiltersChange={jest.fn()}
45 onRowClick={jest.fn()}
46 onSortToggle={jest.fn()} />);
48 expect(dataExplorer.find(ColumnSelector).prop("columns")).toBe(columns);
49 dataExplorer.find(ColumnSelector).prop("onColumnToggle")("columns");
50 expect(onColumnToggle).toHaveBeenCalledWith("columns");
53 it("communicates with <DataTable/>", () => {
54 const onFiltersChange = jest.fn();
55 const onSortToggle = jest.fn();
56 const onRowClick = jest.fn();
57 const columns = [{ name: "Column 1", render: jest.fn(), selected: true }];
58 const items = ["Item 1"];
59 const dataExplorer = mount(<DataExplorer
62 onFiltersChange={onFiltersChange}
63 onSortToggle={onSortToggle}
64 onRowClick={onRowClick}
65 onColumnToggle={jest.fn()}
67 onContextAction={jest.fn()} />);
69 expect(dataExplorer.find(DataTable).prop("columns")).toBe(columns);
70 expect(dataExplorer.find(DataTable).prop("items")).toBe(items);
71 dataExplorer.find(DataTable).prop("onRowClick")("event", "rowClick");
72 dataExplorer.find(DataTable).prop("onFiltersChange")("filtersChange");
73 dataExplorer.find(DataTable).prop("onSortToggle")("sortToggle");
74 expect(onFiltersChange).toHaveBeenCalledWith("filtersChange");
75 expect(onSortToggle).toHaveBeenCalledWith("sortToggle");
76 expect(onRowClick).toHaveBeenCalledWith("rowClick");