18123: Add tests for hide group member and rename/delete group.
[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('unhides 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('removes users from the group', function() {
149         cy.loginAs(activeUser);
150         cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
151         cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
152
153         // Remove other user
154         cy.get('[data-cy=group-members-data-explorer]')
155             .contains('Other User')
156             .parents('tr')
157             .within(() => {
158                 cy.get('[data-cy=resource-delete-button]').click();
159             });
160         cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
161         cy.get('[data-cy=group-members-data-explorer]')
162             .should('not.contain', 'Other User');
163     });
164
165     it('renames the group', function() {
166         // Navigate to Groups
167         cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
168
169         // Open rename dialog
170         cy.get('[data-cy=groups-panel-data-explorer]')
171             .contains(groupName)
172             .rightclick();
173         cy.get('[data-cy=context-menu]')
174             .contains('Rename')
175             .click();
176
177         // Rename the group
178         cy.get('[data-cy=form-dialog]')
179             .should('contain', 'Edit Project')
180             .within(() => {
181                 cy.get('input[name=name]').clear().type(groupName + ' (renamed)');
182                 cy.get('button[type=submit]').click();
183             });
184
185         // Check that the group was renamed
186         cy.get('[data-cy=groups-panel-data-explorer]')
187             .contains(groupName + ' (renamed)');
188     });
189
190     it('deletes the group', function() {
191         // Navigate to Groups
192         cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
193
194         // Delete the group
195         cy.get('[data-cy=groups-panel-data-explorer]')
196             .contains(groupName + ' (renamed)')
197             .rightclick();
198         cy.get('[data-cy=context-menu]')
199             .contains('Remove')
200             .click();
201         cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
202
203         // Check that the group was deleted
204         cy.get('[data-cy=groups-panel-data-explorer]')
205             .should('not.contain', groupName + ' (renamed)');
206     });
207
208 });