21910: Merge branch 'main' into 21910-remove-api_client_id
[arvados.git] / services / workbench2 / cypress / e2e / favorites.cy.js
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 const kebabCase = require('lodash/kebabCase');
6
7 describe('Favorites tests', function () {
8     let activeUser;
9     let adminUser;
10
11     before(function () {
12         // Only set up common users once. These aren't set up as aliases because
13         // aliases are cleaned up after every test. Also it doesn't make sense
14         // to set the same users on beforeEach() over and over again, so we
15         // separate a little from Cypress' 'Best Practices' here.
16         cy.getUser('admin', 'Admin', 'User', true, true)
17             .as('adminUser').then(function () {
18                 adminUser = this.adminUser;
19             });
20         cy.getUser('collectionuser1', 'Collection', 'User', false, true)
21             .as('activeUser').then(function () {
22                 activeUser = this.activeUser;
23             });
24     });
25
26     it('creates and removes a public favorite', function () {
27         cy.loginAs(adminUser);
28
29         cy.createGroup(adminUser.token, {
30             name: `my-favorite-project`,
31             group_class: 'project',
32         }).as('myFavoriteProject').then(function () {
33             cy.contains('Refresh').click();
34             cy.get('main').contains('my-favorite-project').rightclick();
35             cy.contains('Add to public favorites').click();
36             cy.contains('Public Favorites').click();
37             cy.get('main').contains('my-favorite-project').rightclick();
38             cy.contains('Remove from public favorites').click();
39             cy.get('main').contains('my-favorite-project').should('not.exist');
40             cy.trashGroup(adminUser.token, this.myFavoriteProject.uuid);
41         });
42     });
43
44     // Disabled while addressing #18587
45     it.skip('can copy selected into the collection', () => {
46         cy.createCollection(adminUser.token, {
47             name: `Test source collection ${Math.floor(Math.random() * 999999)}`,
48             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
49         }).as('testSourceCollection').then(function (testSourceCollection) {
50             cy.shareWith(adminUser.token, activeUser.user.uuid, testSourceCollection.uuid, 'can_read');
51         });
52         cy.createCollection(adminUser.token, {
53             name: `Test target collection ${Math.floor(Math.random() * 999999)}`,
54         }).as('testTargetCollection').then(function (testTargetCollection) {
55             cy.shareWith(adminUser.token, activeUser.user.uuid, testTargetCollection.uuid, 'can_write');
56             cy.addToFavorites(activeUser.token, activeUser.user.uuid, testTargetCollection.uuid);
57         });
58
59         cy.getAll('@testSourceCollection', '@testTargetCollection')
60             .then(function ([testSourceCollection, testTargetCollection]) {
61                 cy.loginAs(activeUser);
62                 cy.goToPath(`/collections/${testSourceCollection.uuid}`);
63                 cy.get('[data-cy=collection-files-panel]').contains('bar');
64                 cy.get('[data-cy=collection-files-panel]').find('input[type=checkbox]').click();
65                 cy.get('[data-cy=collection-files-panel-options-btn]').click();
66                 cy.get('[data-cy=context-menu]')
67                     .contains('Copy selected into the collection').click();
68                 cy.get('[data-cy=projects-tree-favourites-tree-picker]')
69                     .find('i')
70                     .click();
71                 cy.get('[data-cy=projects-tree-favourites-tree-picker]')
72                     .contains(testTargetCollection.name)
73                     .click();
74                 cy.get('[data-cy=form-submit-btn]').click();
75                 cy.get('.layout-pane-primary').contains('Projects').click();
76                 cy.goToPath(`/collections/${testTargetCollection.uuid}`);
77                 cy.get('[data-cy=collection-files-panel]').contains('bar');
78             });
79     });
80
81     it('can copy collection to favorites', () => {
82         cy.createProject({
83             owningUser: adminUser,
84             targetUser: activeUser,
85             projectName: 'mySharedWritableProject',
86             canWrite: true,
87             addToFavorites: true
88         });
89         cy.createProject({
90             owningUser: adminUser,
91             targetUser: activeUser,
92             projectName: 'mySharedReadonlyProject',
93             canWrite: false,
94             addToFavorites: true
95         });
96         cy.createProject({
97             owningUser: activeUser,
98             projectName: 'myProject1',
99             addToFavorites: true
100         });
101
102         cy.createCollection(adminUser.token, {
103             name: `Test collection ${Math.floor(Math.random() * 999999)}`,
104             owner_uuid: activeUser.user.uuid,
105             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
106         })
107             .as('testCollection');
108
109         cy.getAll('@mySharedWritableProject', '@mySharedReadonlyProject', '@myProject1', '@testCollection')
110             .then(function ([mySharedWritableProject, mySharedReadonlyProject, myProject1, testCollection]) {
111                 cy.loginAs(activeUser);
112
113                 cy.contains(testCollection.name).rightclick();
114                 cy.get('[data-cy=context-menu]').within(() => {
115                     cy.contains('Move to').click();
116                 });
117
118                 cy.get('[data-cy=form-dialog]').within(function () {
119                     // must use .then to avoid selecting instead of expanding https://github.com/cypress-io/cypress/issues/5529
120                     cy.get('[data-cy=projects-tree-favourites-tree-picker]')
121                         .find('i')
122                         .then(el => el.click());
123                     cy.contains(myProject1.name);
124                     cy.contains(mySharedWritableProject.name);
125                     cy.get('[data-cy=projects-tree-favourites-tree-picker]')
126                         .should('not.contain', mySharedReadonlyProject.name);
127                     cy.contains(mySharedWritableProject.name).click();
128                     cy.get('[data-cy=form-submit-btn]').click();
129                 });
130
131                 cy.goToPath(`/projects/${mySharedWritableProject.uuid}`);
132                 cy.get('main').contains(testCollection.name);
133             });
134     });
135
136     it('can edit project and collections in favorites', () => {
137         cy.createProject({
138             owningUser: adminUser,
139             projectName: 'mySharedWritableProject',
140             canWrite: true,
141             addToFavorites: true
142         });
143
144         cy.createCollection(adminUser.token, {
145             owner_uuid: adminUser.user.uuid,
146             name: `Test target collection ${Math.floor(Math.random() * 999999)}`,
147         }).as('testTargetCollection').then(function (testTargetCollection) {
148             cy.addToFavorites(adminUser.token, adminUser.user.uuid, testTargetCollection.uuid);
149         });
150
151         cy.getAll('@mySharedWritableProject', '@testTargetCollection')
152             .then(function ([mySharedWritableProject, testTargetCollection]) {
153                 cy.loginAs(adminUser);
154
155                 cy.get('[data-cy=side-panel-tree]').contains('My Favorites').click();
156
157                 const newProjectName = `New project name ${mySharedWritableProject.name}`;
158                 const newProjectDescription = `New project description ${mySharedWritableProject.name}`;
159                 const newCollectionName = `New collection name ${testTargetCollection.name}`;
160                 const newCollectionDescription = `New collection description ${testTargetCollection.name}`;
161
162                 cy.testEditProjectOrCollection('main', mySharedWritableProject.name, newProjectName, newProjectDescription);
163                 cy.testEditProjectOrCollection('main', testTargetCollection.name, newCollectionName, newCollectionDescription, false);
164
165                 cy.get('[data-cy=side-panel-tree]').contains('Projects').click();
166
167                 cy.get('main').contains(newProjectName).rightclick();
168                 cy.contains('Add to public favorites').click();
169                 cy.get('main').contains(newCollectionName).rightclick();
170                 cy.contains('Add to public favorites').click();
171
172                 cy.get('[data-cy=side-panel-tree]').contains('Public Favorites').click();
173
174                 cy.testEditProjectOrCollection('main', newProjectName, mySharedWritableProject.name, 'newProjectDescription');
175                 cy.testEditProjectOrCollection('main', newCollectionName, testTargetCollection.name, 'newCollectionDescription', false);
176             });
177     });
178
179     it('can view favorites in workflow', () => {
180         cy.createProject({
181             owningUser: adminUser,
182             targetUser: activeUser,
183             projectName: 'mySharedWritableProject',
184             canWrite: true,
185             addToFavorites: true
186         });
187         cy.createProject({
188             owningUser: adminUser,
189             targetUser: activeUser,
190             projectName: 'mySharedReadonlyProject',
191             canWrite: false,
192             addToFavorites: true
193         });
194         cy.createProject({
195             owningUser: activeUser,
196             projectName: 'myProject1',
197             addToFavorites: true
198         });
199
200         cy.getAll('@mySharedWritableProject', '@mySharedReadonlyProject', '@myProject1')
201             .then(function ([mySharedWritableProject, mySharedReadonlyProject, myProject1]) {
202                 cy.createWorkflow(adminUser.token, {
203                     name: `TestWorkflow${Math.floor(Math.random() * 999999)}.cwl`,
204                     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}",
205                     owner_uuid: myProject1.uuid,
206                 })
207                     .as('testWorkflow');
208
209                 cy.createWorkflow(adminUser.token, {
210                     name: `TestWorkflow2-${Math.floor(Math.random() * 999999)}.cwl`,
211                     definition: "{     \"$graph\": [         {             \"$namespaces\": {                 \"arv\": \"http://arvados.org/cwl#\"             },             \"class\": \"Workflow\",             \"doc\": \"Detect blurriness of WSI data.\",             \"id\": \"#main\",             \"inputs\": [                 {                     \"default\": {                         \"basename\": \"3d3cb547725e72ddb442bc620adbc342+2463\",                         \"class\": \"Directory\",                         \"location\": \"keep:3d3cb547725e72ddb442bc620adbc342+2463\"                     },                     \"doc\": \"Collection containing all pipeline input images\",                     \"id\": \"#main/image_collection\",                     \"type\": \"Directory\"                 }             ],             \"outputs\": [                 {                     \"id\": \"#main/blur_report\",                     \"outputSource\": \"#main/blurdetection/report\",                     \"type\": \"Any\"                 }             ],             \"steps\": [                 {                     \"id\": \"#main/blurdetection\",                     \"in\": [                         {                             \"id\": \"#main/blurdetection/image_collection\",                             \"source\": \"#main/image_collection\"                         }                     ],                     \"out\": [                         \"#main/blurdetection/report\"                     ],                     \"run\": \"#blurdetection.cwl\"                 }             ]         },         {             \"arguments\": [                 \"--num_workers\",                 \"0\",                 \"--wsi_dir\",                 \"$(inputs.image_collection)\",                 \"--tile_out_dir\",                 \"$(runtime.outdir)\"             ],             \"baseCommand\": [                 \"python3\",                 \"/updated_blur_on_folder.py\"             ],             \"class\": \"CommandLineTool\",             \"hints\": [                 {                     \"class\": \"DockerRequirement\",                     \"dockerPull\": \"updated_score_aws:cpu2\",                     \"http://arvados.org/cwl#dockerCollectionPDH\": \"0d6702518d1408ce2c471ffec40695cf+4924\"                 },                 {                     \"class\": \"ResourceRequirement\",                     \"coresMin\": 8,                     \"ramMin\": 20000                 },                 {                     \"class\": \"http://arvados.org/cwl#RuntimeConstraints\",                     \"keep_cache\": 2000                 }             ],             \"id\": \"#blurdetection.cwl\",             \"inputs\": [                 {                     \"doc\": \"Collection containing all pipeline input images\",                     \"id\": \"#blurdetection.cwl/image_collection\",                     \"type\": \"Directory\"                 }             ],             \"outputs\": [                 {                     \"id\": \"#blurdetection.cwl/report\",                     \"outputBinding\": {                         \"glob\": \"*.csv\"                     },                     \"type\": \"Any\"                 }             ]         }     ],     \"cwlVersion\": \"v1.0\" }",
212                     owner_uuid: myProject1.uuid,
213                 })
214                     .as('testWorkflow2');
215
216                 cy.loginAs(activeUser);
217
218                 cy.get('main').contains(myProject1.name).click();
219
220                 cy.get('[data-cy=side-panel-button]').click();
221
222                 cy.get('#aside-menu-list').contains('Run a workflow').click();
223
224                 cy.get('@testWorkflow')
225                     .then((testWorkflow) => {
226                         cy.get('main').contains(testWorkflow.name).click();
227                         cy.get('[data-cy=run-process-next-button]').click();
228                         cy.get('[data-cy=new-process-panel]')
229                             .within(() => {
230                                 cy.contains('input').next().click();
231                             });
232                         cy.get('[data-cy=choose-a-file-dialog]').as('chooseFileDialog');
233                         cy.get('[data-cy=projects-tree-favourites-tree-picker]').contains('Favorites').closest('ul').find('i').click();
234                         cy.get('@chooseFileDialog').find(`[data-id=${mySharedWritableProject.uuid}]`);
235                         cy.get('@chooseFileDialog').find(`[data-id=${mySharedReadonlyProject.uuid}]`);
236                         cy.get('button').contains('Cancel').click();
237                     });
238
239                 cy.get('button').contains('Back').click();
240
241                 cy.get('@testWorkflow2')
242                     .then((testWorkflow2) => {
243                         cy.get('main').contains(testWorkflow2.name).click();
244                         cy.get('button').contains('Change Workflow').click();
245                         cy.get('[data-cy=run-process-next-button]').click();
246                         cy.get('[data-cy=new-process-panel]')
247                             .within(() => {
248                                 cy.contains('image_collection').next().click();
249                             });
250                         cy.get('[data-cy=choose-a-directory-dialog]').as('chooseDirectoryDialog');
251                         cy.get('[data-cy=projects-tree-favourites-tree-picker]').contains('Favorites').closest('ul').find('i').click();
252                         cy.get('@chooseDirectoryDialog').find(`[data-id=${mySharedWritableProject.uuid}]`);
253                         cy.get('@chooseDirectoryDialog').find(`[data-id=${mySharedReadonlyProject.uuid}]`);
254                     });
255             });
256     });
257
258     it('shows the correct favorites and public favorites in the side panel', () => {
259         cy.createProject({
260             owningUser: adminUser,
261             projectName: 'myFavoriteProject1',
262         }).as('myFavoriteProject1');
263         cy.createProject({
264             owningUser: adminUser,
265             projectName: 'myFavoriteProject2',
266         }).as('myFavoriteProject2');
267         cy.createProject({
268             owningUser: adminUser,
269             projectName: 'myPublicFavoriteProject1',
270         }).as('myPublicFavoriteProject1');
271         cy.createProject({
272             owningUser: adminUser,
273             projectName: 'myPublicFavoriteProject2',
274         }).as('myPublicFavoriteProject2');
275
276         cy.getAll('@myFavoriteProject1', '@myFavoriteProject2', '@myPublicFavoriteProject1', '@myPublicFavoriteProject2')
277         .then(function ([myFavoriteProject1, myFavoriteProject2, myPublicFavoriteProject1, myPublicFavoriteProject2]) {
278                 cy.loginAs(adminUser);
279
280                 //add two projects to favorites
281                 cy.get('[data-cy=side-panel-tree]').contains('myFavoriteProject1').rightclick();
282                 cy.contains('Add to favorites').click();
283                 cy.get('[data-cy=side-panel-tree]').contains('myFavoriteProject2').rightclick();
284                 cy.contains('Add to favorites').click();
285
286                 //add two projects to public favorites
287                 cy.get('[data-cy=side-panel-tree]').contains('myPublicFavoriteProject1').rightclick();
288                 cy.contains('Add to public favorites').click();
289                 cy.get('[data-cy=side-panel-tree]').contains('myPublicFavoriteProject2').rightclick();
290                 cy.contains('Add to public favorites').click();
291
292                 //close "Home Projects", which is open by default
293                 cy.get(`[data-cy=tree-item-toggle-${kebabCase(adminUser.user.uuid)}]`).click();
294
295                 //check if the correct favorites are displayed in the side panel
296                 cy.get('span').contains('myFavoriteProject1').should('not.exist');
297                 cy.get('span').contains('myFavoriteProject2').should('not.exist');
298                 cy.get(`[data-cy=tree-item-toggle-my-favorites]`).click();
299                 cy.get('span').contains('myFavoriteProject1').should('exist');
300                 cy.get('span').contains('myFavoriteProject2').should('exist');
301                 cy.get(`[data-cy=tree-item-toggle-my-favorites]`).click();
302
303                 //check if the correct public favorites are displayed in the side panel
304                 cy.get('span').contains('myPublicFavoriteProject1').should('not.exist');
305                 cy.get('span').contains('myPublicFavoriteProject2').should('not.exist');
306                 cy.get(`[data-cy=tree-item-toggle-public-favorites]`).click();
307                 cy.get('span').contains('myPublicFavoriteProject1').should('exist');
308                 cy.get('span').contains('myPublicFavoriteProject2').should('exist');
309                 cy.get(`[data-cy=tree-item-toggle-public-favorites]`).click();
310
311                 //double check both sets
312                 cy.get('span').contains('myFavoriteProject1').should('not.exist');
313                 cy.get('span').contains('myFavoriteProject2').should('not.exist');
314                 cy.get(`[data-cy=tree-item-toggle-my-favorites]`).click();
315                 cy.get('span').contains('myFavoriteProject1').should('exist');
316                 cy.get('span').contains('myFavoriteProject2').should('exist');
317                 cy.get(`[data-cy=tree-item-toggle-my-favorites]`).click();
318
319                 cy.get('span').contains('myPublicFavoriteProject1').should('not.exist');
320                 cy.get('span').contains('myPublicFavoriteProject2').should('not.exist');
321                 cy.get(`[data-cy=tree-item-toggle-public-favorites]`).click();
322                 cy.get('span').contains('myPublicFavoriteProject1').should('exist');
323                 cy.get('span').contains('myPublicFavoriteProject2').should('exist');
324                 cy.get(`[data-cy=tree-item-toggle-public-favorites]`).click();
325         });
326     });
327 });