21508: Fix io panel json content width
[arvados.git] / services / workbench2 / src / views / process-panel / process-io-card.test.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
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';
17
18
19 jest.mock('views/process-panel/process-output-collection-files');
20 configure({ adapter: new Adapter() });
21
22 describe('renderers', () => {
23     let store;
24
25     describe('ProcessStatus', () => {
26
27         beforeEach(() => {
28             store = createStore(combineReducers({
29                 auth: (state: any = {}, action: any) => state,
30             }));
31         });
32
33         it('shows main process input loading when raw or params null', () => {
34             // when
35             let panel = mount(
36                 <Provider store={store}>
37                     <MuiThemeProvider theme={CustomTheme}>
38                         <ProcessIOCard
39                             label={ProcessIOCardType.INPUT}
40                             process={false} // Treat as a main process, no requestingContainerUuid
41                             params={null}
42                             raw={{}}
43                         />
44                     </MuiThemeProvider>
45                 </Provider>
46                 );
47
48             // then
49             expect(panel.find(Tab).exists()).toBeFalsy();
50             expect(panel.find(CircularProgress));
51
52             // when
53             panel = mount(
54                 <Provider store={store}>
55                     <MuiThemeProvider theme={CustomTheme}>
56                         <ProcessIOCard
57                             label={ProcessIOCardType.INPUT}
58                             process={false} // Treat as a main process, no requestingContainerUuid
59                             params={[]}
60                             raw={null}
61                         />
62                     </MuiThemeProvider>
63                 </Provider>
64                 );
65
66             // then
67             expect(panel.find(Tab).exists()).toBeFalsy();
68             expect(panel.find(CircularProgress));
69         });
70
71         it('shows main process empty params and raw', () => {
72             // when
73             let panel = mount(
74                 <Provider store={store}>
75                     <MuiThemeProvider theme={CustomTheme}>
76                         <ProcessIOCard
77                             label={ProcessIOCardType.INPUT}
78                             process={false} // Treat as a main process, no requestingContainerUuid
79                             params={[]}
80                             raw={{}}
81                         />
82                     </MuiThemeProvider>
83                 </Provider>
84                 );
85
86             // then
87             expect(panel.find(CircularProgress).exists()).toBeFalsy();
88             expect(panel.find(Tab).exists()).toBeFalsy();
89             expect(panel.find(DefaultView).text()).toEqual('No parameters found');
90         });
91
92         it('shows main process with raw', () => {
93             // when
94             const raw = {some: 'data'};
95             let panel = mount(
96                 <Provider store={store}>
97                     <MuiThemeProvider theme={CustomTheme}>
98                         <ProcessIOCard
99                             label={ProcessIOCardType.INPUT}
100                             process={false} // Treat as a main process, no requestingContainerUuid
101                             params={[]}
102                             raw={raw}
103                         />
104                     </MuiThemeProvider>
105                 </Provider>
106                 );
107
108             // then
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));
112         });
113
114         it('shows main process with params', () => {
115             // when
116             const parameters = [{id: 'someId', label: 'someLabel', value: [{display: 'someValue'}]}];
117             let panel = mount(
118                 <Provider store={store}>
119                     <MuiThemeProvider theme={CustomTheme}>
120                         <ProcessIOCard
121                             label={ProcessIOCardType.INPUT}
122                             process={false} // Treat as a main process, no requestingContainerUuid
123                             params={parameters}
124                             raw={{}}
125                         />
126                     </MuiThemeProvider>
127                 </Provider>
128                 );
129
130             // then
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');
136         });
137
138         // Subprocess
139
140         it('shows subprocess loading', () => {
141             // when
142             const subprocess = {containerRequest: {requestingContainerUuid: 'xyz'}};
143             let panel = mount(
144                 <Provider store={store}>
145                     <MuiThemeProvider theme={CustomTheme}>
146                         <ProcessIOCard
147                             label={ProcessIOCardType.INPUT}
148                             process={subprocess} // Treat as a subprocess without outputUuid
149                             params={null}
150                             raw={null}
151                         />
152                     </MuiThemeProvider>
153                 </Provider>
154                 );
155
156             // then
157             expect(panel.find(Tab).exists()).toBeFalsy();
158             expect(panel.find(CircularProgress));
159         });
160
161         it('shows subprocess mounts', () => {
162             // when
163             const subprocess = {containerRequest: {requestingContainerUuid: 'xyz'}};
164             const sampleMount = {path: '/', pdh: 'abcdef12abcdef12abcdef12abcdef12+0'};
165             let panel = mount(
166                 <Provider store={store}>
167                     <MemoryRouter>
168                         <MuiThemeProvider theme={CustomTheme}>
169                             <ProcessIOCard
170                                 label={ProcessIOCardType.INPUT}
171                                 process={subprocess} // Treat as a subprocess without outputUuid
172                                 params={null}
173                                 raw={null}
174                                 mounts={[sampleMount]}
175                             />
176                         </MuiThemeProvider>
177                     </MemoryRouter>
178                 </Provider>
179                 );
180
181             // then
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);
185
186         });
187
188         it('shows subprocess output collection', () => {
189             // when
190             const subprocess = {containerRequest: {requestingContainerUuid: 'xyz'}};
191             const outputCollection = '123456789';
192             let panel = mount(
193                 <Provider store={store}>
194                     <MuiThemeProvider theme={CustomTheme}>
195                         <ProcessIOCard
196                             label={ProcessIOCardType.OUTPUT}
197                             process={subprocess} // Treat as a subprocess with outputUuid
198                             outputUuid={outputCollection}
199                             params={null}
200                             raw={null}
201                         />
202                     </MuiThemeProvider>
203                 </Provider>
204                 );
205
206             // then
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);
210         });
211
212         it('shows empty subprocess raw', () => {
213             // when
214             const subprocess = {containerRequest: {requestingContainerUuid: 'xyz'}};
215             const outputCollection = '123456789';
216             let panel = mount(
217                 <Provider store={store}>
218                     <MuiThemeProvider theme={CustomTheme}>
219                         <ProcessIOCard
220                             label={ProcessIOCardType.OUTPUT}
221                             process={subprocess} // Treat as a subprocess with outputUuid
222                             outputUuid={outputCollection}
223                             params={null}
224                             raw={{}}
225                         />
226                     </MuiThemeProvider>
227                 </Provider>
228                 );
229
230             // then
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);
235         });
236
237     });
238 });