Merge branch 'main' into 21720-material-ui-upgrade
[arvados.git] / services / workbench2 / src / store / data-explorer / data-explorer-reducer.cy.js
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, DataTableRequestState } 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 = [{
14             name: "Column 1",
15             filters: [],
16             render: cy.stub(),
17             selected: true,
18             configurable: true,
19             sort: {direction: SortDirection.NONE, field: "name"}
20         }];
21         const state = dataExplorerReducer(undefined,
22             dataExplorerActions.SET_COLUMNS({ id: "Data explorer", columns }));
23         expect(state["Data explorer"].columns).to.equal(columns);
24     });
25
26     it('should toggle sorting', () => {
27         const columns = [{
28             name: "Column 1",
29             filters: [],
30             render: cy.stub(),
31             selected: true,
32             sort: {direction: SortDirection.ASC, field: "name"},
33             configurable: true
34         }, {
35             name: "Column 2",
36             filters: [],
37             render: cy.stub(),
38             selected: true,
39             configurable: true,
40             sort: {direction: SortDirection.NONE, field: "name"},
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].sort.direction).to.equal("none");
45         expect(state["Data explorer"].columns[1].sort.direction).to.equal("asc");
46     });
47
48     it('should set filters', () => {
49         const columns = [{
50             name: "Column 1",
51             filters: [],
52             render: cy.stub(),
53             selected: true,
54             configurable: true,
55             sort: {direction: SortDirection.NONE, field: "name"}
56         }];
57
58         const filters = [{
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).to.equal(filters);
65     });
66
67     it('should set items', () => {
68         const items = ["Item 1", "Item 2"];
69         let state = dataExplorerReducer({},
70             dataExplorerActions.SET_REQUEST_STATE({
71                 id: "Data explorer",
72                 requestState: DataTableRequestState.PENDING
73             }));
74         state = dataExplorerReducer(state,
75             dataExplorerActions.SET_ITEMS({
76                 id: "Data explorer",
77                 items: items,
78                 page: 0,
79                 rowsPerPage: 10,
80                 itemsAvailable: 100
81             }));
82         expect(state["Data explorer"].items).to.equal(items);
83     });
84
85     it('should set page', () => {
86         const state = dataExplorerReducer({},
87             dataExplorerActions.SET_PAGE({ id: "Data explorer", page: 2 }));
88         expect(state["Data explorer"].page).to.equal(2);
89     });
90
91     it('should set rows per page', () => {
92         const state = dataExplorerReducer({},
93             dataExplorerActions.SET_ROWS_PER_PAGE({ id: "Data explorer", rowsPerPage: 5 }));
94         expect(state["Data explorer"].rowsPerPage).to.equal(5);
95     });
96 });