|
| 1 | +/** |
| 2 | + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors |
| 3 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | + */ |
| 5 | +/// <reference types="cypress-if" /> |
| 6 | + |
| 7 | +import { User } from '@nextcloud/e2e-test-server/cypress' |
| 8 | +import { clearState } from '../../support/commonUtils.ts' |
| 9 | +import { randomString } from '../../support/utils/randomString.ts' |
| 10 | +import { getUserList, getUserListRow } from './usersUtils.ts' |
| 11 | + |
| 12 | +const admin = new User('admin', 'admin') |
| 13 | + |
| 14 | +/** Scope role queries to the account management sidebar so they don't match |
| 15 | + * unrelated elements (e.g. the global unified search bar at the top of the page). |
| 16 | + */ |
| 17 | +function accountNav() { |
| 18 | + return cy.findByRole('navigation', { name: /account management/i }) |
| 19 | +} |
| 20 | + |
| 21 | +function waitForSearchRequest(alias: string, expectedSearch: string) { |
| 22 | + return cy.wait(alias).then(({ request }) => { |
| 23 | + expect(new URL(request.url).searchParams.get('search')).to.equal(expectedSearch) |
| 24 | + }) |
| 25 | +} |
| 26 | + |
| 27 | +describe('Settings: Unified search for accounts and groups', { testIsolation: false }, () => { |
| 28 | + // Use a stable, searchable prefix in the group name so we can match |
| 29 | + // it independently from the random user id below. |
| 30 | + const matchingGroup = `zzz-match-${randomString(5)}` |
| 31 | + const otherGroup = `aaa-other-${randomString(5)}` |
| 32 | + let alice: User |
| 33 | + let bob: User |
| 34 | + |
| 35 | + after(() => { |
| 36 | + cy.deleteUser(alice) |
| 37 | + cy.deleteUser(bob) |
| 38 | + cy.runOccCommand(`group:delete '${matchingGroup}'`, { failOnNonZeroExit: false }) |
| 39 | + cy.runOccCommand(`group:delete '${otherGroup}'`, { failOnNonZeroExit: false }) |
| 40 | + }) |
| 41 | + |
| 42 | + before(() => { |
| 43 | + clearState() |
| 44 | + |
| 45 | + cy.createRandomUser().then((user) => { |
| 46 | + alice = user |
| 47 | + }) |
| 48 | + cy.createRandomUser().then((user) => { |
| 49 | + bob = user |
| 50 | + }) |
| 51 | + |
| 52 | + cy.runOccCommand(`group:add '${matchingGroup}'`) |
| 53 | + cy.runOccCommand(`group:add '${otherGroup}'`) |
| 54 | + |
| 55 | + cy.login(admin) |
| 56 | + cy.intercept('GET', '**/ocs/v2.php/cloud/groups/details?search=*').as('initialLoadGroups') |
| 57 | + cy.intercept('GET', '**/ocs/v2.php/cloud/users/details?*').as('initialLoadUsers') |
| 58 | + cy.visit('/settings/users') |
| 59 | + cy.wait('@initialLoadGroups') |
| 60 | + cy.wait('@initialLoadUsers') |
| 61 | + }) |
| 62 | + |
| 63 | + beforeEach(() => { |
| 64 | + // Intercept aliases reset between tests even with testIsolation: false, |
| 65 | + // so re-register them here to capture requests triggered inside each test. |
| 66 | + cy.intercept('GET', '**/ocs/v2.php/cloud/groups/details?search=*').as('loadGroups') |
| 67 | + cy.intercept('GET', '**/ocs/v2.php/cloud/users/details?*').as('loadUsers') |
| 68 | + }) |
| 69 | + |
| 70 | + it('shows the search input in the navigation sidebar', () => { |
| 71 | + accountNav().findByRole('textbox', { name: /search accounts and groups/i }) |
| 72 | + .should('be.visible') |
| 73 | + .and('have.value', '') |
| 74 | + }) |
| 75 | + |
| 76 | + it('dispatches the query to both the users and groups API', () => { |
| 77 | + accountNav().findByRole('textbox', { name: /search accounts and groups/i }) |
| 78 | + .type(alice.userId) |
| 79 | + |
| 80 | + // A single keystroke sequence debounces once (300ms), then fans out |
| 81 | + // to both APIs — both requests must carry the same search term. |
| 82 | + cy.wait('@loadUsers').its('request.url').should('include', `search=${alice.userId}`) |
| 83 | + cy.wait('@loadGroups').its('request.url').should('include', `search=${alice.userId}`) |
| 84 | + |
| 85 | + // The user list reflects what the backend returned for this query. |
| 86 | + getUserListRow(alice.userId).should('exist') |
| 87 | + getUserList().should('not.contain', bob.userId) |
| 88 | + }) |
| 89 | + |
| 90 | + it('filters the group list when the query matches a group name', () => { |
| 91 | + accountNav().findByRole('textbox', { name: /search accounts and groups/i }) |
| 92 | + .clear() |
| 93 | + .type(matchingGroup) |
| 94 | + |
| 95 | + cy.wait('@loadGroups').its('request.url').should('include', `search=${matchingGroup}`) |
| 96 | + |
| 97 | + cy.get('ul[data-cy-users-settings-navigation-groups="custom"]') |
| 98 | + .should('contain', matchingGroup) |
| 99 | + .and('not.contain', otherGroup) |
| 100 | + }) |
| 101 | + |
| 102 | + it('resets both lists when the clear button is clicked', () => { |
| 103 | + accountNav().findByRole('button', { name: /clear search/i }).click() |
| 104 | + |
| 105 | + accountNav().findByRole('textbox', { name: /search accounts and groups/i }) |
| 106 | + .should('have.value', '') |
| 107 | + |
| 108 | + waitForSearchRequest('@loadUsers', '') |
| 109 | + waitForSearchRequest('@loadGroups', '') |
| 110 | + |
| 111 | + getUserListRow(alice.userId).should('exist') |
| 112 | + getUserListRow(bob.userId).should('exist') |
| 113 | + cy.get('ul[data-cy-users-settings-navigation-groups="custom"]') |
| 114 | + .should('contain', matchingGroup) |
| 115 | + .and('contain', otherGroup) |
| 116 | + }) |
| 117 | +}) |
0 commit comments