17306: Failing test fix
[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-pciker]').find('i').click();
132                     cy.contains(myProject1.name);
133                     cy.contains(mySharedWritableProject.name);
134                     cy.get('[data-cy=projects-tree-favourites-tree-pciker]')
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(activeUser);
147
148         cy.createCollection(adminUser.token, {
149             name: `Test source collection ${Math.floor(Math.random() * 999999)}`,
150             owner_uuid: activeUser.user.uuid,
151             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
152         })
153             .as('testSourceCollection');
154
155         cy.createCollection(adminUser.token, {
156             name: `Test target collection ${Math.floor(Math.random() * 999999)}`,
157             owner_uuid: activeUser.user.uuid
158         })
159             .as('testTargetCollection');
160
161         cy.getAll('@testSourceCollection', '@testTargetCollection')
162             .then(function ([testSourceCollection, testTargetCollection]) {
163                 cy.loginAs(activeUser);
164
165                 cy.get('.layout-pane-primary')
166                     .contains('Projects').click();
167
168                 cy.get('main').contains(testTargetCollection.name).rightclick();
169                 cy.get('[data-cy=context-menu]').within(() => {
170                     cy.contains('Add to favorites').click();
171                 });
172
173                 cy.get('main').contains(testSourceCollection.name).click();
174                 cy.get('[data-cy=collection-files-panel]').contains('bar');
175                 cy.get('[data-cy=collection-files-panel]').find('input[type=checkbox]').click({ force: true });
176                 cy.get('[data-cy=collection-files-panel-options-btn]').click();
177                 cy.get('[data-cy=context-menu]')
178                     .contains('Copy selected into the collection').click();
179
180                 cy.get('[data-cy=projects-tree-favourites-tree-pciker]')
181                     .find('i')
182                     .click();
183
184                 cy.get('[data-cy=projects-tree-favourites-tree-pciker]')
185                     .contains(testTargetCollection.name)
186                     .click();
187
188                 cy.get('[data-cy=form-submit-btn]').click();
189
190                 cy.get('.layout-pane-primary')
191                     .contains('Projects').click();
192
193                 cy.get('main').contains(testTargetCollection.name).click();
194
195                 cy.get('[data-cy=collection-files-panel]').contains('bar');
196             });
197     });
198 });