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 } 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 { ProcessIOCard, ProcessIOCardType } from './process-io-card';
13 import { DefaultView } from "components/default-view/default-view";
14 import { DefaultVirtualCodeSnippet } from "components/default-code-snippet/default-virtual-code-snippet";
15 import { ProcessOutputCollectionFiles } from './process-output-collection-files';
16 import { MemoryRouter } from 'react-router-dom';
18 // Mock collection files component since it just needs to exist
19 jest.mock('views/process-panel/process-output-collection-files');
20 // Mock autosizer for the io panel virtual list
21 jest.mock('react-virtualized-auto-sizer', () => ({ children }: any) => children({ height: 600, width: 600 }));
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(DefaultVirtualCodeSnippet).text()).toContain(JSON.stringify(raw, null, 2).replace(/\n/g, ''));
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');
141 it('shows main process with output collection', () => {
143 const outputCollection = '987654321';
144 const parameters = [{id: 'someId', label: 'someLabel', value: {display: 'someValue'}}];
146 <Provider store={store}>
147 <MuiThemeProvider theme={CustomTheme}>
149 label={ProcessIOCardType.OUTPUT}
150 process={false} // Treat as a main process, no requestingContainerUuid
151 outputUuid={outputCollection}
160 expect(panel.find(CircularProgress).exists()).toBeFalsy();
161 expect(panel.find(Tab).length).toBe(3); // Empty raw is shown if parameters are present
162 expect(panel.find(TableBody).text()).toContain('someId');
163 expect(panel.find(TableBody).text()).toContain('someLabel');
164 expect(panel.find(TableBody).text()).toContain('someValue');
167 panel.find(Tab).at(2).simulate('click');
168 expect(panel.find(ProcessOutputCollectionFiles).prop('currentItemUuid')).toBe(outputCollection);
173 it('shows subprocess loading', () => {
175 const subprocess = {containerRequest: {requestingContainerUuid: 'xyz'}};
177 <Provider store={store}>
178 <MuiThemeProvider theme={CustomTheme}>
180 label={ProcessIOCardType.INPUT}
181 process={subprocess} // Treat as a subprocess without outputUuid
190 expect(panel.find(Tab).exists()).toBeFalsy();
191 expect(panel.find(CircularProgress));
194 it('shows subprocess mounts', () => {
196 const subprocess = {containerRequest: {requestingContainerUuid: 'xyz'}};
197 const sampleMount = {path: '/', pdh: 'abcdef12abcdef12abcdef12abcdef12+0'};
199 <Provider store={store}>
201 <MuiThemeProvider theme={CustomTheme}>
203 label={ProcessIOCardType.INPUT}
204 process={subprocess} // Treat as a subprocess without outputUuid
207 mounts={[sampleMount]}
215 expect(panel.find(CircularProgress).exists()).toBeFalsy();
216 expect(panel.find(Tab).length).toBe(1); // Empty raw is hidden in subprocesses
217 expect(panel.find(TableBody).text()).toContain(sampleMount.pdh);
221 it('shows subprocess output collection', () => {
223 const subprocess = {containerRequest: {requestingContainerUuid: 'xyz'}};
224 const outputCollection = '123456789';
226 <Provider store={store}>
227 <MuiThemeProvider theme={CustomTheme}>
229 label={ProcessIOCardType.OUTPUT}
230 process={subprocess} // Treat as a subprocess with outputUuid
231 outputUuid={outputCollection}
240 expect(panel.find(CircularProgress).exists()).toBeFalsy();
241 expect(panel.find(Tab).length).toBe(1); // Unloaded raw is hidden in subprocesses
242 expect(panel.find(ProcessOutputCollectionFiles).prop('currentItemUuid')).toBe(outputCollection);
245 it('shows empty subprocess raw', () => {
247 const subprocess = {containerRequest: {requestingContainerUuid: 'xyz'}};
248 const outputCollection = '123456789';
250 <Provider store={store}>
251 <MuiThemeProvider theme={CustomTheme}>
253 label={ProcessIOCardType.OUTPUT}
254 process={subprocess} // Treat as a subprocess with outputUuid
255 outputUuid={outputCollection}
264 expect(panel.find(CircularProgress).exists()).toBeFalsy();
265 expect(panel.find(Tab).length).toBe(2); // Empty raw is visible in subprocesses
266 expect(panel.find(Tab).first().text()).toBe('Collection');
267 expect(panel.find(ProcessOutputCollectionFiles).prop('currentItemUuid')).toBe(outputCollection);