17500: Allows Cypress tests to navigate using the app's router.
[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.contains(testCollection.name).rightclick();
135                 cy.get('[data-cy=context-menu]').within(() => {
136                     cy.contains('Move to').click();
137                 });
138
139                 cy.get('[data-cy=form-dialog]').within(function () {
140                     cy.get('[data-cy=projects-tree-favourites-tree-picker]').find('i').click();
141                     cy.contains(myProject1.name);
142                     cy.contains(mySharedWritableProject.name);
143                     cy.get('[data-cy=projects-tree-favourites-tree-picker]')
144                         .should('not.contain', mySharedReadonlyProject.name);
145                     cy.contains(mySharedWritableProject.name).click();
146                     cy.get('[data-cy=form-submit-btn]').click();
147                 });
148
149                 cy.goToPath(`/projects/${mySharedWritableProject.uuid}`);
150                 cy.get('main').contains(testCollection.name);
151             });
152     });
153
154     it('can view favourites in workflow', () => {
155         cy.createProject({
156             owningUser: adminUser,
157             targetUser: activeUser,
158             projectName: 'mySharedWritableProject',
159             canWrite: true,
160             addToFavorites: true
161         });
162         cy.createProject({
163             owningUser: adminUser,
164             targetUser: activeUser,
165             projectName: 'mySharedReadonlyProject',
166             canWrite: false,
167             addToFavorites: true
168         });
169         cy.createProject({
170             owningUser: activeUser,
171             projectName: 'myProject1',
172             addToFavorites: true
173         });
174
175         cy.getAll('@mySharedWritableProject', '@mySharedReadonlyProject', '@myProject1')
176             .then(function ([mySharedWritableProject, mySharedReadonlyProject, myProject1]) {
177                 cy.createWorkflow(adminUser.token, {
178                     name: `TestWorkflow${Math.floor(Math.random() * 999999)}.cwl`,
179                     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}",
180                     owner_uuid: myProject1.uuid,
181                 })
182                     .as('testWorkflow');
183
184                 cy.createWorkflow(adminUser.token, {
185                     name: `TestWorkflow2-${Math.floor(Math.random() * 999999)}.cwl`,
186                     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\" }",
187                     owner_uuid: myProject1.uuid,
188                 })
189                     .as('testWorkflow2');
190
191                 cy.loginAs(activeUser);
192
193                 cy.get('main').contains(myProject1.name).click();
194
195                 cy.get('[data-cy=side-panel-button]').click();
196
197                 cy.get('#aside-menu-list').contains('Run a process').click();
198
199                 cy.get('@testWorkflow')
200                     .then((testWorkflow) => {
201                         cy.get('main').contains(testWorkflow.name).click();
202                         cy.get('[data-cy=run-process-next-button]').click();
203                         cy.get('[readonly]').click();
204                         cy.get('[data-cy=choose-a-file-dialog]').as('chooseFileDialog');
205                         cy.get('[data-cy=projects-tree-favourites-tree-picker]').contains('Favorites').closest('ul').find('i').click();
206                         cy.get('@chooseFileDialog').find(`[data-id=${mySharedWritableProject.uuid}]`);
207                         cy.get('@chooseFileDialog').find(`[data-id=${mySharedReadonlyProject.uuid}]`);
208                         cy.get('button').contains('Cancel').click();
209                     });
210
211                 cy.get('button').contains('Back').click();
212
213                 cy.get('@testWorkflow2')
214                     .then((testWorkflow2) => {
215                         cy.get('main').contains(testWorkflow2.name).click();
216                         cy.get('button').contains('Change Workflow').click();
217                         cy.get('[data-cy=run-process-next-button]').click();
218                         cy.get('[readonly]').click();
219                         cy.get('[data-cy=choose-a-directory-dialog]').as('chooseDirectoryDialog');
220                         cy.get('[data-cy=projects-tree-favourites-tree-picker]').contains('Favorites').closest('ul').find('i').click();
221                         cy.get('@chooseDirectoryDialog').find(`[data-id=${mySharedWritableProject.uuid}]`);
222                         cy.get('@chooseDirectoryDialog').find(`[data-id=${mySharedReadonlyProject.uuid}]`);
223                     });
224             });
225     });
226 });