Merge branch '21832-installer-rds-support'
[arvados.git] / services / workbench2 / cypress / e2e / create-workflow.cy.js
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 describe('Create workflow tests', function () {
6     let activeUser;
7     let adminUser;
8
9     before(function () {
10         cy.getUser('admin', 'Admin', 'User', true, true)
11             .as('adminUser').then(function () {
12                 adminUser = this.adminUser;
13             }
14             );
15         cy.getUser('collectionuser1', 'Collection', 'User', false, true)
16             .as('activeUser').then(function () {
17                 activeUser = this.activeUser;
18             }
19             );
20     });
21
22     it('can create project with nested data', function () {
23         cy.createGroup(adminUser.token, {
24             group_class: "project",
25             name: `Test project (${Math.floor(Math.random() * 999999)})`,
26         }).as('project1');
27
28         cy.get('@project1').then(() => {
29             cy.createGroup(adminUser.token, {
30                 group_class: "project",
31                 name: `Test project (${Math.floor(Math.random() * 999999)})`,
32                 owner_uuid: this.project1.uuid,
33             }).as('project2');
34         })
35
36         cy.get('@project2').then(() => {
37             cy.createGroup(adminUser.token, {
38                 group_class: "project",
39                 name: `Test project (${Math.floor(Math.random() * 999999)})`,
40                 owner_uuid: this.project2.uuid,
41             }).as('project3');
42         });
43
44         cy.get('@project3').then(() => {
45             cy.createWorkflow(adminUser.token, {
46                 name: `TestWorkflow${Math.floor(Math.random() * 999999)}.cwl`,
47                 definition: "{\n    \"$graph\": [\n        {\n            \"class\": \"Workflow\",\n            \"doc\": \"Reverse the lines in a document, then sort those lines.\",\n            \"hints\": [\n                {\n                    \"acrContainerImage\": \"99b0201f4cade456b4c9d343769a3b70+261\",\n                    \"class\": \"http://arvados.org/cwl#WorkflowRunnerResources\"\n                }\n            ],\n            \"id\": \"#main\",\n            \"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}",
48             })
49                 .as('testWorkflow');
50
51             cy.createCollection(adminUser.token, {
52                 name: `Test collection ${Math.floor(Math.random() * 999999)}`,
53                 owner_uuid: this.project3.uuid,
54                 manifest_text: "./subdir 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo\n. 37b51d194a7513e45b56f6524f2d51f2+3 0:3:baz\n"
55             })
56                 .as('testCollection');
57         });
58
59         cy.get('@testWorkflow').then(() => {
60             cy.loginAs(adminUser);
61
62             cy.get('[data-cy=side-panel-button]').click();
63             cy.get('[data-cy=side-panel-run-process]').click();
64
65             cy.get('.layout-pane')
66                 .contains(this.testWorkflow.name)
67                 .click();
68
69             cy.get('[data-cy=run-process-next-button]').click();
70
71             cy.get('[data-cy=new-process-panel]').contains('Run workflow').should('be.disabled');
72
73             cy.get('[data-cy=new-process-panel]')
74                 .within(() => {
75                     cy.get('[name=name]').type(`Workflow name (${Math.floor(Math.random() * 999999)})`);
76                     cy.contains('input').next().click();
77                 });
78
79             cy.get('[data-cy=choose-a-file-dialog]').as('chooseFileDialog');
80             cy.get('@chooseFileDialog').contains('Home Projects').closest('ul').find('i').click();
81
82             cy.get('@project1').then((project1) => {
83                 cy.get('@chooseFileDialog').find(`[data-id=${project1.uuid}]`).find('i').click();
84             });
85
86             cy.get('@project2').then((project2) => {
87                 cy.get('@chooseFileDialog').find(`[data-id=${project2.uuid}]`).find('i').click();
88             });
89
90             cy.get('@project3').then((project3) => {
91                 cy.get('@chooseFileDialog').find(`[data-id=${project3.uuid}]`).find('i').click();
92             });
93
94             cy.get('@testCollection').then((testCollection) => {
95                 cy.get('@chooseFileDialog').find(`[data-id=${testCollection.uuid}]`).find('i').click();
96             });
97
98             cy.get('@chooseFileDialog').contains('baz').click();
99
100             cy.get('@chooseFileDialog').find('button').contains('Ok').click();
101
102             cy.get('[data-cy=new-process-panel]')
103                 .find('button').contains('Run workflow').should('not.be.disabled');
104         });
105     });
106
107     ['workflow_with_array_fields.yaml', 'workflow_with_default_array_fields.yaml'].forEach((yamlfile) =>
108     it('can select multi files when creating workflow '+yamlfile, () => {
109         cy.createProject({
110             owningUser: activeUser,
111             projectName: 'myProject1',
112             addToFavorites: true
113         });
114
115         cy.createCollection(adminUser.token, {
116             name: `Test collection ${Math.floor(Math.random() * 999999)}`,
117             owner_uuid: activeUser.user.uuid,
118             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n. 37b51d194a7513e45b56f6524f2d51f2+3 0:3:baz\n"
119         })
120             .as('testCollection');
121
122         cy.createCollection(adminUser.token, {
123             name: `Test collection ${Math.floor(Math.random() * 999999)}`,
124             owner_uuid: activeUser.user.uuid,
125             manifest_text: `. 37b51d194a7513e45b56f6524f2d51f2+3 0:3:buz\n`
126         })
127             .as('testCollection2');
128
129         cy.getAll('@myProject1', '@testCollection', '@testCollection2')
130             .then(function ([myProject1, testCollection, testCollection2]) {
131                 cy.readFile('cypress/fixtures/'+yamlfile).then(workflow => {
132                     cy.createWorkflow(adminUser.token, {
133                         name: `TestWorkflow${Math.floor(Math.random() * 999999)}.cwl`,
134                         definition: workflow,
135                         owner_uuid: myProject1.uuid,
136                     })
137                         .as('testWorkflow');
138                 });
139
140                 cy.loginAs(activeUser);
141
142                 cy.get('main').contains(myProject1.name).click();
143
144                 cy.get('[data-cy=side-panel-button]').click();
145
146                 cy.get('#aside-menu-list').contains('Run a workflow').click();
147
148                 cy.get('@testWorkflow')
149                     .then((testWorkflow) => {
150                         cy.get('main').contains(testWorkflow.name).click();
151                         cy.get('[data-cy=run-process-next-button]').click();
152
153                         cy.get('label').contains('foo').parent('div').find('input').click();
154                         cy.get('div[role=dialog]')
155                             .within(() => {
156                                 // must use .then to avoid selecting instead of expanding https://github.com/cypress-io/cypress/issues/5529
157                                 cy.get('p').contains('Home Projects').closest('ul')
158                                     .find('i')
159                                     .then(el => el.click());
160
161                                 cy.get(`[data-id=${testCollection.uuid}]`)
162                                     .find('i').click();
163
164                                 cy.wait(1000);
165                                 cy.contains('bar').closest('[data-action=TOGGLE_ACTIVE]').parent().find('input[type=checkbox]').click();
166                                 cy.contains('baz').closest('[data-action=TOGGLE_ACTIVE]').parent().find('input[type=checkbox]').click();
167
168                                 cy.get('[data-cy=ok-button]').click();
169                             });
170
171                         cy.get('label').contains('bar').parent('div').find('input').click();
172                         cy.get('div[role=dialog]')
173                             .within(() => {
174                                 // must use .then to avoid selecting instead of expanding https://github.com/cypress-io/cypress/issues/5529
175                                 cy.get('p').contains('Home Projects').closest('ul')
176                                     .find('i')
177                                     .then(el => el.click());
178
179                                 cy.get(`[data-id=${testCollection.uuid}]`)
180                                     .find('input[type=checkbox]').click();
181
182                                 cy.get(`[data-id=${testCollection2.uuid}]`)
183                                     .find('input[type=checkbox]').click();
184
185                                 cy.get('[data-cy=ok-button]').click();
186                             });
187                     });
188
189                 cy.get('label').contains('foo').parent('div')
190                     .within(() => {
191                         cy.contains('baz');
192                         cy.contains('bar');
193                     });
194
195                 cy.get('label').contains('bar').parent('div')
196                     .within(() => {
197                         cy.contains(testCollection.name);
198                         cy.contains(testCollection2.name);
199                     });
200             });
201     }));
202
203     it('allows selecting collection subdirectories and reselects existing selections', () => {
204         cy.createProject({
205             owningUser: activeUser,
206             projectName: 'myProject1',
207             addToFavorites: true
208         });
209
210         cy.createCollection(adminUser.token, {
211             name: `Test collection ${Math.floor(Math.random() * 999999)}`,
212             owner_uuid: activeUser.user.uuid,
213             manifest_text: "./subdir/dir1 d41d8cd98f00b204e9800998ecf8427e+0 0:0:\\056\n./subdir/dir2 d41d8cd98f00b204e9800998ecf8427e+0 0:0:\\056\n"
214         })
215             .as('testCollection');
216
217         cy.getAll('@myProject1', '@testCollection')
218             .then(function ([myProject1, testCollection]) {
219                 cy.readFile('cypress/fixtures/workflow_directory_array.yaml').then(workflow => {
220                     cy.createWorkflow(adminUser.token, {
221                         name: `TestWorkflow${Math.floor(Math.random() * 999999)}.cwl`,
222                         definition: workflow,
223                         owner_uuid: myProject1.uuid,
224                     })
225                         .as('testWorkflow');
226                 });
227
228                 cy.loginAs(activeUser);
229
230                 cy.get('main').contains(myProject1.name).click();
231
232                 cy.get('[data-cy=side-panel-button]').click();
233
234                 cy.get('#aside-menu-list').contains('Run a workflow').click();
235
236                 cy.get('@testWorkflow')
237                     .then((testWorkflow) => {
238                         cy.get('main').contains(testWorkflow.name).click();
239                         cy.get('[data-cy=run-process-next-button]').click();
240
241                         cy.get('label').contains('directoryInputName').parent('div').find('input').click();
242                         cy.get('div[role=dialog]')
243                             .within(() => {
244                                 // must use .then to avoid selecting instead of expanding https://github.com/cypress-io/cypress/issues/5529
245                                 cy.get('p').contains('Home Projects').closest('ul')
246                                     .find('i')
247                                     .then(el => el.click());
248
249                                 cy.get(`[data-id=${testCollection.uuid}]`)
250                                     .find('i').click();
251
252                                 cy.get(`[data-id="${testCollection.uuid}/subdir"]`)
253                                     .find('i').click();
254
255                                 cy.contains('dir1').closest('[data-action=TOGGLE_ACTIVE]').parent().find('input[type=checkbox]').click();
256                                 cy.contains('dir2').closest('[data-action=TOGGLE_ACTIVE]').parent().find('input[type=checkbox]').click();
257
258                                 cy.get('[data-cy=ok-button]').click();
259                             });
260
261                         // Verify subdirectories were selected
262                         cy.get('label').contains('directoryInputName').parent('div')
263                             .within(() => {
264                                 cy.contains('dir1');
265                                 cy.contains('dir2');
266                             });
267
268                         // Reopen tree picker and verify subdirectories are preselected
269                         cy.get('label').contains('directoryInputName').parent('div').find('input').click();
270                         cy.waitForDom().get('div[role=dialog]')
271                             .within(() => {
272                                 cy.contains('dir1').closest('[data-action=TOGGLE_ACTIVE]').parent().find('input[type=checkbox]').should('be.checked');
273                                 cy.contains('dir2').closest('[data-action=TOGGLE_ACTIVE]').parent().find('input[type=checkbox]').should('be.checked');
274                             });
275                     });
276
277             });
278     })
279 })