18123: Add basic group edit cypress tests.
[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
10     before(function() {
11         // Only set up common users once. These aren't set up as aliases because
12         // aliases are cleaned up after every test. Also it doesn't make sense
13         // to set the same users on beforeEach() over and over again, so we
14         // separate a little from Cypress' 'Best Practices' here.
15         cy.getUser('admin', 'Admin', 'User', true, true)
16             .as('adminUser').then(function() {
17                 adminUser = this.adminUser;
18             }
19         );
20         cy.getUser('user', 'Active', 'User', false, true)
21             .as('activeUser').then(function() {
22                 activeUser = this.activeUser;
23             }
24         );
25         cy.getUser('otheruser', 'Other', 'User', false, true)
26             .as('otherUser').then(function() {
27                 otherUser = this.otherUser;
28             }
29         );
30     });
31
32     beforeEach(function() {
33         cy.clearCookies();
34         cy.clearLocalStorage();
35     });
36
37     it('creates a new group', function() {
38         const groupName = `Test group (${Math.floor(999999 * Math.random())})`;
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=form-dialog]')
97             .should('contain', 'Edit permission')
98             .within(() => {
99                 cy.contains('Read').click();
100             });
101         cy.get('li span')
102             .contains('Write')
103             .parents('li')
104             .click();
105         cy.get('[data-cy=form-dialog] button[type=submit]').click();
106         cy.get('[data-cy=group-members-data-explorer]')
107             .contains('Other User')
108             .parents('tr')
109             .within(() => {
110                 cy.contains('Write');
111             });
112     });
113
114     it('removes users from the group', function() {
115         // Remove other user
116         cy.get('[data-cy=group-members-data-explorer]')
117             .contains('Other User')
118             .parents('tr')
119             .within(() => {
120                 cy.get('[data-cy=resource-delete-button]').click();
121             });
122         cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
123         cy.get('[data-cy=group-members-data-explorer]')
124             .should('not.contain', 'Other User');
125
126     });
127 });