16622: Tweak icon & titles
[arvados.git] / src / components / data-explorer / data-explorer.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 { configure, mount } from "enzyme";
7 import * as Adapter from 'enzyme-adapter-react-16';
8
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
17 configure({ adapter: new Adapter() });
18
19 describe("<DataExplorer />", () => {
20
21     it("communicates with <SearchInput/>", () => {
22         const onSearch = jest.fn();
23         const onSetColumns = jest.fn();
24         const dataExplorer = mount(<DataExplorer
25             {...mockDataExplorerProps()}
26             items={[{ name: "item 1" }]}
27             searchValue="search value"
28             onSearch={onSearch}
29             onSetColumns={onSetColumns} />);
30         expect(dataExplorer.find(SearchInput).prop("value")).toEqual("search value");
31         dataExplorer.find(SearchInput).prop("onSearch")("new value");
32         expect(onSearch).toHaveBeenCalledWith("new value");
33     });
34
35     it("communicates with <ColumnSelector/>", () => {
36         const onColumnToggle = jest.fn();
37         const onSetColumns = jest.fn();
38         const columns = [{ name: "Column 1", render: jest.fn(), selected: true, configurable: true, sortDirection: SortDirection.ASC, filters: {} }];
39         const dataExplorer = mount(<DataExplorer
40             {...mockDataExplorerProps()}
41             columns={columns}
42             onColumnToggle={onColumnToggle}
43             items={[{ name: "item 1" }]}
44             onSetColumns={onSetColumns} />);
45         expect(dataExplorer.find(ColumnSelector).prop("columns")).toBe(columns);
46         dataExplorer.find(ColumnSelector).prop("onColumnToggle")("columns");
47         expect(onColumnToggle).toHaveBeenCalledWith("columns");
48     });
49
50     it("communicates with <DataTable/>", () => {
51         const onFiltersChange = jest.fn();
52         const onSortToggle = jest.fn();
53         const onRowClick = jest.fn();
54         const onSetColumns = jest.fn();
55         const columns = [{ name: "Column 1", render: jest.fn(), selected: true, configurable: true, sortDirection: SortDirection.ASC, filters: {} }];
56         const items = [{ name: "item 1" }];
57         const dataExplorer = mount(<DataExplorer
58             {...mockDataExplorerProps()}
59             columns={columns}
60             items={items}
61             onFiltersChange={onFiltersChange}
62             onSortToggle={onSortToggle}
63             onRowClick={onRowClick}
64             onSetColumns={onSetColumns} />);
65         expect(dataExplorer.find(DataTable).prop("columns").slice(0, -1)).toEqual(columns);
66         expect(dataExplorer.find(DataTable).prop("items")).toBe(items);
67         dataExplorer.find(DataTable).prop("onRowClick")("event", "rowClick");
68         dataExplorer.find(DataTable).prop("onFiltersChange")("filtersChange");
69         dataExplorer.find(DataTable).prop("onSortToggle")("sortToggle");
70         expect(onFiltersChange).toHaveBeenCalledWith("filtersChange");
71         expect(onSortToggle).toHaveBeenCalledWith("sortToggle");
72         expect(onRowClick).toHaveBeenCalledWith("rowClick");
73     });
74
75     it("communicates with <TablePagination/>", () => {
76         const onChangePage = jest.fn();
77         const onChangeRowsPerPage = jest.fn();
78         const onSetColumns = jest.fn();
79         const dataExplorer = mount(<DataExplorer
80             {...mockDataExplorerProps()}
81             items={[{ name: "item 1" }]}
82             page={10}
83             rowsPerPage={50}
84             onChangePage={onChangePage}
85             onChangeRowsPerPage={onChangeRowsPerPage}
86             onSetColumns={onSetColumns} />);
87         expect(dataExplorer.find(TablePagination).prop("page")).toEqual(10);
88         expect(dataExplorer.find(TablePagination).prop("rowsPerPage")).toEqual(50);
89         dataExplorer.find(TablePagination).prop("onChangePage")(undefined, 6);
90         dataExplorer.find(TablePagination).prop("onChangeRowsPerPage")({ target: { value: 10 } });
91         expect(onChangePage).toHaveBeenCalledWith(6);
92         expect(onChangeRowsPerPage).toHaveBeenCalledWith(10);
93     });
94 });
95
96 const mockDataExplorerProps = () => ({
97     fetchMode: DataTableFetchMode.PAGINATED,
98     columns: [],
99     items: [],
100     itemsAvailable: 0,
101     contextActions: [],
102     searchValue: "",
103     page: 0,
104     rowsPerPage: 0,
105     rowsPerPageOptions: [0],
106     onSearch: jest.fn(),
107     onFiltersChange: jest.fn(),
108     onSortToggle: jest.fn(),
109     onRowClick: jest.fn(),
110     onRowDoubleClick: jest.fn(),
111     onColumnToggle: jest.fn(),
112     onChangePage: jest.fn(),
113     onChangeRowsPerPage: jest.fn(),
114     onContextMenu: jest.fn(),
115     defaultIcon: ProjectIcon,
116     onSetColumns: jest.fn(),
117     onLoadMore: jest.fn(),
118     defaultMessages: ['testing'],
119     contextMenuColumn: true
120 });