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';
17 import { CopyIcon } from 'components/icon/icon';
18 import copy from 'copy-to-clipboard';
20 // Mock collection files component since it just needs to exist
21 jest.mock('views/process-panel/process-output-collection-files');
22 // Mock autosizer for the io panel virtual list
23 jest.mock('react-virtualized-auto-sizer', () => ({ children }: any) => children({ height: 600, width: 600 }));
24 // Mock copy to clipboard
25 jest.mock('copy-to-clipboard');
27 configure({ adapter: new Adapter() });
29 describe('renderers', () => {
32 describe('ProcessStatus', () => {
35 store = createStore(combineReducers({
36 auth: (state: any = {}, action: any) => state,
40 it('shows main process input loading when raw or params null', () => {
43 <Provider store={store}>
44 <MuiThemeProvider theme={CustomTheme}>
46 label={ProcessIOCardType.INPUT}
47 process={false} // Treat as a main process, no requestingContainerUuid
56 expect(panel.find(Tab).exists()).toBeFalsy();
57 expect(panel.find(CircularProgress));
61 <Provider store={store}>
62 <MuiThemeProvider theme={CustomTheme}>
64 label={ProcessIOCardType.INPUT}
65 process={false} // Treat as a main process, no requestingContainerUuid
74 expect(panel.find(Tab).exists()).toBeFalsy();
75 expect(panel.find(CircularProgress));
78 it('shows main process empty params and raw', () => {
81 <Provider store={store}>
82 <MuiThemeProvider theme={CustomTheme}>
84 label={ProcessIOCardType.INPUT}
85 process={false} // Treat as a main process, no requestingContainerUuid
94 expect(panel.find(CircularProgress).exists()).toBeFalsy();
95 expect(panel.find(Tab).exists()).toBeFalsy();
96 expect(panel.find(DefaultView).text()).toEqual('No parameters found');
99 it('shows main process with raw and allows copying json', () => {
101 const raw = {some: 'data'};
103 <Provider store={store}>
104 <MuiThemeProvider theme={CustomTheme}>
106 label={ProcessIOCardType.INPUT}
107 process={false} // Treat as a main process, no requestingContainerUuid
116 expect(panel.find(CircularProgress).exists()).toBeFalsy();
117 expect(panel.find(Tab).length).toBe(1);
118 expect(panel.find(DefaultVirtualCodeSnippet).text()).toContain(JSON.stringify(raw, null, 2).replace(/\n/g, ''));
121 panel.find(CopyIcon).simulate('click');
122 expect(copy).toHaveBeenCalledWith(JSON.stringify(raw, null, 2), undefined);
125 it('shows main process with params', () => {
127 const parameters = [{id: 'someId', label: 'someLabel', value: {display: 'someValue'}}];
129 <Provider store={store}>
130 <MuiThemeProvider theme={CustomTheme}>
132 label={ProcessIOCardType.INPUT}
133 process={false} // Treat as a main process, no requestingContainerUuid
142 expect(panel.find(CircularProgress).exists()).toBeFalsy();
143 expect(panel.find(Tab).length).toBe(2); // Empty raw is shown if parameters are present
144 expect(panel.find(TableBody).text()).toContain('someId');
145 expect(panel.find(TableBody).text()).toContain('someLabel');
146 expect(panel.find(TableBody).text()).toContain('someValue');
149 it('shows main process with output collection', () => {
151 const outputCollection = '987654321';
152 const parameters = [{id: 'someId', label: 'someLabel', value: {display: 'someValue'}}];
154 <Provider store={store}>
155 <MuiThemeProvider theme={CustomTheme}>
157 label={ProcessIOCardType.OUTPUT}
158 process={false} // Treat as a main process, no requestingContainerUuid
159 outputUuid={outputCollection}
168 expect(panel.find(CircularProgress).exists()).toBeFalsy();
169 expect(panel.find(Tab).length).toBe(3); // Empty raw is shown if parameters are present
170 expect(panel.find(TableBody).text()).toContain('someId');
171 expect(panel.find(TableBody).text()).toContain('someLabel');
172 expect(panel.find(TableBody).text()).toContain('someValue');
175 panel.find(Tab).at(2).simulate('click');
176 expect(panel.find(ProcessOutputCollectionFiles).prop('currentItemUuid')).toBe(outputCollection);
181 it('shows subprocess loading', () => {
183 const subprocess = {containerRequest: {requestingContainerUuid: 'xyz'}};
185 <Provider store={store}>
186 <MuiThemeProvider theme={CustomTheme}>
188 label={ProcessIOCardType.INPUT}
189 process={subprocess} // Treat as a subprocess without outputUuid
198 expect(panel.find(Tab).exists()).toBeFalsy();
199 expect(panel.find(CircularProgress));
202 it('shows subprocess mounts', () => {
204 const subprocess = {containerRequest: {requestingContainerUuid: 'xyz'}};
205 const sampleMount = {path: '/', pdh: 'abcdef12abcdef12abcdef12abcdef12+0'};
207 <Provider store={store}>
209 <MuiThemeProvider theme={CustomTheme}>
211 label={ProcessIOCardType.INPUT}
212 process={subprocess} // Treat as a subprocess without outputUuid
215 mounts={[sampleMount]}
223 expect(panel.find(CircularProgress).exists()).toBeFalsy();
224 expect(panel.find(Tab).length).toBe(1); // Empty raw is hidden in subprocesses
225 expect(panel.find(TableBody).text()).toContain(sampleMount.pdh);
229 it('shows subprocess output collection', () => {
231 const subprocess = {containerRequest: {requestingContainerUuid: 'xyz'}};
232 const outputCollection = '123456789';
234 <Provider store={store}>
235 <MuiThemeProvider theme={CustomTheme}>
237 label={ProcessIOCardType.OUTPUT}
238 process={subprocess} // Treat as a subprocess with outputUuid
239 outputUuid={outputCollection}
248 expect(panel.find(CircularProgress).exists()).toBeFalsy();
249 expect(panel.find(Tab).length).toBe(1); // Unloaded raw is hidden in subprocesses
250 expect(panel.find(ProcessOutputCollectionFiles).prop('currentItemUuid')).toBe(outputCollection);
253 it('shows empty subprocess raw', () => {
255 const subprocess = {containerRequest: {requestingContainerUuid: 'xyz'}};
256 const outputCollection = '123456789';
258 <Provider store={store}>
259 <MuiThemeProvider theme={CustomTheme}>
261 label={ProcessIOCardType.OUTPUT}
262 process={subprocess} // Treat as a subprocess with outputUuid
263 outputUuid={outputCollection}
272 expect(panel.find(CircularProgress).exists()).toBeFalsy();
273 expect(panel.find(Tab).length).toBe(2); // Empty raw is visible in subprocesses
274 expect(panel.find(Tab).first().text()).toBe('Collection');
275 expect(panel.find(ProcessOutputCollectionFiles).prop('currentItemUuid')).toBe(outputCollection);