21700: Install Bundler system-wide in Rails postinst
[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 { 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
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 }));
22
23 configure({ adapter: new Adapter() });
24
25 describe('renderers', () => {
26     let store;
27
28     describe('ProcessStatus', () => {
29
30         beforeEach(() => {
31             store = createStore(combineReducers({
32                 auth: (state: any = {}, action: any) => state,
33             }));
34         });
35
36         it('shows main process input loading when raw or params null', () => {
37             // when
38             let panel = mount(
39                 <Provider store={store}>
40                     <MuiThemeProvider theme={CustomTheme}>
41                         <ProcessIOCard
42                             label={ProcessIOCardType.INPUT}
43                             process={false} // Treat as a main process, no requestingContainerUuid
44                             params={null}
45                             raw={{}}
46                         />
47                     </MuiThemeProvider>
48                 </Provider>
49                 );
50
51             // then
52             expect(panel.find(Tab).exists()).toBeFalsy();
53             expect(panel.find(CircularProgress));
54
55             // when
56             panel = mount(
57                 <Provider store={store}>
58                     <MuiThemeProvider theme={CustomTheme}>
59                         <ProcessIOCard
60                             label={ProcessIOCardType.INPUT}
61                             process={false} // Treat as a main process, no requestingContainerUuid
62                             params={[]}
63                             raw={null}
64                         />
65                     </MuiThemeProvider>
66                 </Provider>
67                 );
68
69             // then
70             expect(panel.find(Tab).exists()).toBeFalsy();
71             expect(panel.find(CircularProgress));
72         });
73
74         it('shows main process empty params and raw', () => {
75             // when
76             let panel = mount(
77                 <Provider store={store}>
78                     <MuiThemeProvider theme={CustomTheme}>
79                         <ProcessIOCard
80                             label={ProcessIOCardType.INPUT}
81                             process={false} // Treat as a main process, no requestingContainerUuid
82                             params={[]}
83                             raw={{}}
84                         />
85                     </MuiThemeProvider>
86                 </Provider>
87                 );
88
89             // then
90             expect(panel.find(CircularProgress).exists()).toBeFalsy();
91             expect(panel.find(Tab).exists()).toBeFalsy();
92             expect(panel.find(DefaultView).text()).toEqual('No parameters found');
93         });
94
95         it('shows main process with raw', () => {
96             // when
97             const raw = {some: 'data'};
98             let panel = mount(
99                 <Provider store={store}>
100                     <MuiThemeProvider theme={CustomTheme}>
101                         <ProcessIOCard
102                             label={ProcessIOCardType.INPUT}
103                             process={false} // Treat as a main process, no requestingContainerUuid
104                             params={[]}
105                             raw={raw}
106                         />
107                     </MuiThemeProvider>
108                 </Provider>
109                 );
110
111             // then
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, ''));
115         });
116
117         it('shows main process with params', () => {
118             // when
119             const parameters = [{id: 'someId', label: 'someLabel', value: {display: 'someValue'}}];
120             let panel = mount(
121                 <Provider store={store}>
122                     <MuiThemeProvider theme={CustomTheme}>
123                         <ProcessIOCard
124                             label={ProcessIOCardType.INPUT}
125                             process={false} // Treat as a main process, no requestingContainerUuid
126                             params={parameters}
127                             raw={{}}
128                         />
129                     </MuiThemeProvider>
130                 </Provider>
131                 );
132
133             // then
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');
139         });
140
141         // Subprocess
142
143         it('shows subprocess loading', () => {
144             // when
145             const subprocess = {containerRequest: {requestingContainerUuid: 'xyz'}};
146             let panel = mount(
147                 <Provider store={store}>
148                     <MuiThemeProvider theme={CustomTheme}>
149                         <ProcessIOCard
150                             label={ProcessIOCardType.INPUT}
151                             process={subprocess} // Treat as a subprocess without outputUuid
152                             params={null}
153                             raw={null}
154                         />
155                     </MuiThemeProvider>
156                 </Provider>
157                 );
158
159             // then
160             expect(panel.find(Tab).exists()).toBeFalsy();
161             expect(panel.find(CircularProgress));
162         });
163
164         it('shows subprocess mounts', () => {
165             // when
166             const subprocess = {containerRequest: {requestingContainerUuid: 'xyz'}};
167             const sampleMount = {path: '/', pdh: 'abcdef12abcdef12abcdef12abcdef12+0'};
168             let panel = mount(
169                 <Provider store={store}>
170                     <MemoryRouter>
171                         <MuiThemeProvider theme={CustomTheme}>
172                             <ProcessIOCard
173                                 label={ProcessIOCardType.INPUT}
174                                 process={subprocess} // Treat as a subprocess without outputUuid
175                                 params={null}
176                                 raw={null}
177                                 mounts={[sampleMount]}
178                             />
179                         </MuiThemeProvider>
180                     </MemoryRouter>
181                 </Provider>
182                 );
183
184             // then
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);
188
189         });
190
191         it('shows subprocess output collection', () => {
192             // when
193             const subprocess = {containerRequest: {requestingContainerUuid: 'xyz'}};
194             const outputCollection = '123456789';
195             let panel = mount(
196                 <Provider store={store}>
197                     <MuiThemeProvider theme={CustomTheme}>
198                         <ProcessIOCard
199                             label={ProcessIOCardType.OUTPUT}
200                             process={subprocess} // Treat as a subprocess with outputUuid
201                             outputUuid={outputCollection}
202                             params={null}
203                             raw={null}
204                         />
205                     </MuiThemeProvider>
206                 </Provider>
207                 );
208
209             // then
210             expect(panel.find(CircularProgress).exists()).toBeFalsy();
211             expect(panel.find(Tab).length).toBe(1); // Unloaded raw is hidden in subprocesses
212             expect(panel.find(ProcessOutputCollectionFiles).prop('currentItemUuid')).toBe(outputCollection);
213         });
214
215         it('shows empty subprocess raw', () => {
216             // when
217             const subprocess = {containerRequest: {requestingContainerUuid: 'xyz'}};
218             const outputCollection = '123456789';
219             let panel = mount(
220                 <Provider store={store}>
221                     <MuiThemeProvider theme={CustomTheme}>
222                         <ProcessIOCard
223                             label={ProcessIOCardType.OUTPUT}
224                             process={subprocess} // Treat as a subprocess with outputUuid
225                             outputUuid={outputCollection}
226                             params={null}
227                             raw={{}}
228                         />
229                     </MuiThemeProvider>
230                 </Provider>
231                 );
232
233             // then
234             expect(panel.find(CircularProgress).exists()).toBeFalsy();
235             expect(panel.find(Tab).length).toBe(2); // Empty raw is visible in subprocesses
236             expect(panel.find(Tab).first().text()).toBe('Collection');
237             expect(panel.find(ProcessOutputCollectionFiles).prop('currentItemUuid')).toBe(outputCollection);
238         });
239
240     });
241 });