14abcd2ded33f0d3dca08095de459eb827031682
[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     const groupName = `Test group (${Math.floor(999999 * Math.random())})`;
10
11     before(function() {
12         // Only set up common users once. These aren't set up as aliases because
13         // aliases are cleaned up after every test. Also it doesn't make sense
14         // to set the same users on beforeEach() over and over again, so we
15         // separate a little from Cypress' 'Best Practices' here.
16         cy.getUser('admin', 'Admin', 'User', true, true)
17             .as('adminUser').then(function() {
18                 adminUser = this.adminUser;
19             }
20         );
21         cy.getUser('user', 'Active', 'User', false, true)
22             .as('activeUser').then(function() {
23                 activeUser = this.activeUser;
24             }
25         );
26         cy.getUser('otheruser', 'Other', 'User', false, true)
27             .as('otherUser').then(function() {
28                 otherUser = this.otherUser;
29             }
30         );
31     });
32
33     beforeEach(function() {
34         cy.clearCookies();
35         cy.clearLocalStorage();
36     });
37
38     it('creates a new group', function() {
39         cy.loginAs(activeUser);
40
41         // Navigate to Groups
42         cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
43
44         // Create new group
45         cy.get('[data-cy=groups-panel-new-group]').click();
46         cy.get('[data-cy=form-dialog]')
47             .should('contain', 'Create a group')
48             .within(() => {
49                 cy.get('input[name=name]').type(groupName);
50                 cy.get('button[type=submit]').click();
51             });
52         
53         // Check that the group was created
54         cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
55         cy.get('[data-cy=group-members-data-explorer]').contains('Active User');
56     });
57
58     it('adds users to the group', function() {
59         // Add other user to the group
60         cy.get('[data-cy=group-member-add]').click();
61         cy.get('[data-cy=form-dialog]')
62             .should('contain', 'Add users')
63             .within(() => {
64                 cy.get('input').type("other");
65             });
66         cy.contains('Other User').click();
67         cy.get('[data-cy=form-dialog] button[type=submit]').click();
68
69         // Check that both users are present with appropriate permissions
70         cy.get('[data-cy=group-members-data-explorer]')
71             .contains('Other User')
72             .parents('tr')
73             .within(() => {
74                 cy.contains('Read');
75             });
76         cy.get('[data-cy=group-members-data-explorer] tr')
77             .contains('Active User')
78             .parents('tr')
79             .within(() => {
80                 cy.contains('Manage');
81             });
82     });
83
84     it('changes permission level of a member', function() {
85         // Test change permission level
86         cy.get('[data-cy=group-members-data-explorer]')
87             .contains('Other User')
88             .parents('tr')
89             .within(() => {
90                 cy.contains('Read')
91                     .parents('td')
92                     .within(() => {
93                         cy.get('button').click();
94                     });
95             });
96         cy.get('[data-cy=context-menu]')
97             .contains('Write')
98             .click();
99         cy.get('[data-cy=group-members-data-explorer]')
100             .contains('Other User')
101             .parents('tr')
102             .within(() => {
103                 cy.contains('Write');
104             });
105     });
106
107     it('can unhide and re-hide users', function() {
108         // Must use admin user to have manage permission on user
109         cy.loginAs(adminUser);
110         cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
111         cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
112
113         // Check that other user is hidden
114         cy.get('[data-cy=group-details-permissions-tab]').click();
115         cy.get('[data-cy=group-permissions-data-explorer]')
116             .should('not.contain', 'Other User')
117         cy.get('[data-cy=group-details-members-tab]').click();
118
119         // Test unhide
120         cy.get('[data-cy=group-members-data-explorer]')
121             .contains('Other User')
122             .parents('tr')
123             .within(() => {
124                 cy.get('[data-cy=user-hidden-checkbox]').click();
125             });
126         // Check that other user is visible
127         cy.get('[data-cy=group-details-permissions-tab]').click();
128         cy.get('[data-cy=group-permissions-data-explorer]')
129             .contains('Other User')
130             .parents('tr')
131             .within(() => {
132                 cy.contains('Read');
133             });
134         // Test re-hide
135         cy.get('[data-cy=group-details-members-tab]').click();
136         cy.get('[data-cy=group-members-data-explorer]')
137             .contains('Other User')
138             .parents('tr')
139             .within(() => {
140                 cy.get('[data-cy=user-hidden-checkbox]').click();
141             });
142         // Check that other user is hidden
143         cy.get('[data-cy=group-details-permissions-tab]').click();
144         cy.get('[data-cy=group-permissions-data-explorer]')
145             .should('not.contain', 'Other User')
146     });
147
148     it('displays resources shared with the group', function() {
149         // Switch to activeUser
150         cy.loginAs(activeUser);
151         cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
152
153         // Get groupUuid and create shared project
154         cy.get('[data-cy=groups-panel-data-explorer]')
155             .contains(groupName)
156             .parents('tr')
157             .find('[data-cy=uuid]')
158             .invoke('text')
159             .as('groupUuid')
160             .then((groupUuid) => {
161                 cy.createProject({
162                     owningUser: activeUser,
163                     projectName: 'test-project',
164                 }).as('testProject').then((testProject) => {
165                     cy.shareWith(activeUser.token, groupUuid, testProject.uuid, 'can_read');
166                 });
167             });
168
169         // Check that the project is listed in permissions
170         cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
171         cy.get('[data-cy=group-details-permissions-tab]').click();
172         cy.get('[data-cy=group-permissions-data-explorer]')
173             .contains('test-project');
174     });
175
176     it('removes users from the group', function() {
177         cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
178         cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
179
180         // Remove other user
181         cy.get('[data-cy=group-members-data-explorer]')
182             .contains('Other User')
183             .parents('tr')
184             .within(() => {
185                 cy.get('[data-cy=resource-delete-button]').click();
186             });
187         cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
188         cy.get('[data-cy=group-members-data-explorer]')
189             .should('not.contain', 'Other User');
190     });
191
192     it('renames the group', function() {
193         // Navigate to Groups
194         cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
195
196         // Open rename dialog
197         cy.get('[data-cy=groups-panel-data-explorer]')
198             .contains(groupName)
199             .rightclick();
200         cy.get('[data-cy=context-menu]')
201             .contains('Rename')
202             .click();
203
204         // Rename the group
205         cy.get('[data-cy=form-dialog]')
206             .should('contain', 'Edit Project')
207             .within(() => {
208                 cy.get('input[name=name]').clear().type(groupName + ' (renamed)');
209                 cy.get('button[type=submit]').click();
210             });
211
212         // Check that the group was renamed
213         cy.get('[data-cy=groups-panel-data-explorer]')
214             .contains(groupName + ' (renamed)');
215     });
216
217     it('deletes the group', function() {
218         // Navigate to Groups
219         cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
220
221         // Delete the group
222         cy.get('[data-cy=groups-panel-data-explorer]')
223             .contains(groupName + ' (renamed)')
224             .rightclick();
225         cy.get('[data-cy=context-menu]')
226             .contains('Remove')
227             .click();
228         cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
229
230         // Check that the group was deleted
231         cy.get('[data-cy=groups-panel-data-explorer]')
232             .should('not.contain', groupName + ' (renamed)');
233     });
234
235 });