Merge branch '14470-replace-tree-pickers'
[arvados.git] / src / store / data-explorer / data-explorer-reducer.test.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { dataExplorerReducer, initialDataExplorer } from "./data-explorer-reducer";
6 import { dataExplorerActions } from "./data-explorer-action";
7 import { DataTableFilterItem } from "../../components/data-table-filters/data-table-filters";
8 import { DataColumns } from "../../components/data-table/data-table";
9 import { SortDirection } from "../../components/data-table/data-column";
10
11 describe('data-explorer-reducer', () => {
12     it('should set columns', () => {
13         const columns: DataColumns<any> = [{
14             name: "Column 1",
15             filters: [],
16             render: jest.fn(),
17             selected: true,
18             configurable: true,
19             sortDirection: SortDirection.NONE
20         }];
21         const state = dataExplorerReducer(undefined,
22             dataExplorerActions.SET_COLUMNS({ id: "Data explorer", columns }));
23         expect(state["Data explorer"].columns).toEqual(columns);
24     });
25
26     it('should toggle sorting', () => {
27         const columns: DataColumns<any> = [{
28             name: "Column 1",
29             filters: [],
30             render: jest.fn(),
31             selected: true,
32             sortDirection: SortDirection.ASC,
33             configurable: true
34         }, {
35             name: "Column 2",
36             filters: [],
37             render: jest.fn(),
38             selected: true,
39             configurable: true,
40             sortDirection: SortDirection.NONE,
41         }];
42         const state = dataExplorerReducer({ "Data explorer": { ...initialDataExplorer, columns } },
43             dataExplorerActions.TOGGLE_SORT({ id: "Data explorer", columnName: "Column 2" }));
44         expect(state["Data explorer"].columns[0].sortDirection).toEqual("none");
45         expect(state["Data explorer"].columns[1].sortDirection).toEqual("asc");
46     });
47
48     it('should set filters', () => {
49         const columns: DataColumns<any> = [{
50             name: "Column 1",
51             filters: [],
52             render: jest.fn(),
53             selected: true,
54             configurable: true,
55             sortDirection: SortDirection.NONE
56         }];
57
58         const filters: DataTableFilterItem[] = [{
59             name: "Filter 1",
60             selected: true
61         }];
62         const state = dataExplorerReducer({ "Data explorer": { ...initialDataExplorer, columns } },
63             dataExplorerActions.SET_FILTERS({ id: "Data explorer", columnName: "Column 1", filters }));
64         expect(state["Data explorer"].columns[0].filters).toEqual(filters);
65     });
66
67     it('should set items', () => {
68         const state = dataExplorerReducer({},
69             dataExplorerActions.SET_ITEMS({
70                 id: "Data explorer",
71                 items: ["Item 1", "Item 2"],
72                 page: 0,
73                 rowsPerPage: 10,
74                 itemsAvailable: 100
75             }));
76         expect(state["Data explorer"].items).toEqual(["Item 1", "Item 2"]);
77     });
78
79     it('should set page', () => {
80         const state = dataExplorerReducer({},
81             dataExplorerActions.SET_PAGE({ id: "Data explorer", page: 2 }));
82         expect(state["Data explorer"].page).toEqual(2);
83     });
84
85     it('should set rows per page', () => {
86         const state = dataExplorerReducer({},
87             dataExplorerActions.SET_ROWS_PER_PAGE({ id: "Data explorer", rowsPerPage: 5 }));
88         expect(state["Data explorer"].rowsPerPage).toEqual(5);
89     });
90 });