1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { DataExplorerMiddlewareService } from "./data-explorer-middleware-service";
6 import { dataExplorerMiddleware } from "./data-explorer-middleware";
7 import { dataExplorerActions } from "./data-explorer-action";
8 import { SortDirection } from "components/data-table/data-column";
9 import { createTree } from 'models/tree';
11 describe("DataExplorerMiddleware", () => {
13 it("handles only actions that are identified by service id", () => {
20 sortDirection: SortDirection.NONE,
21 filters: createTree(),
24 requestItems: cy.stub(),
27 const service = new ServiceMock(config);
32 const next = cy.stub();
33 const middleware = dataExplorerMiddleware(service)(api)(next);
34 middleware(dataExplorerActions.SET_PAGE({ id: "OtherId", page: 0 }));
35 middleware(dataExplorerActions.SET_PAGE({ id: "ServiceId", page: 0 }));
36 middleware(dataExplorerActions.SET_PAGE({ id: "OtherId", page: 0 }));
37 expect(api.dispatch).to.be.calledWithMatch(dataExplorerActions.REQUEST_ITEMS({ id: "ServiceId", criteriaChanged: false }));
38 expect(api.dispatch).to.be.calledOnce;
41 it("handles REQUEST_ITEMS action", () => {
48 sortDirection: SortDirection.NONE,
49 filters: createTree(),
52 requestItems: cy.stub(),
55 const service = new ServiceMock(config);
60 const next = cy.stub();
61 const middleware = dataExplorerMiddleware(service)(api)(next);
62 middleware(dataExplorerActions.REQUEST_ITEMS({ id: "ServiceId" }));
63 expect(api.dispatch).to.be.calledOnce;
66 it("handles SET_PAGE action", () => {
70 requestItems: cy.stub(),
73 const service = new ServiceMock(config);
78 const next = cy.stub();
79 const middleware = dataExplorerMiddleware(service)(api)(next);
80 middleware(dataExplorerActions.SET_PAGE({ id: service.getId(), page: 0 }));
81 expect(api.dispatch).to.be.calledOnce;
84 it("handles SET_ROWS_PER_PAGE action", () => {
88 requestItems: cy.stub(),
91 const service = new ServiceMock(config);
96 const next = cy.stub();
97 const middleware = dataExplorerMiddleware(service)(api)(next);
98 middleware(dataExplorerActions.SET_ROWS_PER_PAGE({ id: service.getId(), rowsPerPage: 0 }));
99 expect(api.dispatch).to.be.calledOnce;
102 it("handles SET_FILTERS action", () => {
106 requestItems: cy.stub(),
109 const service = new ServiceMock(config);
114 const next = cy.stub();
115 const middleware = dataExplorerMiddleware(service)(api)(next);
116 middleware(dataExplorerActions.SET_FILTERS({ id: service.getId(), columnName: "", filters: createTree() }));
117 expect(api.dispatch).to.be.calledThrice;
120 it("handles SET_ROWS_PER_PAGE action", () => {
124 requestItems: cy.stub(),
127 const service = new ServiceMock(config);
132 const next = cy.stub();
133 const middleware = dataExplorerMiddleware(service)(api)(next);
134 middleware(dataExplorerActions.SET_ROWS_PER_PAGE({ id: service.getId(), rowsPerPage: 0 }));
135 expect(api.dispatch).to.be.calledOnce;
138 it("handles TOGGLE_SORT action", () => {
142 requestItems: cy.stub(),
145 const service = new ServiceMock(config);
150 const next = cy.stub();
151 const middleware = dataExplorerMiddleware(service)(api)(next);
152 middleware(dataExplorerActions.TOGGLE_SORT({ id: service.getId(), columnName: "" }));
153 expect(api.dispatch).to.be.calledOnce;
156 it("handles SET_SEARCH_VALUE action", () => {
160 requestItems: cy.stub(),
163 const service = new ServiceMock(config);
168 const next = cy.stub();
169 const middleware = dataExplorerMiddleware(service)(api)(next);
170 middleware(dataExplorerActions.SET_EXPLORER_SEARCH_VALUE({ id: service.getId(), searchValue: "" }));
171 expect(api.dispatch).to.be.calledThrice;
174 it("forwards other actions", () => {
178 requestItems: cy.stub(),
181 const service = new ServiceMock(config);
186 const next = cy.stub();
187 const middleware = dataExplorerMiddleware(service)(api)(next);
188 middleware(dataExplorerActions.SET_COLUMNS({ id: service.getId(), columns: [] }));
189 middleware(dataExplorerActions.SET_ITEMS({ id: service.getId(), items: [], rowsPerPage: 0, itemsAvailable: 0, page: 0 }));
190 middleware(dataExplorerActions.TOGGLE_COLUMN({ id: service.getId(), columnName: "" }));
191 expect(api.dispatch).to.not.be.called;
192 expect(next).to.be.calledThrice;
197 class ServiceMock extends DataExplorerMiddlewareService {
198 constructor(config) {
203 return this.config.columns;
207 this.config.requestItems(api);
208 return Promise.resolve();
211 async requestCount() {}