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 } 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', () => {
13 const columns: DataColumns<any> = [{
19 const state = dataExplorerReducer(undefined,
20 dataExplorerActions.SET_COLUMNS({ id: "Data explorer", columns }));
21 expect(state["Data explorer"].columns).toEqual(columns);
24 it('should toggle sorting', () => {
25 const columns: DataColumns<any> = [{
30 sortDirection: SortDirection.ASC
36 sortDirection: SortDirection.NONE,
38 const state = dataExplorerReducer({ "Data explorer": { ...initialDataExplorer, columns } },
39 dataExplorerActions.TOGGLE_SORT({ id: "Data explorer", columnName: "Column 2" }));
40 expect(state["Data explorer"].columns[0].sortDirection).toEqual("none");
41 expect(state["Data explorer"].columns[1].sortDirection).toEqual("asc");
44 it('should set filters', () => {
45 const columns: DataColumns<any> = [{
52 const filters: DataTableFilterItem[] = [{
56 const state = dataExplorerReducer({ "Data explorer": { ...initialDataExplorer, columns } },
57 dataExplorerActions.SET_FILTERS({ id: "Data explorer", columnName: "Column 1", filters }));
58 expect(state["Data explorer"].columns[0].filters).toEqual(filters);
61 it('should set items', () => {
62 const state = dataExplorerReducer({},
63 dataExplorerActions.SET_ITEMS({
65 items: ["Item 1", "Item 2"],
70 expect(state["Data explorer"].items).toEqual(["Item 1", "Item 2"]);
73 it('should set page', () => {
74 const state = dataExplorerReducer({},
75 dataExplorerActions.SET_PAGE({ id: "Data explorer", page: 2 }));
76 expect(state["Data explorer"].page).toEqual(2);
79 it('should set rows per page', () => {
80 const state = dataExplorerReducer({},
81 dataExplorerActions.SET_ROWS_PER_PAGE({ id: "Data explorer", rowsPerPage: 5 }));
82 expect(state["Data explorer"].rowsPerPage).toEqual(5);