1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
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";
11 describe('data-explorer-reducer', () => {
12 it('should set columns', () => {
19 sort: {direction: SortDirection.NONE, field: "name"}
21 const state = dataExplorerReducer(undefined,
22 dataExplorerActions.SET_COLUMNS({ id: "Data explorer", columns }));
23 expect(state["Data explorer"].columns).to.equal(columns);
26 it('should toggle sorting', () => {
32 sort: {direction: SortDirection.ASC, field: "name"},
40 sort: {direction: SortDirection.NONE, field: "name"},
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");
48 it('should set filters', () => {
55 sort: {direction: SortDirection.NONE, field: "name"}
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);
67 it('should set items', () => {
68 const items = ["Item 1", "Item 2"];
69 let state = dataExplorerReducer({},
70 dataExplorerActions.SET_REQUEST_STATE({
72 requestState: DataTableRequestState.PENDING
74 state = dataExplorerReducer(state,
75 dataExplorerActions.SET_ITEMS({
82 expect(state["Data explorer"].items).to.equal(items);
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);
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);