21720: fixed run-process-panel-actions test
[arvados.git] / services / workbench2 / src / store / run-process-panel / run-process-panel-actions.cy.js
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { runProcess } from "./run-process-panel-actions";
6 import { RUN_PROCESS_BASIC_FORM } from "views/run-process-panel/run-process-basic-form";
7 import { RUN_PROCESS_INPUTS_FORM } from "views/run-process-panel/run-process-inputs-form";
8 import { navigateTo } from "store/navigation/navigation-action";
9   
10 describe("run-process-panel-actions", () => {
11     describe("runProcess", () => {
12         const newProcessUUID = 'newProcessUUID';
13         let dispatch, getState, services;
14
15         beforeEach(() => {
16             dispatch = cy.spy();
17             services = {
18                 containerRequestService: {
19                     create: cy.stub().callsFake(async () => ({
20                         uuid: newProcessUUID,
21                     })),
22                 },
23             };
24             cy.spy(navigateTo).as('navigateTo');
25         });
26
27         it("should return when userUuid is null", async () => {
28             // given
29             getState = () => ({
30                 auth: {},
31             });
32
33             // when
34             await runProcess(dispatch, getState, services);
35
36             // then
37             expect(dispatch).not.to.be.called;
38         });
39
40         it("should run workflow with project-uuid", async () => {
41             // given
42             getState = () => ({
43                 auth: {
44                     user: {
45                         email: "test@gmail.com",
46                         firstName: "TestFirstName",
47                         lastName: "TestLastName",
48                         uuid: "zzzzz-tpzed-yid70bw31f51234",
49                         ownerUuid: "zzzzz-tpzed-000000000000000",
50                         isAdmin: false,
51                         isActive: true,
52                         username: "testfirstname",
53                         prefs: {
54                             profile: {},
55                         },
56                     },
57                 },
58                 runProcessPanel: {
59                     processPathname: "/projects/zzzzz-tpzed-yid70bw31f51234",
60                     processOwnerUuid: "zzzzz-tpzed-yid70bw31f51234",
61                     selectedWorkflow: {
62                         href: "/workflows/zzzzz-7fd4e-2tlnerdkxnl4fjt",
63                         kind: "arvados#workflow",
64                         etag: "8gh5xlhlgo61yqscyl1spw8tc",
65                         uuid: "zzzzz-7fd4e-2tlnerdkxnl4fjt",
66                         ownerUuid: "zzzzz-tpzed-o4njwilpp4ov321",
67                         createdAt: "2020-07-15T19:40:50.296041000Z",
68                         modifiedByClientUuid: "zzzzz-ozdt8-libnr89sc5nq111",
69                         modifiedByUserUuid: "zzzzz-tpzed-o4njwilpp4ov321",
70                         modifiedAt: "2020-07-15T19:40:50.296376000Z",
71                         name: "revsort.cwl",
72                         description:
73                             "Reverse the lines in a document, then sort those lines.",
74                         definition:
75                             '{\n    "$graph": [\n        {\n            "class": "Workflow",\n            "doc": "Reverse the lines in a document, then sort those lines.",\n            "id": "#main",\n            "hints":[{"class":"http://arvados.org/cwl#WorkflowRunnerResources","acrContainerImage":"arvados/jobs:2.0.4", "ramMin": 16000}], "inputs": [\n                {\n                    "default": null,\n                    "doc": "The input file to be processed.",\n                    "id": "#main/input",\n                    "type": "File"\n                },\n                {\n                    "default": true,\n                    "doc": "If true, reverse (decending) sort",\n                    "id": "#main/reverse_sort",\n                    "type": "boolean"\n                }\n            ],\n            "outputs": [\n                {\n                    "doc": "The output with the lines reversed and sorted.",\n                    "id": "#main/output",\n                    "outputSource": "#main/sorted/output",\n                    "type": "File"\n                }\n            ],\n            "steps": [\n                {\n                    "id": "#main/rev",\n                    "in": [\n                        {\n                            "id": "#main/rev/input",\n                            "source": "#main/input"\n                        }\n                    ],\n                    "out": [\n                        "#main/rev/output"\n                    ],\n                    "run": "#revtool.cwl"\n                },\n                {\n                    "id": "#main/sorted",\n                    "in": [\n                        {\n                            "id": "#main/sorted/input",\n                            "source": "#main/rev/output"\n                        },\n                        {\n                            "id": "#main/sorted/reverse",\n                            "source": "#main/reverse_sort"\n                        }\n                    ],\n                    "out": [\n                        "#main/sorted/output"\n                    ],\n                    "run": "#sorttool.cwl"\n                }\n            ]\n        },\n        {\n            "baseCommand": "rev",\n            "class": "CommandLineTool",\n            "doc": "Reverse each line using the `rev` command",\n            "hints": [\n                {\n                    "class": "ResourceRequirement",\n                    "ramMin": 8\n                }\n            ],\n            "id": "#revtool.cwl",\n            "inputs": [\n                {\n                    "id": "#revtool.cwl/input",\n                    "inputBinding": {},\n                    "type": "File"\n                }\n            ],\n            "outputs": [\n                {\n                    "id": "#revtool.cwl/output",\n                    "outputBinding": {\n                        "glob": "output.txt"\n                    },\n                    "type": "File"\n                }\n            ],\n            "stdout": "output.txt"\n        },\n        {\n            "baseCommand": "sort",\n            "class": "CommandLineTool",\n            "doc": "Sort lines using the `sort` command",\n            "hints": [\n                {\n                    "class": "ResourceRequirement",\n                    "ramMin": 8\n                }\n            ],\n            "id": "#sorttool.cwl",\n            "inputs": [\n                {\n                    "id": "#sorttool.cwl/reverse",\n                    "inputBinding": {\n                        "position": 1,\n                        "prefix": "-r"\n                    },\n                    "type": "boolean"\n                },\n                {\n                    "id": "#sorttool.cwl/input",\n                    "inputBinding": {\n                        "position": 2\n                    },\n                    "type": "File"\n                }\n            ],\n            "outputs": [\n                {\n                    "id": "#sorttool.cwl/output",\n                    "outputBinding": {\n                        "glob": "output.txt"\n                    },\n                    "type": "File"\n                }\n            ],\n            "stdout": "output.txt"\n        }\n    ],\n    "cwlVersion": "v1.0"\n}',
76                     },
77                 },
78                 form: {
79                     [RUN_PROCESS_BASIC_FORM]: {
80                         values: {
81                             name: "basicFormTestName",
82                             description: "basicFormTestDescription",
83                         },
84                     },
85                     [RUN_PROCESS_INPUTS_FORM]: {
86                         values: {
87                             inputs: {},
88                         }
89                     }
90                 },
91             });
92
93             // when
94             await runProcess(dispatch, getState, services);
95
96             // then
97             expect(services.containerRequestService.create).to.be.calledWithMatch(testCreateArgs);
98             expect(dispatch).to.be.calledWithMatch(navigateTo(newProcessUUID));
99         });
100     });
101 });
102
103 const testMounts = {
104     '/var/spool/cwl': {
105         kind: 'collection',
106         writable: true,
107     },
108     stdout: {
109         kind: 'file',
110         path: '/var/spool/cwl/cwl.output.json',
111     },
112     '/var/lib/cwl/workflow.json': {
113         kind: 'json',
114         content: {
115             $graph: [
116                 {
117                     class: 'Workflow',
118                     doc: 'Reverse the lines in a document, then sort those lines.',
119                     id: '#main',
120                     hints: [
121                         {
122                             class: 'http://arvados.org/cwl#WorkflowRunnerResources',
123                             acrContainerImage: 'arvados/jobs:2.0.4',
124                             ramMin: 16000,
125                         },
126                     ],
127                     inputs: [
128                         {
129                             default: null,
130                             doc: 'The input file to be processed.',
131                             id: '#main/input',
132                             type: 'File',
133                         },
134                         {
135                             default: true,
136                             doc: 'If true, reverse (decending) sort',
137                             id: '#main/reverse_sort',
138                             type: 'boolean',
139                         },
140                     ],
141                     outputs: [
142                         {
143                             doc: 'The output with the lines reversed and sorted.',
144                             id: '#main/output',
145                             outputSource: '#main/sorted/output',
146                             type: 'File',
147                         },
148                     ],
149                     steps: [
150                         {
151                             id: '#main/rev',
152                             in: [
153                                 {
154                                     id: '#main/rev/input',
155                                     source: '#main/input',
156                                 },
157                             ],
158                             out: ['#main/rev/output'],
159                             run: '#revtool.cwl',
160                         },
161                         {
162                             id: '#main/sorted',
163                             in: [
164                                 {
165                                     id: '#main/sorted/input',
166                                     source: '#main/rev/output',
167                                 },
168                                 {
169                                     id: '#main/sorted/reverse',
170                                     source: '#main/reverse_sort',
171                                 },
172                             ],
173                             out: ['#main/sorted/output'],
174                             run: '#sorttool.cwl',
175                         },
176                     ],
177                 },
178                 {
179                     baseCommand: 'rev',
180                     class: 'CommandLineTool',
181                     doc: 'Reverse each line using the `rev` command',
182                     hints: [
183                         {
184                             class: 'ResourceRequirement',
185                             ramMin: 8,
186                         },
187                     ],
188                     id: '#revtool.cwl',
189                     inputs: [
190                         {
191                             id: '#revtool.cwl/input',
192                             inputBinding: {},
193                             type: 'File',
194                         },
195                     ],
196                     outputs: [
197                         {
198                             id: '#revtool.cwl/output',
199                             outputBinding: {
200                                 glob: 'output.txt',
201                             },
202                             type: 'File',
203                         },
204                     ],
205                     stdout: 'output.txt',
206                 },
207                 {
208                     baseCommand: 'sort',
209                     class: 'CommandLineTool',
210                     doc: 'Sort lines using the `sort` command',
211                     hints: [
212                         {
213                             class: 'ResourceRequirement',
214                             ramMin: 8,
215                         },
216                     ],
217                     id: '#sorttool.cwl',
218                     inputs: [
219                         {
220                             id: '#sorttool.cwl/reverse',
221                             inputBinding: {
222                                 position: 1,
223                                 prefix: '-r',
224                             },
225                             type: 'boolean',
226                         },
227                         {
228                             id: '#sorttool.cwl/input',
229                             inputBinding: {
230                                 position: 2,
231                             },
232                             type: 'File',
233                         },
234                     ],
235                     outputs: [
236                         {
237                             id: '#sorttool.cwl/output',
238                             outputBinding: {
239                                 glob: 'output.txt',
240                             },
241                             type: 'File',
242                         },
243                     ],
244                     stdout: 'output.txt',
245                 },
246             ],
247             cwlVersion: 'v1.0',
248         },
249     },
250     '/var/lib/cwl/cwl.input.json': {
251         kind: 'json',
252         content: {
253             '': {},
254         },
255     },
256 };
257
258 const testCreateArgs = {
259     command: [
260         'arvados-cwl-runner',
261         '--local',
262         '--api=containers',
263         "--no-log-timestamps",
264         "--disable-color",
265         '--project-uuid=zzzzz-tpzed-yid70bw31f51234',
266         '/var/lib/cwl/workflow.json#main',
267         '/var/lib/cwl/cwl.input.json',
268     ],
269     containerImage: 'arvados/jobs:2.0.4',
270     cwd: '/var/spool/cwl',
271     description: undefined,
272     mounts: testMounts,
273     secretMounts: undefined,
274     name: 'basicFormTestName',
275     outputName: 'Output from basicFormTestName',
276     outputPath: '/var/spool/cwl',
277     ownerUuid: 'zzzzz-tpzed-yid70bw31f51234',
278     priority: 500,
279     properties: {
280         workflowName: 'revsort.cwl',
281         template_uuid: 'zzzzz-7fd4e-2tlnerdkxnl4fjt',
282     },
283     runtimeConstraints: {
284         API: true,
285         ram: 16256 * (1024 * 1024),
286         vcpus: 1,
287     },
288     schedulingParameters: { max_run_time: undefined },
289     state: 'Committed',
290     useExisting: false,
291 };