1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 describe('User profile tests', function() {
8 const roleGroupName = `Test role group (${Math.floor(999999 * Math.random())})`;
9 const projectGroupName = `Test project group (${Math.floor(999999 * Math.random())})`;
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;
21 cy.getUser('user', 'Active', 'User', false, true)
22 .as('activeUser').then(function() {
23 activeUser = this.activeUser;
28 function assertProfileValues({
38 cy.get('[data-cy=profile-form] [data-cy=firstName] [data-cy=value]').contains(firstName);
39 cy.get('[data-cy=profile-form] [data-cy=lastName] [data-cy=value]').contains(lastName);
40 cy.get('[data-cy=profile-form] [data-cy=email] [data-cy=value]').contains(email);
41 cy.get('[data-cy=profile-form] [data-cy=username] [data-cy=value]').contains(username);
43 cy.get('[data-cy=profile-form] input[name="prefs.profile.organization"]').invoke('val').should('equal', org);
44 cy.get('[data-cy=profile-form] input[name="prefs.profile.organization_email"]').invoke('val').should('equal', org_email);
45 cy.get('[data-cy=profile-form] select[name="prefs.profile.role"]').invoke('val').should('equal', role);
46 cy.get('[data-cy=profile-form] input[name="prefs.profile.website_url"]').invoke('val').should('equal', website);
49 function enterProfileValues({
55 cy.get('[data-cy=profile-form] input[name="prefs.profile.organization"]').clear();
57 cy.get('[data-cy=profile-form] input[name="prefs.profile.organization"]').type(org);
59 cy.get('[data-cy=profile-form] input[name="prefs.profile.organization_email"]').clear();
61 cy.get('[data-cy=profile-form] input[name="prefs.profile.organization_email"]').type(org_email);
63 cy.get('[data-cy=profile-form] select[name="prefs.profile.role"]').select(role);
64 cy.get('[data-cy=profile-form] input[name="prefs.profile.website_url"]').clear();
66 cy.get('[data-cy=profile-form] input[name="prefs.profile.website_url"]').type(website);
70 beforeEach(function() {
71 cy.loginAs(adminUser);
72 cy.goToPath('/my-account');
79 cy.get('[data-cy=profile-form] button[type="submit"]').click({force: true});
81 cy.goToPath('/user/' + activeUser.user.uuid);
88 cy.get('[data-cy=profile-form] button[type="submit"]').click({force: true});
91 it('non-admin can edit own profile', function() {
92 cy.loginAs(activeUser);
94 cy.get('header button[title="Account Management"]').click();
95 cy.get('#account-menu').contains('My account').click();
97 // Admin tab should be hidden
98 cy.get('div [role="tab"]').should('not.contain', 'ADMIN');
100 // Check initial values
101 assertProfileValues({
104 email: 'user@example.local',
115 org_email: 'email@example.com',
116 role: 'Data Scientist',
117 website: 'example.com',
121 cy.get('[data-cy=profile-form] button[type="submit"]').click();
124 assertProfileValues({
127 email: 'user@example.local',
130 org_email: 'email@example.com',
131 role: 'Data Scientist',
132 website: 'example.com',
136 it('non-admin cannot edit other profile', function() {
137 cy.loginAs(activeUser);
138 cy.goToPath('/user/' + adminUser.user.uuid);
140 assertProfileValues({
143 email: 'admin@example.local',
151 // Inputs should be disabled
152 cy.get('[data-cy=profile-form] input[name="prefs.profile.organization"]').should('be.disabled');
153 cy.get('[data-cy=profile-form] input[name="prefs.profile.organization_email"]').should('be.disabled');
154 cy.get('[data-cy=profile-form] select[name="prefs.profile.role"]').should('be.disabled');
155 cy.get('[data-cy=profile-form] input[name="prefs.profile.website_url"]').should('be.disabled');
157 // Submit should be disabled
158 cy.get('[data-cy=profile-form] button[type="submit"]').should('be.disabled');
160 // Admin tab should be hidden
161 cy.get('div [role="tab"]').should('not.contain', 'ADMIN');
164 it('admin can edit own profile', function() {
165 cy.loginAs(adminUser);
167 cy.get('header button[title="Account Management"]').click();
168 cy.get('#account-menu').contains('My account').click();
170 // Admin tab should be visible
171 cy.get('div [role="tab"]').should('contain', 'ADMIN');
173 // Check initial values
174 assertProfileValues({
177 email: 'admin@example.local',
187 org: 'Admin org name',
188 org_email: 'admin@example.com',
190 website: 'admin.local',
192 cy.get('[data-cy=profile-form] button[type="submit"]').click();
195 assertProfileValues({
198 email: 'admin@example.local',
200 org: 'Admin org name',
201 org_email: 'admin@example.com',
203 website: 'admin.local',
207 it('admin can edit other profile', function() {
208 cy.loginAs(adminUser);
209 cy.goToPath('/user/' + activeUser.user.uuid);
212 assertProfileValues({
215 email: 'user@example.local',
224 org: 'Changed org name',
225 org_email: 'changed@example.com',
227 website: 'changed.local',
229 cy.get('[data-cy=profile-form] button[type="submit"]').click();
232 assertProfileValues({
235 email: 'user@example.local',
237 org: 'Changed org name',
238 org_email: 'changed@example.com',
240 website: 'changed.local',
244 it('displays role groups on user profile', function() {
245 cy.loginAs(adminUser);
247 cy.createGroup(adminUser.token, {
250 }).as('roleGroup').then(function() {
251 cy.createLink(adminUser.token, {
253 link_class: 'permission',
254 head_uuid: this.roleGroup.uuid,
255 tail_uuid: adminUser.user.uuid
257 cy.createLink(adminUser.token, {
259 link_class: 'permission',
260 head_uuid: this.roleGroup.uuid,
261 tail_uuid: activeUser.user.uuid
265 cy.createGroup(adminUser.token, {
266 name: projectGroupName,
267 group_class: 'project',
268 }).as('projectGroup').then(function() {
269 cy.createLink(adminUser.token, {
271 link_class: 'permission',
272 head_uuid: this.projectGroup.uuid,
273 tail_uuid: adminUser.user.uuid
275 cy.createLink(adminUser.token, {
277 link_class: 'permission',
278 head_uuid: this.projectGroup.uuid,
279 tail_uuid: activeUser.user.uuid
283 cy.goToPath('/user/' + activeUser.user.uuid);
284 cy.get('div [role="tab"]').contains('GROUPS').click();
285 cy.get('[data-cy=user-profile-groups-data-explorer]').contains(roleGroupName);
286 cy.get('[data-cy=user-profile-groups-data-explorer]').should('not.contain', projectGroupName);
288 cy.goToPath('/user/' + adminUser.user.uuid);
289 cy.get('div [role="tab"]').contains('GROUPS').click();
290 cy.get('[data-cy=user-profile-groups-data-explorer]').contains(roleGroupName);
291 cy.get('[data-cy=user-profile-groups-data-explorer]').should('not.contain', projectGroupName);