20225: Correct cypress test names / add terminal newline (style)
[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.get('[data-cy=add-invited-people]').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.get('[data-cy=add-invited-people]').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                 // Test search
110                 cy.get('[data-cy=search-input] input').type('readonly');
111                 cy.get('main').should('not.contain', mySharedWritableProject.name);
112                 cy.get('main').should('contain', mySharedReadonlyProject.name);
113                 cy.get('[data-cy=search-input] input').clear();
114
115                 // Test filter
116                 cy.waitForDom().get('th').contains('Type').click();
117                 cy.get('div[role=presentation]').contains('Project').click();
118                 cy.waitForDom().get('main table tr td').contains('Project').should('not.exist');
119                 cy.get('div[role=presentation]').contains('Project').click();
120                 cy.waitForDom().get('div[role=presentation] button').contains('Close').click();
121
122                 // Test move to trash
123                 cy.get('main').contains(mySharedWritableProject.name).rightclick();
124                 cy.get('[data-cy=context-menu]').should('contain', 'Move to trash');
125                 cy.get('[data-cy=context-menu]').contains('Move to trash').click();
126
127                 // GUARD: Let's wait for the above removed project to disappear
128                 // before continuing, to avoid intermittent failures.
129                 cy.get('main').should('not.contain', mySharedWritableProject.name);
130
131                 cy.get('main').contains(mySharedReadonlyProject.name).rightclick();
132                 cy.get('[data-cy=context-menu]').should('not.contain', 'Move to trash');
133             });
134     });
135
136     it('can edit project in shared with me', () => {
137         cy.createProject({
138             owningUser: adminUser,
139             targetUser: activeUser,
140             projectName: 'mySharedWritableProject',
141             canWrite: true,
142             addToFavorites: true
143         });
144
145         cy.getAll('@mySharedWritableProject')
146             .then(function ([mySharedWritableProject]) {
147                 cy.loginAs(activeUser);
148
149                 cy.get('[data-cy=side-panel-tree]').contains('Shared with me').click();
150
151                 const newProjectName = `New project name ${mySharedWritableProject.name}`;
152                 const newProjectDescription = `New project description ${mySharedWritableProject.name}`;
153
154                 cy.testEditProjectOrCollection('main', mySharedWritableProject.name, newProjectName, newProjectDescription);
155             });
156     });
157
158     it('can share only when target users are present', () => {
159         const collName = `mySharedCollectionForUsers-${new Date().getTime()}`;
160         cy.createCollection(adminUser.token, {
161             name: collName,
162             owner_uuid: adminUser.uuid,
163         }).as('mySharedCollectionForUsers')
164
165         cy.getAll('@mySharedCollectionForUsers')
166             .then(function ([]) {
167                 cy.loginAs(adminUser);
168                 cy.get('[data-cy=project-panel]').contains(collName).rightclick();
169                 cy.get('[data-cy=context-menu]').contains('Share').click();
170                 cy.get('button').get('[data-cy=add-invited-people]').should('be.disabled');
171                 cy.get('[data-cy=invite-people-field] input').type('Anonymous');
172                 cy.get('div[role=tooltip]').contains('anonymous').click();
173                 cy.get('button').get('[data-cy=add-invited-people]').should('not.be.disabled');
174                 cy.get('[data-cy=invite-people-field] div[role=button]').contains('anonymous').parent().find('svg').click();
175                 cy.get('button').get('[data-cy=add-invited-people]').should('be.disabled');
176             });
177     });
178 });