1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from "react";
6 import { configure, mount } from "enzyme";
7 import Adapter from "enzyme-adapter-react-16";
9 import { DataExplorer } from "./data-explorer";
10 import { ColumnSelector } from "../column-selector/column-selector";
11 import { DataTable, DataTableFetchMode } from "../data-table/data-table";
12 import { SearchInput } from "../search-input/search-input";
13 import { TablePagination } from "@material-ui/core";
14 import { ProjectIcon } from "../icon/icon";
15 import { SortDirection } from "../data-table/data-column";
16 import { combineReducers, createStore } from "redux";
17 import { Provider } from "react-redux";
19 configure({ adapter: new Adapter() });
21 describe("<DataExplorer />", () => {
24 const initialMSState = {
33 multiselect: (state: any = initialMSState.multiselect, action: any) => state,
34 resources: (state: any = initialMSState.resources, action: any) => state,
39 it("communicates with <SearchInput/>", () => {
40 const onSearch = jest.fn();
41 const onSetColumns = jest.fn();
43 const dataExplorer = mount(
44 <Provider store={store}>
46 {...mockDataExplorerProps()}
47 items={[{ name: "item 1" }]}
48 searchValue="search value"
50 onSetColumns={onSetColumns}
54 expect(dataExplorer.find(SearchInput).prop("value")).toEqual("search value");
55 dataExplorer.find(SearchInput).prop("onSearch")("new value");
56 expect(onSearch).toHaveBeenCalledWith("new value");
59 it("communicates with <ColumnSelector/>", () => {
60 const onColumnToggle = jest.fn();
61 const onSetColumns = jest.fn();
62 const columns = [{ name: "Column 1", render: jest.fn(), selected: true, configurable: true, sortDirection: SortDirection.ASC, filters: {} }];
63 const dataExplorer = mount(
64 <Provider store={store}>
66 {...mockDataExplorerProps()}
68 onColumnToggle={onColumnToggle}
69 items={[{ name: "item 1" }]}
70 onSetColumns={onSetColumns}
74 expect(dataExplorer.find(ColumnSelector).prop("columns")).toBe(columns);
75 dataExplorer.find(ColumnSelector).prop("onColumnToggle")("columns");
76 expect(onColumnToggle).toHaveBeenCalledWith("columns");
79 it("communicates with <DataTable/>", () => {
80 const onFiltersChange = jest.fn();
81 const onSortToggle = jest.fn();
82 const onRowClick = jest.fn();
83 const onSetColumns = jest.fn();
84 const columns = [{ name: "Column 1", render: jest.fn(), selected: true, configurable: true, sortDirection: SortDirection.ASC, filters: {} }];
85 const items = [{ name: "item 1" }];
86 const dataExplorer = mount(
87 <Provider store={store}>
89 {...mockDataExplorerProps()}
92 onFiltersChange={onFiltersChange}
93 onSortToggle={onSortToggle}
94 onRowClick={onRowClick}
95 onSetColumns={onSetColumns}
99 expect(dataExplorer.find(DataTable).prop("columns").slice(1, 2)).toEqual(columns);
100 expect(dataExplorer.find(DataTable).prop("items")).toBe(items);
101 dataExplorer.find(DataTable).prop("onRowClick")("event", "rowClick");
102 dataExplorer.find(DataTable).prop("onFiltersChange")("filtersChange");
103 dataExplorer.find(DataTable).prop("onSortToggle")("sortToggle");
104 expect(onFiltersChange).toHaveBeenCalledWith("filtersChange");
105 expect(onSortToggle).toHaveBeenCalledWith("sortToggle");
106 expect(onRowClick).toHaveBeenCalledWith("rowClick");
109 it("communicates with <TablePagination/>", () => {
110 const onChangePage = jest.fn();
111 const onChangeRowsPerPage = jest.fn();
112 const onSetColumns = jest.fn();
113 const dataExplorer = mount(
114 <Provider store={store}>
116 {...mockDataExplorerProps()}
117 items={[{ name: "item 1" }]}
120 onChangePage={onChangePage}
121 onChangeRowsPerPage={onChangeRowsPerPage}
122 onSetColumns={onSetColumns}
126 expect(dataExplorer.find(TablePagination).prop("page")).toEqual(10);
127 expect(dataExplorer.find(TablePagination).prop("rowsPerPage")).toEqual(50);
128 dataExplorer.find(TablePagination).prop("onChangePage")(undefined, 6);
129 dataExplorer.find(TablePagination).prop("onChangeRowsPerPage")({ target: { value: 10 } });
130 expect(onChangePage).toHaveBeenCalledWith(6);
131 expect(onChangeRowsPerPage).toHaveBeenCalledWith(10);
135 const mockDataExplorerProps = () => ({
136 fetchMode: DataTableFetchMode.PAGINATED,
144 rowsPerPageOptions: [0],
146 onFiltersChange: jest.fn(),
147 onSortToggle: jest.fn(),
148 onRowClick: jest.fn(),
149 onRowDoubleClick: jest.fn(),
150 onColumnToggle: jest.fn(),
151 onChangePage: jest.fn(),
152 onChangeRowsPerPage: jest.fn(),
153 onContextMenu: jest.fn(),
154 defaultIcon: ProjectIcon,
155 onSetColumns: jest.fn(),
156 onLoadMore: jest.fn(),
157 defaultMessages: ["testing"],
158 contextMenuColumn: true,
159 setCheckedListOnStore: jest.fn(),
160 toggleMSToolbar: jest.fn(),
161 isMSToolbarVisible: false,