Merge branch '16159-logout-request-with-token'
[arvados-workbench2.git] / cypress / integration / favorites.spec.js
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 describe('Favorites 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('collectionuser1', 'Collection', 'User', false, true)
20             .as('activeUser').then(function () {
21                 activeUser = this.activeUser;
22             }
23             );
24     })
25
26     beforeEach(function () {
27         cy.clearCookies()
28         cy.clearLocalStorage()
29     });
30
31     it('creates and removes a public favorite', function () {
32         cy.loginAs(adminUser);
33
34         cy.createGroup(adminUser.token, {
35             name: `my-favorite-project`,
36             group_class: 'project',
37         }).as('myFavoriteProject').then(function () {
38             cy.contains('Refresh').click();
39             cy.get('main').contains('my-favorite-project').rightclick();
40             cy.contains('Add to public favorites').click();
41             cy.contains('Public Favorites').click();
42             cy.get('main').contains('my-favorite-project').rightclick();
43             cy.contains('Remove from public favorites').click();
44             cy.get('main').contains('my-favorite-project').should('not.exist');
45             cy.trashGroup(adminUser.token, this.myFavoriteProject.uuid);
46         });
47     });
48
49     it('can copy selected into the collection', () => {
50         cy.loginAs(adminUser);
51
52         cy.createCollection(adminUser.token, {
53             name: `Test source collection ${Math.floor(Math.random() * 999999)}`,
54             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
55         })
56             .as('testSourceCollection').then(function (testSourceCollection) {
57                 cy.shareWith(adminUser.token, activeUser.user.uuid, testSourceCollection.uuid, 'can_read');
58             });
59
60         cy.createCollection(adminUser.token, {
61             name: `Test target collection ${Math.floor(Math.random() * 999999)}`,
62         })
63             .as('testTargetCollection').then(function (testTargetCollection) {
64                 cy.shareWith(adminUser.token, activeUser.user.uuid, testTargetCollection.uuid, 'can_write');
65             });
66
67         cy.getAll('@testSourceCollection', '@testTargetCollection')
68             .then(function ([testSourceCollection, testTargetCollection]) {
69                 cy.loginAs(activeUser);
70
71                 cy.get('.layout-pane-primary')
72                     .contains('Projects').click();
73
74                 cy.addToFavorites(activeUser.token, activeUser.user.uuid, testTargetCollection.uuid);
75
76                 cy.get('main').contains(testSourceCollection.name).click();
77                 cy.get('[data-cy=collection-files-panel]').contains('bar');
78                 cy.get('[data-cy=collection-files-panel]').find('input[type=checkbox]').click({ force: true });
79                 cy.get('[data-cy=collection-files-panel-options-btn]').click();
80                 cy.get('[data-cy=context-menu]')
81                     .contains('Copy selected into the collection').click();
82
83                 cy.get('[data-cy=projects-tree-favourites-tree-picker]')
84                     .find('i')
85                     .click();
86
87                 cy.get('[data-cy=projects-tree-favourites-tree-picker]')
88                     .contains(testTargetCollection.name)
89                     .click();
90
91                 cy.get('[data-cy=form-submit-btn]').click();
92
93                 cy.get('.layout-pane-primary')
94                     .contains('Projects').click();
95
96                 cy.get('main').contains(testTargetCollection.name).click();
97
98                 cy.get('[data-cy=collection-files-panel]').contains('bar');
99             });
100     });
101
102     it('can copy collection to favorites', () => {
103         cy.createProject({
104             owningUser: adminUser,
105             targetUser: activeUser,
106             projectName: 'mySharedWritableProject',
107             canWrite: true,
108             addToFavorites: true
109         });
110         cy.createProject({
111             owningUser: adminUser,
112             targetUser: activeUser,
113             projectName: 'mySharedReadonlyProject',
114             canWrite: false,
115             addToFavorites: true
116         });
117         cy.createProject({
118             owningUser: activeUser,
119             projectName: 'myProject1',
120             addToFavorites: true
121         });
122
123         cy.createCollection(adminUser.token, {
124             name: `Test collection ${Math.floor(Math.random() * 999999)}`,
125             owner_uuid: activeUser.user.uuid,
126             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
127         })
128             .as('testCollection');
129
130         cy.getAll('@mySharedWritableProject', '@mySharedReadonlyProject', '@myProject1', '@testCollection')
131             .then(function ([mySharedWritableProject, mySharedReadonlyProject, myProject1, testCollection]) {
132                 cy.loginAs(activeUser);
133
134                 cy.doSearch(`${activeUser.user.uuid}`);
135
136                 cy.contains(testCollection.name).rightclick();
137                 cy.get('[data-cy=context-menu]').within(() => {
138                     cy.contains('Move to').click();
139                 });
140
141                 cy.get('[data-cy=form-dialog]').within(function () {
142                     cy.get('[data-cy=projects-tree-favourites-tree-picker]').find('i').click();
143                     cy.contains(myProject1.name);
144                     cy.contains(mySharedWritableProject.name);
145                     cy.get('[data-cy=projects-tree-favourites-tree-picker]')
146                         .should('not.contain', mySharedReadonlyProject.name);
147                     cy.contains(mySharedWritableProject.name).click();
148                     cy.get('[data-cy=form-submit-btn]').click();
149                 });
150
151                 cy.doSearch(`${mySharedWritableProject.uuid}`);
152                 cy.get('main').contains(testCollection.name);
153             });
154     });
155
156     it('can view favourites in workflow', () => {
157         cy.createProject({
158             owningUser: adminUser,
159             targetUser: activeUser,
160             projectName: 'mySharedWritableProject',
161             canWrite: true,
162             addToFavorites: true
163         });
164         cy.createProject({
165             owningUser: adminUser,
166             targetUser: activeUser,
167             projectName: 'mySharedReadonlyProject',
168             canWrite: false,
169             addToFavorites: true
170         });
171         cy.createProject({
172             owningUser: activeUser,
173             projectName: 'myProject1',
174             addToFavorites: true
175         });
176
177         cy.getAll('@mySharedWritableProject', '@mySharedReadonlyProject', '@myProject1')
178             .then(function ([mySharedWritableProject, mySharedReadonlyProject, myProject1]) {
179                 cy.loginAs(activeUser);
180
181                 cy.createWorkflow(adminUser.token, {
182                     name: `TestWorkflow${Math.floor(Math.random() * 999999)}.cwl`,
183                     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}",
184                     owner_uuid: myProject1.uuid,
185                 })
186                     .as('testWorkflow');
187
188                 cy.createWorkflow(adminUser.token, {
189                     name: `TestWorkflow2-${Math.floor(Math.random() * 999999)}.cwl`,
190                     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\" }",
191                     owner_uuid: myProject1.uuid,
192                 })
193                     .as('testWorkflow2');
194
195                 cy.contains('Shared with me').click();
196
197                 cy.doSearch(`${activeUser.user.uuid}`);
198
199                 cy.get('main').contains(myProject1.name).click();
200
201                 cy.get('[data-cy=side-panel-button]').click();
202
203                 cy.get('#aside-menu-list').contains('Run a process').click();
204
205                 cy.get('@testWorkflow')
206                     .then((testWorkflow) => {
207                         cy.get('main').contains(testWorkflow.name).click();
208                         cy.get('[data-cy=run-process-next-button]').click();
209                         cy.get('[readonly]').click();
210                         cy.get('[data-cy=choose-a-file-dialog]').as('chooseFileDialog');
211                         cy.get('[data-cy=projects-tree-favourites-tree-picker]').contains('Favorites').closest('ul').find('i').click();
212                         cy.get('@chooseFileDialog').find(`[data-id=${mySharedWritableProject.uuid}]`);
213                         cy.get('@chooseFileDialog').find(`[data-id=${mySharedReadonlyProject.uuid}]`);
214                         cy.get('button').contains('Cancel').click();
215                     });
216
217                 cy.get('button').contains('Back').click();
218
219                 cy.get('@testWorkflow2')
220                     .then((testWorkflow2) => {
221                         cy.get('main').contains(testWorkflow2.name).click();
222                         cy.get('button').contains('Change Workflow').click();
223                         cy.get('[data-cy=run-process-next-button]').click();
224                         cy.get('[readonly]').click();
225                         cy.get('[data-cy=choose-a-directory-dialog]').as('chooseDirectoryDialog');
226                         cy.get('[data-cy=projects-tree-favourites-tree-picker]').contains('Favorites').closest('ul').find('i').click();
227                         cy.get('@chooseDirectoryDialog').find(`[data-id=${mySharedWritableProject.uuid}]`);
228                         cy.get('@chooseDirectoryDialog').find(`[data-id=${mySharedReadonlyProject.uuid}]`);
229                     });
230             });
231     });
232 });