Merge branch 'master' into 16848-token-handling-improvements
[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('checks that Public favorites does not appear under shared with me', function () {
32         cy.loginAs(adminUser);
33         cy.contains('Shared with me').click();
34         cy.get('main').contains('Public favorites').should('not.exist');
35     });
36
37     it('creates and removes a public favorite', function () {
38         cy.loginAs(adminUser);
39         cy.createGroup(adminUser.token, {
40             name: `my-favorite-project`,
41             group_class: 'project',
42         }).as('myFavoriteProject').then(function () {
43             cy.contains('Refresh').click();
44             cy.get('main').contains('my-favorite-project').rightclick();
45             cy.contains('Add to public favorites').click();
46             cy.contains('Public Favorites').click();
47             cy.get('main').contains('my-favorite-project').rightclick();
48             cy.contains('Remove from public favorites').click();
49             cy.get('main').contains('my-favorite-project').should('not.exist');
50             cy.trashGroup(adminUser.token, this.myFavoriteProject.uuid);
51         });
52     });
53
54     it('can copy collection to favorites', () => {
55         cy.loginAs(adminUser);
56
57         cy.createGroup(adminUser.token, {
58             name: `my-shared-writable-project ${Math.floor(Math.random() * 999999)}`,
59             group_class: 'project',
60         }).as('mySharedWritableProject').then(function (mySharedWritableProject) {
61             cy.contains('Refresh').click();
62             cy.get('main').contains(mySharedWritableProject.name).rightclick();
63             cy.get('[data-cy=context-menu]').within(() => {
64                 cy.contains('Share').click();
65             });
66             cy.get('[id="select-permissions"]').as('selectPermissions');
67             cy.get('@selectPermissions').click();
68             cy.contains('Write').click();
69             cy.get('.sharing-dialog').as('sharingDialog');
70             cy.get('[data-cy=invite-people-field]').find('input').type(activeUser.user.email);
71             cy.get('[role=tooltip]').click();
72             cy.get('@sharingDialog').contains('Save').click();
73         });
74
75         cy.createGroup(adminUser.token, {
76             name: `my-shared-readonly-project ${Math.floor(Math.random() * 999999)}`,
77             group_class: 'project',
78         }).as('mySharedReadonlyProject').then(function (mySharedReadonlyProject) {
79             cy.contains('Refresh').click();
80             cy.get('main').contains(mySharedReadonlyProject.name).rightclick();
81             cy.get('[data-cy=context-menu]').within(() => {
82                 cy.contains('Share').click();
83             });
84             cy.get('.sharing-dialog').as('sharingDialog');
85             cy.get('[data-cy=invite-people-field]').find('input').type(activeUser.user.email);
86             cy.get('[role=tooltip]').click();
87             cy.get('@sharingDialog').contains('Save').click();
88         });
89
90         cy.createGroup(activeUser.token, {
91             name: `my-project ${Math.floor(Math.random() * 999999)}`,
92             group_class: 'project',
93         }).as('myProject1');
94
95         cy.createCollection(adminUser.token, {
96             name: `Test collection ${Math.floor(Math.random() * 999999)}`,
97             owner_uuid: activeUser.user.uuid,
98             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
99         })
100             .as('testCollection');
101
102         cy.getAll('@mySharedWritableProject', '@mySharedReadonlyProject', '@myProject1', '@testCollection')
103             .then(function ([mySharedWritableProject, mySharedReadonlyProject, myProject1, testCollection]) {
104                 cy.loginAs(activeUser);
105
106                 cy.contains('Shared with me').click();
107
108                 cy.get('main').contains(mySharedWritableProject.name).rightclick();
109                 cy.get('[data-cy=context-menu]').within(() => {
110                     cy.contains('Add to favorites').click();
111                 });
112
113                 cy.get('main').contains(mySharedReadonlyProject.name).rightclick();
114                 cy.get('[data-cy=context-menu]').within(() => {
115                     cy.contains('Add to favorites').click();
116                 });
117
118                 cy.doSearch(`${activeUser.user.uuid}`);
119
120                 cy.get('main').contains(myProject1.name).rightclick();
121                 cy.get('[data-cy=context-menu]').within(() => {
122                     cy.contains('Add to favorites').click();
123                 });
124
125                 cy.contains(testCollection.name).rightclick();
126                 cy.get('[data-cy=context-menu]').within(() => {
127                     cy.contains('Move to').click();
128                 });
129
130                 cy.get('[data-cy=form-dialog]').within(function () {
131                     cy.get('[data-cy=projects-tree-favourites-tree-picker]').find('i').click();
132                     cy.contains(myProject1.name);
133                     cy.contains(mySharedWritableProject.name);
134                     cy.get('[data-cy=projects-tree-favourites-tree-picker]')
135                         .should('not.contain', mySharedReadonlyProject.name);
136                     cy.contains(mySharedWritableProject.name).click();
137                     cy.get('[data-cy=form-submit-btn]').click();
138                 });
139
140                 cy.doSearch(`${mySharedWritableProject.uuid}`);
141                 cy.get('main').contains(testCollection.name);
142             });
143     });
144
145     it('can copy selected into the collection', () => {
146         cy.loginAs(adminUser);
147
148         cy.createCollection(adminUser.token, {
149             name: `Test source collection ${Math.floor(Math.random() * 999999)}`,
150             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
151         })
152             .as('testSourceCollection').then(function (testSourceCollection) {
153                 cy.contains('Refresh').click();
154                 cy.get('main').contains(testSourceCollection.name).rightclick();
155                 cy.get('[data-cy=context-menu]').within(() => {
156                     cy.contains('Share').click();
157                 });
158                 cy.get('[id="select-permissions"]').as('selectPermissions');
159                 cy.get('@selectPermissions').click();
160                 cy.contains('Write').click();
161                 cy.get('.sharing-dialog').as('sharingDialog');
162                 cy.get('[data-cy=invite-people-field]').find('input').type(activeUser.user.email);
163                 cy.get('[role=tooltip]').click();
164                 cy.get('@sharingDialog').contains('Save').click();
165             });
166
167         cy.createCollection(adminUser.token, {
168             name: `Test target collection ${Math.floor(Math.random() * 999999)}`,
169         })
170             .as('testTargetCollection').then(function (testTargetCollection) {
171                 cy.contains('Refresh').click();
172                 cy.get('main').contains(testTargetCollection.name).rightclick();
173                 cy.get('[data-cy=context-menu]').within(() => {
174                     cy.contains('Share').click();
175                 });
176                 cy.get('[id="select-permissions"]').as('selectPermissions');
177                 cy.get('@selectPermissions').click();
178                 cy.contains('Write').click();
179                 cy.get('.sharing-dialog').as('sharingDialog');
180                 cy.get('[data-cy=invite-people-field]').find('input').type(activeUser.user.email);
181                 cy.get('[role=tooltip]').click();
182                 cy.get('@sharingDialog').contains('Save').click();
183             });
184
185         cy.getAll('@testSourceCollection', '@testTargetCollection')
186             .then(function ([testSourceCollection, testTargetCollection]) {
187                 cy.loginAs(activeUser);
188
189                 cy.get('.layout-pane-primary')
190                     .contains('Projects').click();
191
192                 cy.get('main').contains(testTargetCollection.name).rightclick();
193                 cy.get('[data-cy=context-menu]').within(() => {
194                     cy.contains('Add to favorites').click();
195                 });
196
197                 cy.get('main').contains(testSourceCollection.name).click();
198                 cy.get('[data-cy=collection-files-panel]').contains('bar');
199                 cy.get('[data-cy=collection-files-panel]').find('input[type=checkbox]').click({ force: true });
200                 cy.get('[data-cy=collection-files-panel-options-btn]').click();
201                 cy.get('[data-cy=context-menu]')
202                     .contains('Copy selected into the collection').click();
203
204                 cy.get('[data-cy=projects-tree-favourites-tree-picker]')
205                     .find('i')
206                     .click();
207
208                 cy.get('[data-cy=projects-tree-favourites-tree-picker]')
209                     .contains(testTargetCollection.name)
210                     .click();
211
212                 cy.get('[data-cy=form-submit-btn]').click();
213
214                 cy.get('.layout-pane-primary')
215                     .contains('Projects').click();
216
217                 cy.get('main').contains(testTargetCollection.name).click();
218
219                 cy.get('[data-cy=collection-files-panel]').contains('bar');
220             });
221     });
222 });