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 actions from "./data-explorer-action";
7 import { DataColumn } from "../../components/data-table/data-column";
8 import { DataTableFilterItem } from "../../components/data-table-filters/data-table-filters";
10 describe('data-explorer-reducer', () => {
11 it('should set columns', () => {
12 const columns: Array<DataColumn<any>> = [{
17 const state = dataExplorerReducer(undefined,
18 actions.SET_COLUMNS({ id: "Data explorer", columns }));
19 expect(state["Data explorer"].columns).toEqual(columns);
22 it('should toggle sorting', () => {
23 const columns: Array<DataColumn<any>> = [{
32 sortDirection: "none",
34 const state = dataExplorerReducer({ "Data explorer": { ...initialDataExplorer, columns } },
35 actions.TOGGLE_SORT({ id: "Data explorer", columnName: "Column 2" }));
36 expect(state["Data explorer"].columns[0].sortDirection).toEqual("none");
37 expect(state["Data explorer"].columns[1].sortDirection).toEqual("asc");
40 it('should set filters', () => {
41 const columns: Array<DataColumn<any>> = [{
47 const filters: DataTableFilterItem[] = [{
51 const state = dataExplorerReducer({ "Data explorer": { ...initialDataExplorer, columns } },
52 actions.SET_FILTERS({ id: "Data explorer", columnName: "Column 1", filters }));
53 expect(state["Data explorer"].columns[0].filters).toEqual(filters);
56 it('should set items', () => {
57 const state = dataExplorerReducer({ "Data explorer": undefined },
58 actions.SET_ITEMS({ id: "Data explorer", items: ["Item 1", "Item 2"] }));
59 expect(state["Data explorer"].items).toEqual(["Item 1", "Item 2"]);
62 it('should set page', () => {
63 const state = dataExplorerReducer({ "Data explorer": undefined },
64 actions.SET_PAGE({ id: "Data explorer", page: 2 }));
65 expect(state["Data explorer"].page).toEqual(2);
68 it('should set rows per page', () => {
69 const state = dataExplorerReducer({ "Data explorer": undefined },
70 actions.SET_ROWS_PER_PAGE({ id: "Data explorer", rowsPerPage: 5 }));
71 expect(state["Data explorer"].rowsPerPage).toEqual(5);