Merge branch '20487-inputs-display' refs #20487
[arvados.git] / cypress / integration / workflow.spec.js
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 describe('Registered workflow panel tests', function() {
6     let activeUser;
7     let adminUser;
8
9     before(function() {
10         // Only set up common users once. These aren't set up as aliases because
11         // aliases are cleaned up after every test. Also it doesn't make sense
12         // to set the same users on beforeEach() over and over again, so we
13         // separate a little from Cypress' 'Best Practices' here.
14         cy.getUser('admin', 'Admin', 'User', true, true)
15             .as('adminUser').then(function() {
16                 adminUser = this.adminUser;
17             }
18         );
19         cy.getUser('user', 'Active', 'User', false, true)
20             .as('activeUser').then(function() {
21                 activeUser = this.activeUser;
22             }
23         );
24     });
25
26     it('should handle null definition', function() {
27         cy.createResource(activeUser.token, "workflows", {workflow: {name: "Test wf"}})
28             .then(function(workflowResource) {
29                 cy.loginAs(activeUser);
30                 cy.goToPath(`/workflows/${workflowResource.uuid}`);
31                 cy.get('[data-cy=registered-workflow-info-panel]').should('contain', workflowResource.name);
32                 cy.get('[data-cy=workflow-details-attributes-modifiedby-user]').contains(`Active User (${activeUser.user.uuid})`);
33             });
34     });
35
36     it('should handle malformed definition', function() {
37         cy.createResource(activeUser.token, "workflows", {workflow: {name: "Test wf", definition: "zap:"}})
38             .then(function(workflowResource) {
39                 cy.loginAs(activeUser);
40                 cy.goToPath(`/workflows/${workflowResource.uuid}`);
41                 cy.get('[data-cy=registered-workflow-info-panel]').should('contain', workflowResource.name);
42                 cy.get('[data-cy=workflow-details-attributes-modifiedby-user]').contains(`Active User (${activeUser.user.uuid})`);
43             });
44     });
45
46     it('should handle malformed run', function() {
47         cy.createResource(activeUser.token, "workflows", {workflow: {
48             name: "Test wf",
49             definition: JSON.stringify({
50                 cwlVersion: "v1.2",
51                 $graph: [
52                     {
53                         "class": "Workflow",
54                         "id": "#main",
55                         "inputs": [],
56                         "outputs": [],
57                         "requirements": [
58                             {
59                                 "class": "SubworkflowFeatureRequirement"
60                             }
61                         ],
62                         "steps": [
63                             {
64                                 "id": "#main/cat1-testcli.cwl (v1.2.0-109-g9b091ed)",
65                                 "in": [],
66                                 "label": "cat1-testcli.cwl (v1.2.0-109-g9b091ed)",
67                                 "out": [
68                                     {
69                                         "id": "#main/step/args"
70                                     }
71                                 ],
72                                 "run": `keep:undefined/bar`
73                             }
74                         ]
75                     }
76                 ],
77                 "cwlVersion": "v1.2",
78                 "http://arvados.org/cwl#gitBranch": "1.2.1_proposed",
79                 "http://arvados.org/cwl#gitCommit": "9b091ed7e0bef98b3312e9478c52b89ba25792de",
80                 "http://arvados.org/cwl#gitCommitter": "GitHub <noreply@github.com>",
81                 "http://arvados.org/cwl#gitDate": "Sun, 11 Sep 2022 21:24:42 +0200",
82                 "http://arvados.org/cwl#gitDescribe": "v1.2.0-109-g9b091ed",
83                 "http://arvados.org/cwl#gitOrigin": "git@github.com:common-workflow-language/cwl-v1.2",
84                 "http://arvados.org/cwl#gitPath": "tests/cat1-testcli.cwl",
85                 "http://arvados.org/cwl#gitStatus": ""
86             })
87         }}).then(function(workflowResource) {
88             cy.loginAs(activeUser);
89             cy.goToPath(`/workflows/${workflowResource.uuid}`);
90             cy.get('[data-cy=registered-workflow-info-panel]').should('contain', workflowResource.name);
91             cy.get('[data-cy=workflow-details-attributes-modifiedby-user]').contains(`Active User (${activeUser.user.uuid})`);
92         });
93     });
94
95     const verifyIOParameter = (name, label, doc, val, collection) => {
96         cy.get('table tr').contains(name).parents('tr').within(($mainRow) => {
97             label && cy.contains(label);
98
99             if (val) {
100                 if (Array.isArray(val)) {
101                     val.forEach(v => cy.contains(v));
102                 } else {
103                     cy.contains(val);
104                 }
105             }
106             if (collection) {
107                 cy.contains(collection);
108             }
109         });
110     };
111
112     it('shows workflow details', function() {
113         cy.createCollection(adminUser.token, {
114             name: `Test collection ${Math.floor(Math.random() * 999999)}`,
115             owner_uuid: activeUser.user.uuid,
116             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
117         })
118             .then(function(collectionResource) {
119                 cy.createResource(activeUser.token, "workflows", {workflow: {
120                     name: "Test wf",
121                     definition: JSON.stringify({
122                         cwlVersion: "v1.2",
123                         $graph: [
124                             {
125                                 "class": "Workflow",
126                                 "hints": [
127                                     {
128                                         "class": "DockerRequirement",
129                                         "dockerPull": "python:2-slim"
130                                     }
131                                 ],
132                                 "id": "#main",
133                                 "inputs": [
134                                     {
135                                         "id": "#main/file1",
136                                         "type": "File"
137                                     },
138                                     {
139                                         "id": "#main/numbering",
140                                         "type": [
141                                             "null",
142                                             "boolean"
143                                         ]
144                                     },
145                                     {
146                                         "default": {
147                                             "basename": "args.py",
148                                             "class": "File",
149                                             "location": "keep:de738550734533c5027997c87dc5488e+53/args.py",
150                                             "nameext": ".py",
151                                             "nameroot": "args",
152                                             "size": 179
153                                         },
154                                         "id": "#main/args.py",
155                                         "type": "File"
156                                     }
157                                 ],
158                                 "outputs": [
159                                     {
160                                         "id": "#main/args",
161                                         "outputSource": "#main/step/args",
162                                         "type": {
163                                             "items": "string",
164                                             "name": "_:b0adccc1-502d-476f-8a5b-c8ef7119e2dc",
165                                             "type": "array"
166                                         }
167                                     }
168                                 ],
169                                 "requirements": [
170                                     {
171                                         "class": "SubworkflowFeatureRequirement"
172                                     }
173                                 ],
174                                 "steps": [
175                                     {
176                                         "id": "#main/cat1-testcli.cwl (v1.2.0-109-g9b091ed)",
177                                         "in": [
178                                             {
179                                                 "id": "#main/step/file1",
180                                                 "source": "#main/file1"
181                                             },
182                                             {
183                                                 "id": "#main/step/numbering",
184                                                 "source": "#main/numbering"
185                                             },
186                                             {
187                                                 "id": "#main/step/args.py",
188                                                 "source": "#main/args.py"
189                                             }
190                                         ],
191                                         "label": "cat1-testcli.cwl (v1.2.0-109-g9b091ed)",
192                                         "out": [
193                                             {
194                                                 "id": "#main/step/args"
195                                             }
196                                         ],
197                                         "run": `keep:${collectionResource.portable_data_hash}/bar`
198                                     }
199                                 ]
200                             }
201                         ],
202                         "cwlVersion": "v1.2",
203                         "http://arvados.org/cwl#gitBranch": "1.2.1_proposed",
204                         "http://arvados.org/cwl#gitCommit": "9b091ed7e0bef98b3312e9478c52b89ba25792de",
205                         "http://arvados.org/cwl#gitCommitter": "GitHub <noreply@github.com>",
206                         "http://arvados.org/cwl#gitDate": "Sun, 11 Sep 2022 21:24:42 +0200",
207                         "http://arvados.org/cwl#gitDescribe": "v1.2.0-109-g9b091ed",
208                         "http://arvados.org/cwl#gitOrigin": "git@github.com:common-workflow-language/cwl-v1.2",
209                         "http://arvados.org/cwl#gitPath": "tests/cat1-testcli.cwl",
210                         "http://arvados.org/cwl#gitStatus": ""
211                     })
212                 }}).then(function(workflowResource) {
213                     cy.loginAs(activeUser);
214                     cy.goToPath(`/workflows/${workflowResource.uuid}`);
215                     cy.get('[data-cy=registered-workflow-info-panel]').should('contain', workflowResource.name);
216                     cy.get('[data-cy=workflow-details-attributes-modifiedby-user]').contains(`Active User (${activeUser.user.uuid})`);
217                     cy.get('[data-cy=registered-workflow-info-panel')
218                         .should('contain', 'gitCommit: 9b091ed7e0bef98b3312e9478c52b89ba25792de')
219
220                     cy.get('[data-cy=process-io-card] h6').contains('Inputs')
221                         .parents('[data-cy=process-io-card]').within(() => {
222                             verifyIOParameter('file1', null, '', '', '');
223                             verifyIOParameter('numbering', null, '', '', '');
224                             verifyIOParameter('args.py', null, '', 'args.py', 'de738550734533c5027997c87dc5488e+53');
225                         });
226                     cy.get('[data-cy=process-io-card] h6').contains('Outputs')
227                         .parents('[data-cy=process-io-card]').within(() => {
228                             verifyIOParameter('args', null, '', '', '');
229                         });
230                     cy.get('[data-cy=collection-files-panel]').within(() => {
231                         cy.get('[data-cy=collection-files-right-panel]', { timeout: 5000 })
232                             .should('contain', 'bar');
233                     });
234                 });
235             });
236     });
237 });