Skip to content

Commit 3e0368e

Browse files
committed
test(settings): Test user manager can be set and unset
Signed-off-by: nfebe <fenn25.fn@gmail.com>
1 parent 1301cf5 commit 3e0368e

File tree

2 files changed

+121
-41
lines changed

2 files changed

+121
-41
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import { User } from '@nextcloud/cypress'
7+
import { getUserListRow, handlePasswordConfirmation, toggleEditButton, waitLoading } from './usersUtils'
8+
import { clearState } from '../../support/commonUtils'
9+
10+
const admin = new User('admin', 'admin')
11+
12+
describe('Settings: User Manager Management', function() {
13+
let user: User
14+
let manager: User
15+
16+
beforeEach(function() {
17+
clearState()
18+
cy.createRandomUser().then(($user) => {
19+
manager = $user
20+
return cy.createRandomUser()
21+
}).then(($user) => {
22+
user = $user
23+
cy.login(admin)
24+
cy.intercept('PUT', `/ocs/v2.php/cloud/users/${user.userId}*`).as('updateUser')
25+
})
26+
})
27+
28+
it('Can assign and remove a manager through the UI', function() {
29+
cy.visit('/settings/users')
30+
31+
toggleEditButton(user, true)
32+
33+
// Scroll to manager cell and wait for it to be visible
34+
getUserListRow(user.userId)
35+
.find('[data-cy-user-list-cell-manager]')
36+
.scrollIntoView()
37+
.should('be.visible')
38+
39+
// Assign a manager
40+
getUserListRow(user.userId).find('[data-cy-user-list-cell-manager]').within(() => {
41+
// Verify no manager is set initially
42+
cy.get('.vs__selected').should('not.exist')
43+
44+
// Open the dropdown menu
45+
cy.get('[role="combobox"]').click({ force: true })
46+
47+
// Wait for the dropdown to be visible and initialized
48+
waitLoading('[data-cy-user-list-input-manager]')
49+
50+
// Type the manager's username to search
51+
cy.get('input[type="search"]').type(manager.userId, { force: true })
52+
53+
// Wait for the search results to load
54+
waitLoading('[data-cy-user-list-input-manager]')
55+
})
56+
57+
// Now select the manager from the filtered results
58+
// Since the dropdown is floating, we need to search globally
59+
cy.get('.vs__dropdown-menu').find('li').contains('span', manager.userId).should('be.visible').click({ force: true })
60+
61+
// Handle password confirmation if needed
62+
handlePasswordConfirmation(admin.password)
63+
64+
// Verify the manager is selected in the UI
65+
cy.get('.vs__selected').should('exist').and('contain.text', manager.userId)
66+
67+
// Verify the PUT request was made to set the manager
68+
cy.wait('@updateUser').then((interception) => {
69+
// Verify the request URL and body
70+
expect(interception.request.url).to.match(/\/cloud\/users\/.+/)
71+
expect(interception.request.body).to.deep.equal({
72+
key: 'manager',
73+
value: manager.userId
74+
})
75+
expect(interception.response?.statusCode).to.equal(200)
76+
})
77+
78+
// Wait for the save to complete
79+
waitLoading('[data-cy-user-list-input-manager]')
80+
81+
// Verify the manager is set in the backend
82+
cy.getUserData(user).then(($result) => {
83+
expect($result.body).to.contain(`<manager>${manager.userId}</manager>`)
84+
})
85+
86+
// Now remove the manager
87+
getUserListRow(user.userId).find('[data-cy-user-list-cell-manager]').within(() => {
88+
// Clear the manager selection
89+
cy.get('.vs__clear').click({ force: true })
90+
91+
// Verify the manager is cleared in the UI
92+
cy.get('.vs__selected').should('not.exist')
93+
94+
// Handle password confirmation if needed
95+
handlePasswordConfirmation(admin.password)
96+
})
97+
98+
// Verify the PUT request was made to clear the manager
99+
cy.wait('@updateUser').then((interception) => {
100+
// Verify the request URL and body
101+
expect(interception.request.url).to.match(/\/cloud\/users\/.+/)
102+
expect(interception.request.body).to.deep.equal({
103+
key: 'manager',
104+
value: '',
105+
})
106+
expect(interception.response?.statusCode).to.equal(200)
107+
})
108+
109+
// Wait for the save to complete
110+
waitLoading('[data-cy-user-list-input-manager]')
111+
112+
// Verify the manager is cleared in the backend
113+
cy.getUserData(user).then(($result) => {
114+
expect($result.body).to.not.contain(`<manager>${manager.userId}</manager>`)
115+
expect($result.body).to.contain('<manager></manager>')
116+
})
117+
118+
// Finish editing the user
119+
toggleEditButton(user, false)
120+
})
121+
})

cypress/e2e/settings/users_modify.cy.ts

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -181,47 +181,6 @@ describe('Settings: Change user properties', function() {
181181
})
182182
})
183183

184-
it('Can set manager of a user', function() {
185-
// create the manager
186-
let manager: User
187-
cy.createRandomUser().then(($user) => { manager = $user })
188-
189-
// open the User settings as admin
190-
cy.login(admin)
191-
cy.visit('/settings/users')
192-
193-
// toggle edit button into edit mode
194-
toggleEditButton(user, true)
195-
196-
getUserListRow(user.userId)
197-
.find('[data-cy-user-list-cell-manager]')
198-
.scrollIntoView()
199-
200-
getUserListRow(user.userId).find('[data-cy-user-list-cell-manager]').within(() => {
201-
// see that the user has no manager
202-
cy.get('.vs__selected').should('not.exist')
203-
// Open the dropdown menu
204-
cy.get('[role="combobox"]').click({ force: true })
205-
// select the manager
206-
cy.contains('li', manager.userId).click({ force: true })
207-
208-
// Handle password confirmation on time out
209-
handlePasswordConfirmation(admin.password)
210-
211-
// see that the user has a manager set
212-
cy.get('.vs__selected').should('exist').and('contain.text', manager.userId)
213-
})
214-
215-
// see that the changes are loading
216-
waitLoading('[data-cy-user-list-input-manager]')
217-
218-
// finish editing the user
219-
toggleEditButton(user, false)
220-
221-
// validate the manager is set
222-
cy.getUserData(user).then(($result) => expect($result.body).to.contain(`<manager>${manager.userId}</manager>`))
223-
})
224-
225184
it('Can make user a subadmin of a group', function() {
226185
// create a group
227186
const groupName = 'userstestgroup'

0 commit comments

Comments
 (0)