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 { DefaultCodeSnippet } from "components/default-code-snippet/default-code-snippet";
15 import { ProcessOutputCollectionFiles } from './process-output-collection-files';
16 import { MemoryRouter } from 'react-router-dom';
19 jest.mock('views/process-panel/process-output-collection-files');
20 configure({ adapter: new Adapter() });
22 describe('renderers', () => {
25 describe('ProcessStatus', () => {
28 store = createStore(combineReducers({
29 auth: (state: any = {}, action: any) => state,
33 it('shows main process input loading when raw or params null', () => {
36 <Provider store={store}>
37 <MuiThemeProvider theme={CustomTheme}>
39 label={ProcessIOCardType.INPUT}
40 process={false} // Treat as a main process, no requestingContainerUuid
49 expect(panel.find(Tab).exists()).toBeFalsy();
50 expect(panel.find(CircularProgress));
54 <Provider store={store}>
55 <MuiThemeProvider theme={CustomTheme}>
57 label={ProcessIOCardType.INPUT}
58 process={false} // Treat as a main process, no requestingContainerUuid
67 expect(panel.find(Tab).exists()).toBeFalsy();
68 expect(panel.find(CircularProgress));
71 it('shows main process empty params and raw', () => {
74 <Provider store={store}>
75 <MuiThemeProvider theme={CustomTheme}>
77 label={ProcessIOCardType.INPUT}
78 process={false} // Treat as a main process, no requestingContainerUuid
87 expect(panel.find(CircularProgress).exists()).toBeFalsy();
88 expect(panel.find(Tab).exists()).toBeFalsy();
89 expect(panel.find(DefaultView).text()).toEqual('No parameters found');
92 it('shows main process with raw', () => {
94 const raw = {some: 'data'};
96 <Provider store={store}>
97 <MuiThemeProvider theme={CustomTheme}>
99 label={ProcessIOCardType.INPUT}
100 process={false} // Treat as a main process, no requestingContainerUuid
109 expect(panel.find(CircularProgress).exists()).toBeFalsy();
110 expect(panel.find(Tab).length).toBe(1);
111 expect(panel.find(DefaultCodeSnippet).text()).toContain(JSON.stringify(raw, null, 2));
114 it('shows main process with params', () => {
116 const parameters = [{id: 'someId', label: 'someLabel', value: [{display: 'someValue'}]}];
118 <Provider store={store}>
119 <MuiThemeProvider theme={CustomTheme}>
121 label={ProcessIOCardType.INPUT}
122 process={false} // Treat as a main process, no requestingContainerUuid
131 expect(panel.find(CircularProgress).exists()).toBeFalsy();
132 expect(panel.find(Tab).length).toBe(2); // Empty raw is shown if parameters are present
133 expect(panel.find(TableBody).text()).toContain('someId');
134 expect(panel.find(TableBody).text()).toContain('someLabel');
135 expect(panel.find(TableBody).text()).toContain('someValue');
140 it('shows subprocess loading', () => {
142 const subprocess = {containerRequest: {requestingContainerUuid: 'xyz'}};
144 <Provider store={store}>
145 <MuiThemeProvider theme={CustomTheme}>
147 label={ProcessIOCardType.INPUT}
148 process={subprocess} // Treat as a subprocess without outputUuid
157 expect(panel.find(Tab).exists()).toBeFalsy();
158 expect(panel.find(CircularProgress));
161 it('shows subprocess mounts', () => {
163 const subprocess = {containerRequest: {requestingContainerUuid: 'xyz'}};
164 const sampleMount = {path: '/', pdh: 'abcdef12abcdef12abcdef12abcdef12+0'};
166 <Provider store={store}>
168 <MuiThemeProvider theme={CustomTheme}>
170 label={ProcessIOCardType.INPUT}
171 process={subprocess} // Treat as a subprocess without outputUuid
174 mounts={[sampleMount]}
182 expect(panel.find(CircularProgress).exists()).toBeFalsy();
183 expect(panel.find(Tab).length).toBe(1); // Empty raw is hidden in subprocesses
184 expect(panel.find(TableBody).text()).toContain(sampleMount.pdh);
188 it('shows subprocess output collection', () => {
190 const subprocess = {containerRequest: {requestingContainerUuid: 'xyz'}};
191 const outputCollection = '123456789';
193 <Provider store={store}>
194 <MuiThemeProvider theme={CustomTheme}>
196 label={ProcessIOCardType.OUTPUT}
197 process={subprocess} // Treat as a subprocess with outputUuid
198 outputUuid={outputCollection}
207 expect(panel.find(CircularProgress).exists()).toBeFalsy();
208 expect(panel.find(Tab).length).toBe(1); // Unloaded raw is hidden in subprocesses
209 expect(panel.find(ProcessOutputCollectionFiles).prop('currentItemUuid')).toBe(outputCollection);
212 it('shows empty subprocess raw', () => {
214 const subprocess = {containerRequest: {requestingContainerUuid: 'xyz'}};
215 const outputCollection = '123456789';
217 <Provider store={store}>
218 <MuiThemeProvider theme={CustomTheme}>
220 label={ProcessIOCardType.OUTPUT}
221 process={subprocess} // Treat as a subprocess with outputUuid
222 outputUuid={outputCollection}
231 expect(panel.find(CircularProgress).exists()).toBeFalsy();
232 expect(panel.find(Tab).length).toBe(2); // Empty raw is visible in subprocesses
233 expect(panel.find(Tab).first().text()).toBe('Collection');
234 expect(panel.find(ProcessOutputCollectionFiles).prop('currentItemUuid')).toBe(outputCollection);