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 sortDirection: SortDirection.NONE
21 const state = dataExplorerReducer(undefined,
22 dataExplorerActions.SET_COLUMNS({ id: "Data explorer", columns }));
23 expect(state["Data explorer"].columns).toEqual(columns);
26 it('should toggle sorting', () => {
27 const columns: DataColumns<any> = [{
32 sortDirection: SortDirection.ASC,
40 sortDirection: SortDirection.NONE,
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");
48 it('should set filters', () => {
49 const columns: DataColumns<any> = [{
55 sortDirection: SortDirection.NONE
58 const filters: DataTableFilterItem[] = [{
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);
67 it('should set items', () => {
68 const state = dataExplorerReducer({},
69 dataExplorerActions.SET_ITEMS({
71 items: ["Item 1", "Item 2"],
76 expect(state["Data explorer"].items).toEqual(["Item 1", "Item 2"]);
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);
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);