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";
13 import SearchInput from "../search-input/search-input";
15 configure({ adapter: new Adapter() });
17 describe("<DataExplorer />", () => {
18 it("communicates with <ContextMenu/>", () => {
19 const onContextAction = jest.fn();
20 const dataExplorer = mount(<DataExplorer
21 {...mockDataExplorerProps()}
23 onContextAction={onContextAction}
25 columns={[{ name: "Column 1", render: jest.fn(), selected: true }]} />);
26 expect(dataExplorer.find(ContextMenu).prop("actions")).toEqual([]);
27 dataExplorer.find(DataTable).prop("onRowContextMenu")({
28 preventDefault: jest.fn()
30 dataExplorer.find(ContextMenu).prop("onActionClick")({ name: "Action 1", icon: "" });
31 expect(onContextAction).toHaveBeenCalledWith({ name: "Action 1", icon: "" }, "Item 1");
34 it("communicates with <SearchInput/>", () => {
35 const onSearch = jest.fn();
36 const dataExplorer = mount(<DataExplorer
37 {...mockDataExplorerProps()}
38 searchValue="search value"
39 onSearch={onSearch}/>);
40 expect(dataExplorer.find(SearchInput).prop("value")).toEqual("search value");
41 dataExplorer.find(SearchInput).prop("onSearch")("new value");
42 expect(onSearch).toHaveBeenCalledWith("new value");
45 it("communicates with <ColumnSelector/>", () => {
46 const onColumnToggle = jest.fn();
47 const columns = [{ name: "Column 1", render: jest.fn(), selected: true }];
48 const dataExplorer = mount(<DataExplorer
49 {...mockDataExplorerProps()}
51 onColumnToggle={onColumnToggle}
53 items={["Item 1"]} />);
54 expect(dataExplorer.find(ColumnSelector).prop("columns")).toBe(columns);
55 dataExplorer.find(ColumnSelector).prop("onColumnToggle")("columns");
56 expect(onColumnToggle).toHaveBeenCalledWith("columns");
59 it("communicates with <DataTable/>", () => {
60 const onFiltersChange = jest.fn();
61 const onSortToggle = jest.fn();
62 const onRowClick = jest.fn();
63 const columns = [{ name: "Column 1", render: jest.fn(), selected: true }];
64 const items = ["Item 1"];
65 const dataExplorer = mount(<DataExplorer
66 {...mockDataExplorerProps()}
69 onFiltersChange={onFiltersChange}
70 onSortToggle={onSortToggle}
71 onRowClick={onRowClick} />);
72 expect(dataExplorer.find(DataTable).prop("columns")).toBe(columns);
73 expect(dataExplorer.find(DataTable).prop("items")).toBe(items);
74 dataExplorer.find(DataTable).prop("onRowClick")("event", "rowClick");
75 dataExplorer.find(DataTable).prop("onFiltersChange")("filtersChange");
76 dataExplorer.find(DataTable).prop("onSortToggle")("sortToggle");
77 expect(onFiltersChange).toHaveBeenCalledWith("filtersChange");
78 expect(onSortToggle).toHaveBeenCalledWith("sortToggle");
79 expect(onRowClick).toHaveBeenCalledWith("rowClick");
83 const mockDataExplorerProps = () => ({
89 onFiltersChange: jest.fn(),
90 onSortToggle: jest.fn(),
91 onRowClick: jest.fn(),
92 onColumnToggle: jest.fn(),
93 onContextAction: jest.fn()