20000: Try to improve cypress reliability
[arvados.git] / cypress / integration / sharing.spec.js
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 describe('Sharing 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         cy.getUser('collectionuser1', 'Collection', 'User', false, true)
19             .as('activeUser').then(function () {
20                 activeUser = this.activeUser;
21             });
22     })
23
24     beforeEach(function () {
25         cy.clearCookies()
26         cy.clearLocalStorage()
27     });
28
29     it('can create and delete sharing URLs on collections', () => {
30         const collName = 'shared-collection ' + new Date().getTime();
31         cy.createCollection(adminUser.token, {
32             name: collName,
33             owner_uuid: adminUser.uuid,
34         }).as('sharedCollection').then(function (sharedCollection) {
35             cy.loginAs(adminUser);
36
37             cy.get('main').contains(sharedCollection.name).rightclick();
38             cy.get('[data-cy=context-menu]').within(() => {
39                 cy.contains('Share').click();
40             });
41             cy.get('.sharing-dialog').within(() => {
42                 cy.contains('Sharing URLs').click();
43                 cy.contains('Create sharing URL');
44                 cy.contains('No sharing URLs');
45                 cy.should('not.contain', 'Token');
46                 cy.should('not.contain', 'expiring at:');
47
48                 cy.contains('Create sharing URL').click();
49                 cy.should('not.contain', 'No sharing URLs');
50                 cy.contains('Token');
51                 cy.contains('expiring at:');
52
53                 cy.get('[data-cy=remove-url-btn]').find('button').click();
54                 cy.contains('No sharing URLs');
55                 cy.should('not.contain', 'Token');
56                 cy.should('not.contain', 'expiring at:');
57             })
58         })
59     });
60
61     it('can share projects to other users', () => {
62         cy.loginAs(adminUser);
63
64         cy.createGroup(adminUser.token, {
65             name: `my-shared-writable-project ${Math.floor(Math.random() * 999999)}`,
66             group_class: 'project',
67         }).as('mySharedWritableProject').then(function (mySharedWritableProject) {
68             cy.contains('Refresh').click();
69             cy.get('main').contains(mySharedWritableProject.name).rightclick();
70             cy.get('[data-cy=context-menu]').within(() => {
71                 cy.contains('Share').click();
72             });
73             cy.get('[id="select-permissions"]').as('selectPermissions');
74             cy.get('@selectPermissions').click();
75             cy.contains('Write').click();
76             cy.get('.sharing-dialog').as('sharingDialog');
77             cy.get('[data-cy=invite-people-field]').find('input').type(activeUser.user.email);
78             cy.get('[role=tooltip]').click();
79             cy.get('@sharingDialog').within(() => {
80                 cy.contains('Save changes').click();
81                 cy.contains('Close').click();
82             });
83         });
84
85         cy.createGroup(adminUser.token, {
86             name: `my-shared-readonly-project ${Math.floor(Math.random() * 999999)}`,
87             group_class: 'project',
88         }).as('mySharedReadonlyProject').then(function (mySharedReadonlyProject) {
89             cy.contains('Refresh').click();
90             cy.get('main').contains(mySharedReadonlyProject.name).rightclick();
91             cy.get('[data-cy=context-menu]').within(() => {
92                 cy.contains('Share').click();
93             });
94             cy.get('.sharing-dialog').as('sharingDialog');
95             cy.get('[data-cy=invite-people-field]').find('input').type(activeUser.user.email);
96             cy.get('[role=tooltip]').click();
97             cy.get('@sharingDialog').within(() => {
98                 cy.contains('Save changes').click();
99                 cy.contains('Close').click();
100             });
101         });
102
103         cy.getAll('@mySharedWritableProject', '@mySharedReadonlyProject')
104             .then(function ([mySharedWritableProject, mySharedReadonlyProject]) {
105                 cy.loginAs(activeUser);
106
107                 cy.contains('Shared with me').click();
108
109                 cy.get('main').contains(mySharedWritableProject.name).rightclick();
110                 cy.get('[data-cy=context-menu]').should('contain', 'Move to trash');
111                 cy.get('[data-cy=context-menu]').contains('Move to trash').click();
112
113                 // GUARD: Let's wait for the above removed project to disappear
114                 // before continuing, to avoid intermittent failures.
115                 cy.get('main').should('not.contain', mySharedWritableProject.name);
116
117                 cy.get('main').contains(mySharedReadonlyProject.name).rightclick();
118                 cy.get('[data-cy=context-menu]').should('not.contain', 'Move to trash');
119             });
120     });
121
122     it('can edit project in shared with me', () => {
123         cy.createProject({
124             owningUser: adminUser,
125             targetUser: activeUser,
126             projectName: 'mySharedWritableProject',
127             canWrite: true,
128             addToFavorites: true
129         });
130
131         cy.getAll('@mySharedWritableProject')
132             .then(function ([mySharedWritableProject]) {
133                 cy.loginAs(activeUser);
134
135                 cy.get('[data-cy=side-panel-tree]').contains('Shared with me').click();
136
137                 const newProjectName = `New project name ${mySharedWritableProject.name}`;
138                 const newProjectDescription = `New project description ${mySharedWritableProject.name}`;
139
140                 cy.testEditProjectOrCollection('main', mySharedWritableProject.name, newProjectName, newProjectDescription);
141             });
142     });
143 });