1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import { mount, configure } from 'enzyme';
7 import { combineReducers, createStore } from "redux";
8 import { CircularProgress, MuiThemeProvider, Tab, TableBody, TableCell } from "@material-ui/core";
9 import { CustomTheme } from 'common/custom-theme';
10 import Adapter from "enzyme-adapter-react-16";
11 import { Provider } from 'react-redux';
12 import configureMockStore from 'redux-mock-store'
13 import { ProcessIOCard, ProcessIOCardType } from './process-io-card';
14 import { DefaultView } from "components/default-view/default-view";
15 import { DefaultCodeSnippet } from "components/default-code-snippet/default-code-snippet";
16 import { ProcessOutputCollectionFiles } from './process-output-collection-files';
17 import { MemoryRouter } from 'react-router-dom';
20 const middlewares = [];
21 const mockStore = configureMockStore(middlewares);
22 jest.mock('views/process-panel/process-output-collection-files');
23 configure({ adapter: new Adapter() });
25 describe('renderers', () => {
28 describe('ProcessStatus', () => {
31 store = createStore(combineReducers({
32 auth: (state: any = {}, action: any) => state,
36 it('shows main process input loading when raw or params null', () => {
39 <Provider store={store}>
40 <MuiThemeProvider theme={CustomTheme}>
42 label={ProcessIOCardType.INPUT}
43 process={false} // Treat as a main process, no requestingContainerUuid
52 expect(panel.find(Tab).exists()).toBeFalsy();
53 expect(panel.find(CircularProgress));
57 <Provider store={store}>
58 <MuiThemeProvider theme={CustomTheme}>
60 label={ProcessIOCardType.INPUT}
61 process={false} // Treat as a main process, no requestingContainerUuid
70 expect(panel.find(Tab).exists()).toBeFalsy();
71 expect(panel.find(CircularProgress));
74 it('shows main process empty params and raw', () => {
77 <Provider store={store}>
78 <MuiThemeProvider theme={CustomTheme}>
80 label={ProcessIOCardType.INPUT}
81 process={false} // Treat as a main process, no requestingContainerUuid
90 expect(panel.find(CircularProgress).exists()).toBeFalsy();
91 expect(panel.find(Tab).exists()).toBeFalsy();
92 expect(panel.find(DefaultView).text()).toEqual('No parameters found');
95 it('shows main process with raw', () => {
97 const raw = {some: 'data'};
99 <Provider store={store}>
100 <MuiThemeProvider theme={CustomTheme}>
102 label={ProcessIOCardType.INPUT}
103 process={false} // Treat as a main process, no requestingContainerUuid
112 expect(panel.find(CircularProgress).exists()).toBeFalsy();
113 expect(panel.find(Tab).length).toBe(1);
114 expect(panel.find(DefaultCodeSnippet).text()).toContain(JSON.stringify(raw, null, 2));
117 it('shows main process with params', () => {
119 const parameters = [{id: 'someId', label: 'someLabel', value: [{display: 'someValue'}]}];
121 <Provider store={store}>
122 <MuiThemeProvider theme={CustomTheme}>
124 label={ProcessIOCardType.INPUT}
125 process={false} // Treat as a main process, no requestingContainerUuid
134 expect(panel.find(CircularProgress).exists()).toBeFalsy();
135 expect(panel.find(Tab).length).toBe(2); // Empty raw is shown if parameters are present
136 expect(panel.find(TableBody).text()).toContain('someId');
137 expect(panel.find(TableBody).text()).toContain('someLabel');
138 expect(panel.find(TableBody).text()).toContain('someValue');
143 it('shows subprocess loading', () => {
145 const subprocess = {containerRequest: {requestingContainerUuid: 'xyz'}};
147 <Provider store={store}>
148 <MuiThemeProvider theme={CustomTheme}>
150 label={ProcessIOCardType.INPUT}
151 process={subprocess} // Treat as a subprocess without outputUuid
160 expect(panel.find(Tab).exists()).toBeFalsy();
161 expect(panel.find(CircularProgress));
164 it('shows subprocess mounts', () => {
166 const subprocess = {containerRequest: {requestingContainerUuid: 'xyz'}};
167 const sampleMount = {path: '/', pdh: 'abcdef12abcdef12abcdef12abcdef12+0'};
169 <Provider store={store}>
171 <MuiThemeProvider theme={CustomTheme}>
173 label={ProcessIOCardType.INPUT}
174 process={subprocess} // Treat as a subprocess without outputUuid
177 mounts={[sampleMount]}
185 expect(panel.find(CircularProgress).exists()).toBeFalsy();
186 expect(panel.find(Tab).length).toBe(1); // Empty raw is hidden in subprocesses
187 expect(panel.find(TableBody).text()).toContain(sampleMount.pdh);
191 it('shows subprocess output collection', () => {
193 const subprocess = {containerRequest: {requestingContainerUuid: 'xyz'}};
194 const outputCollection = '123456789';
196 <Provider store={store}>
197 <MuiThemeProvider theme={CustomTheme}>
199 label={ProcessIOCardType.OUTPUT}
200 process={subprocess} // Treat as a subprocess with outputUuid
201 outputUuid={outputCollection}
210 expect(panel.find(CircularProgress).exists()).toBeFalsy();
211 expect(panel.find(Tab).length).toBe(1); // Empty raw is hidden in subprocesses
212 expect(panel.find(ProcessOutputCollectionFiles).prop('currentItemUuid')).toBe(outputCollection);