1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from "react";
6 import { configure, mount } from "enzyme";
7 import { ServiceRepository, createServices } from "services/services";
8 import { configureStore } from "store/store";
9 import { createBrowserHistory } from "history";
10 import { mockConfig } from 'common/config';
11 import { ApiActions } from "services/api/api-actions";
12 import Axios from "axios";
13 import MockAdapter from "axios-mock-adapter";
14 import { Process } from "store/processes/process";
15 import { ContainerState } from "models/container";
16 import Adapter from "enzyme-adapter-react-16";
17 import { SubprocessProgressBar } from "./subprocess-progress-bar";
18 import { Provider } from "react-redux";
19 import { FilterBuilder } from 'services/api/filter-builder';
20 import { ProcessStatusFilter, buildProcessStatusFilters } from 'store/resource-type-filters/resource-type-filters';
21 import {act} from "react-dom/test-utils";
23 configure({ adapter: new Adapter() });
25 describe("<SubprocessProgressBar />", () => {
26 const axiosInst = Axios.create({ headers: {} });
27 const axiosMock = new MockAdapter(axiosInst);
30 let services: ServiceRepository;
31 const config: any = {};
32 const actions: ApiActions = {
33 progressFn: (id: string, working: boolean) => { },
34 errorFn: (id: string, message: string) => { }
36 let statusResponse = {
37 [ProcessStatusFilter.COMPLETED]: 0,
38 [ProcessStatusFilter.RUNNING]: 0,
39 [ProcessStatusFilter.FAILED]: 0,
40 [ProcessStatusFilter.QUEUED]: 0,
43 const createMockListFunc = (uuid: string) => jest.fn(async (args) => {
44 const baseFilter = new FilterBuilder().addEqual('requesting_container_uuid', uuid).getFilters();
46 const filterResponses = Object.keys(statusResponse)
47 .map(status => ({filters: buildProcessStatusFilters(new FilterBuilder(baseFilter), status).getFilters(), value: statusResponse[status]}));
49 const matchedFilter = filterResponses.find(response => response.filters === args.filters);
51 return { itemsAvailable: matchedFilter.value };
53 return { itemsAvailable: 0 };
58 services = createServices(mockConfig({}), actions, axiosInst);
59 store = configureStore(createBrowserHistory(), services, config);
62 it("requests subprocess progress stats for stopped processes and displays progress", async () => {
66 state: ContainerState.COMPLETE,
69 containerUuid: 'zzzzz-dz642-000000000000000',
74 [ProcessStatusFilter.COMPLETED]: 100,
75 [ProcessStatusFilter.RUNNING]: 200,
77 // Combined into failed segment
78 [ProcessStatusFilter.FAILED]: 200,
79 [ProcessStatusFilter.CANCELLED]: 100,
81 // Combined into queued segment
82 [ProcessStatusFilter.QUEUED]: 300,
83 [ProcessStatusFilter.ONHOLD]: 100,
86 services.containerRequestService.list = createMockListFunc(process.containerRequest.containerUuid);
89 await act(async () => {
91 <Provider store={store}>
92 <SubprocessProgressBar process={process} />
95 await progressBar.update();
97 // expects 6 subprocess status list requests
98 const expectedFilters = [
99 ProcessStatusFilter.COMPLETED,
100 ProcessStatusFilter.RUNNING,
101 ProcessStatusFilter.FAILED,
102 ProcessStatusFilter.CANCELLED,
103 ProcessStatusFilter.QUEUED,
104 ProcessStatusFilter.ONHOLD,
106 buildProcessStatusFilters(
107 new FilterBuilder().addEqual(
108 "requesting_container_uuid",
109 process.containerRequest.containerUuid
115 expectedFilters.forEach((filter) => {
116 expect(services.containerRequestService.list).toHaveBeenCalledWith({limit: 0, offset: 0, filters: filter});
119 // Verify progress bar with correct degment widths
120 ['10%', '20%', '30%', '40%'].forEach((value, i) => {
121 const styles = progressBar.find('.progress').at(i).props().style;
122 expect(styles).toHaveProperty('width', value);
126 it("dislays correct progress bar widths with different values", async () => {
129 state: ContainerState.COMPLETE,
132 containerUuid: 'zzzzz-dz642-000000000000001',
137 [ProcessStatusFilter.COMPLETED]: 50,
138 [ProcessStatusFilter.RUNNING]: 55,
140 [ProcessStatusFilter.FAILED]: 30,
141 [ProcessStatusFilter.CANCELLED]: 30,
143 [ProcessStatusFilter.QUEUED]: 235,
144 [ProcessStatusFilter.ONHOLD]: 100,
147 services.containerRequestService.list = createMockListFunc(process.containerRequest.containerUuid);
150 await act(async () => {
152 <Provider store={store}>
153 <SubprocessProgressBar process={process} />
156 await progressBar.update();
158 // Verify progress bar with correct degment widths
159 ['10%', '11%', '12%', '67%'].forEach((value, i) => {
160 const styles = progressBar.find('.progress').at(i).props().style;
161 expect(styles).toHaveProperty('width', value);