19153: Fix project cypress test
[arvados-workbench2.git] / cypress / integration / group-manage.spec.js
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 describe('Group manage tests', function() {
6     let activeUser;
7     let adminUser;
8     let otherUser;
9     let userThree;
10     const groupName = `Test group (${Math.floor(999999 * Math.random())})`;
11
12     before(function() {
13         // Only set up common users once. These aren't set up as aliases because
14         // aliases are cleaned up after every test. Also it doesn't make sense
15         // to set the same users on beforeEach() over and over again, so we
16         // separate a little from Cypress' 'Best Practices' here.
17         cy.getUser('admin', 'Admin', 'User', true, true)
18             .as('adminUser').then(function() {
19                 adminUser = this.adminUser;
20             }
21         );
22         cy.getUser('user', 'Active', 'User', false, true)
23             .as('activeUser').then(function() {
24                 activeUser = this.activeUser;
25             }
26         );
27         cy.getUser('otheruser', 'Other', 'User', false, true)
28             .as('otherUser').then(function() {
29                 otherUser = this.otherUser;
30             }
31         );
32         cy.getUser('userThree', 'User', 'Three', false, true)
33             .as('userThree').then(function() {
34                 userThree = this.userThree;
35             }
36         );
37     });
38
39     it('creates a new group', function() {
40         cy.loginAs(activeUser);
41
42         // Navigate to Groups
43         cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
44
45         // Create new group
46         cy.get('[data-cy=groups-panel-new-group]').click();
47         cy.get('[data-cy=form-dialog]')
48             .should('contain', 'New Group')
49             .within(() => {
50                 cy.get('input[name=name]').type(groupName);
51                 cy.get('[data-cy=users-field] input').type("three");
52             });
53         cy.get('[role=tooltip]').click();
54         cy.get('[data-cy=form-dialog]').within(() => {
55             cy.get('[data-cy=form-submit-btn]').click();
56         })
57
58         // Check that the group was created
59         cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
60         cy.get('[data-cy=group-members-data-explorer]').contains(activeUser.user.full_name);
61         cy.get('[data-cy=group-members-data-explorer]').contains(userThree.user.full_name);
62     });
63
64     it('adds users to the group', function() {
65         // Add other user to the group
66         cy.get('[data-cy=group-member-add]').click();
67         cy.get('.sharing-dialog')
68             .should('contain', 'Sharing settings')
69             .within(() => {
70                 cy.get('[data-cy=invite-people-field] input').type("other");
71             });
72         cy.get('[role=tooltip]').click();
73         cy.get('.sharing-dialog').contains('Save').click();
74         cy.get('.sharing-dialog').contains('Close').click();
75
76         // Check that both users are present with appropriate permissions
77         cy.get('[data-cy=group-members-data-explorer]')
78             .contains(otherUser.user.full_name)
79             .parents('tr')
80             .within(() => {
81                 cy.contains('Read');
82             });
83         cy.get('[data-cy=group-members-data-explorer] tr')
84             .contains(activeUser.user.full_name)
85             .parents('tr')
86             .within(() => {
87                 cy.contains('Manage');
88             });
89     });
90
91     it('changes permission level of a member', function() {
92         // Test change permission level
93         cy.get('[data-cy=group-members-data-explorer]')
94             .contains(otherUser.user.full_name)
95             .parents('tr')
96             .within(() => {
97                 cy.contains('Read')
98                     .parents('td')
99                     .within(() => {
100                         cy.get('button').click();
101                     });
102             });
103         cy.get('[data-cy=context-menu]')
104             .contains('Write')
105             .click();
106         cy.get('[data-cy=group-members-data-explorer]')
107             .contains(otherUser.user.full_name)
108             .parents('tr')
109             .within(() => {
110                 cy.contains('Write');
111             });
112     });
113
114     it('can unhide and re-hide users', function() {
115         // Must use admin user to have manage permission on user
116         cy.loginAs(adminUser);
117         cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
118         cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
119
120         // Check that other user is hidden
121         cy.get('[data-cy=group-details-permissions-tab]').click();
122         cy.get('[data-cy=group-permissions-data-explorer]')
123             .should('not.contain', otherUser.user.full_name)
124         cy.get('[data-cy=group-details-members-tab]').click();
125
126         // Test unhide
127         cy.get('[data-cy=group-members-data-explorer]')
128             .contains(otherUser.user.full_name)
129             .parents('tr')
130             .within(() => {
131                 cy.get('[data-cy=user-visible-checkbox]').click();
132             });
133         // Check that other user is visible
134         cy.get('[data-cy=group-details-permissions-tab]').click();
135         cy.get('[data-cy=group-permissions-data-explorer]')
136             .contains(otherUser.user.full_name)
137             .parents('tr')
138             .within(() => {
139                 cy.contains('Read');
140             });
141         // Test re-hide
142         cy.get('[data-cy=group-details-members-tab]').click();
143         cy.get('[data-cy=group-members-data-explorer]')
144             .contains(otherUser.user.full_name)
145             .parents('tr')
146             .within(() => {
147                 cy.get('[data-cy=user-visible-checkbox]').click();
148             });
149         // Check that other user is hidden
150         cy.get('[data-cy=group-details-permissions-tab]').click();
151         cy.get('[data-cy=group-permissions-data-explorer]')
152             .should('not.contain', otherUser.user.full_name)
153     });
154
155     it('displays resources shared with the group', function() {
156         // Switch to activeUser
157         cy.loginAs(activeUser);
158         cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
159
160         // Get groupUuid and create shared project
161         cy.get('[data-cy=groups-panel-data-explorer]')
162             .contains(groupName)
163             .parents('tr')
164             .find('[data-cy=uuid]')
165             .invoke('text')
166             .as('groupUuid')
167             .then((groupUuid) => {
168                 cy.createProject({
169                     owningUser: activeUser,
170                     projectName: 'test-project',
171                 }).as('testProject').then((testProject) => {
172                     cy.shareWith(activeUser.token, groupUuid, testProject.uuid, 'can_read');
173                 });
174             });
175
176         // Check that the project is listed in permissions
177         cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
178         cy.get('[data-cy=group-details-permissions-tab]').click();
179         cy.get('[data-cy=group-permissions-data-explorer]')
180             .contains('test-project')
181             .parents('tr')
182             .within(() => {
183                 cy.contains('Read');
184             });
185     });
186
187     it('removes users from the group', function() {
188         cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
189         cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
190
191         // Remove other user
192         cy.get('[data-cy=group-members-data-explorer]')
193             .contains(otherUser.user.full_name)
194             .parents('tr')
195             .within(() => {
196                 cy.get('[data-cy=resource-delete-button]').click();
197             });
198         cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
199         cy.get('[data-cy=group-members-data-explorer]')
200             .should('not.contain', otherUser.user.full_name);
201
202         // Remove user three
203         cy.get('[data-cy=group-members-data-explorer]')
204             .contains(userThree.user.full_name)
205             .parents('tr')
206             .within(() => {
207                 cy.get('[data-cy=resource-delete-button]').click();
208             });
209         cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
210         cy.get('[data-cy=group-members-data-explorer]')
211             .should('not.contain', userThree.user.full_name);
212     });
213
214     it('renames the group', function() {
215         // Navigate to Groups
216         cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
217
218         // Open rename dialog
219         cy.get('[data-cy=groups-panel-data-explorer]')
220             .contains(groupName)
221             .rightclick();
222         cy.get('[data-cy=context-menu]')
223             .contains('Rename')
224             .click();
225
226         // Rename the group
227         cy.get('[data-cy=form-dialog]')
228             .should('contain', 'Edit Group')
229             .within(() => {
230                 cy.get('input[name=name]').clear().type(groupName + ' (renamed)');
231                 cy.get('button').contains('Save').click();
232             });
233
234         // Check that the group was renamed
235         cy.get('[data-cy=groups-panel-data-explorer]')
236             .contains(groupName + ' (renamed)');
237     });
238
239     it('deletes the group', function() {
240         // Navigate to Groups
241         cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
242
243         // Delete the group
244         cy.get('[data-cy=groups-panel-data-explorer]')
245             .contains(groupName + ' (renamed)')
246             .rightclick();
247         cy.get('[data-cy=context-menu]')
248             .contains('Remove')
249             .click();
250         cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
251
252         // Check that the group was deleted
253         cy.get('[data-cy=groups-panel-data-explorer]')
254             .should('not.contain', groupName + ' (renamed)');
255     });
256
257     it('disables group-related controls for built-in groups', function() {
258         cy.loginAs(adminUser);
259
260         ['All users', 'Anonymous users', 'System group'].forEach((builtInGroup) => {
261             cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
262             cy.get('[data-cy=groups-panel-data-explorer]').contains(builtInGroup).click();
263
264             // Check group member actions
265             cy.get('[data-cy=group-members-data-explorer]')
266                 .within(() => {
267                     cy.get('[data-cy=group-member-add]').should('not.exist');
268                     cy.get('[data-cy=user-visible-checkbox] input').should('be.disabled');
269                     cy.get('[data-cy=resource-delete-button]').should('be.disabled');
270                     cy.get('[data-cy=edit-permission-button]').should('not.exist');
271                 });
272
273             // Check permissions actions
274             cy.get('[data-cy=group-details-permissions-tab]').click();
275             cy.get('[data-cy=group-permissions-data-explorer]').within(() => {
276                 cy.get('[data-cy=resource-delete-button]').should('be.disabled');
277                 cy.get('[data-cy=edit-permission-button]').should('not.exist');
278             });
279         });
280     });
281
282 });