|
| 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 | +}) |
0 commit comments