diff options
author | Ferdinand Thiessen <opensource@fthiessen.de> | 2024-08-29 00:42:01 +0200 |
---|---|---|
committer | Ferdinand Thiessen <opensource@fthiessen.de> | 2024-08-29 00:42:01 +0200 |
commit | ffba646d93103ed6397ec25c690b298a09b48756 (patch) | |
tree | f5ff4fc6fca15b7ce1353b0a626f487c4f55118f | |
parent | 8c4600ada2a9ebf06457e5c9f2c8391af61e5f44 (diff) | |
download | nextcloud-server-feat/allow-account-local-search.tar.gz nextcloud-server-feat/allow-account-local-search.zip |
test: Add end-to-end test for account management filteringfeat/allow-account-local-search
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
-rw-r--r-- | cypress/e2e/settings/usersUtils.ts | 8 | ||||
-rw-r--r-- | cypress/e2e/settings/users_filter.cy.ts | 137 | ||||
-rw-r--r-- | cypress/support/commands.ts | 15 |
3 files changed, 160 insertions, 0 deletions
diff --git a/cypress/e2e/settings/usersUtils.ts b/cypress/e2e/settings/usersUtils.ts index 7d8ea55d35b..0afdd64f3d3 100644 --- a/cypress/e2e/settings/usersUtils.ts +++ b/cypress/e2e/settings/usersUtils.ts @@ -27,6 +27,14 @@ export function getUserList() { } /** + * Get the group list + */ +export function getGroupList(): Cypress.Chainable<JQuery> { + return cy.findByRole('navigation', { name: 'Account management' }) + .findByRole('list', { name: 'Groups' }) +} + +/** * Get the row entry for given userId within the settings users list * * @param userId the user to query diff --git a/cypress/e2e/settings/users_filter.cy.ts b/cypress/e2e/settings/users_filter.cy.ts new file mode 100644 index 00000000000..fde7a0d2375 --- /dev/null +++ b/cypress/e2e/settings/users_filter.cy.ts @@ -0,0 +1,137 @@ +/** + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +import { User } from '@nextcloud/cypress' +import { getGroupList, getUserList, getUserListRow } from './usersUtils' + +const admin = new User('admin', 'admin') + +describe('Settings: Filter in account management', { testIsolation: true }, () => { + + // create state once + before(() => { + cy.restoreDB() + + cy.removeUserData(['jane', 'louis']) + cy.createUser({ language: 'en_US', password: '1234', userId: 'jane' }) + cy.createUser({ language: 'en_US', password: '1234', userId: 'louis' }) + cy.runOccCommand('group:add engineering') + cy.runOccCommand('group:add sales') + }) + + // only reload the page on every test + beforeEach(() => { + cy.login(admin) + cy.visit('/settings/users') + }) + + it('Can see all groups', () => { + getGroupList() + .findAllByRole('listitem') + .should((elements) => { + expect(elements).to.have.length(2) + const entries = elements.get().map((element) => element.textContent?.trim()) + expect(entries).to.have.members(['sales', 'engineering']) + }) + }) + + it('Can filter group list', () => { + // See all groups + getGroupList().findAllByRole('listitem').should('have.length', 2) + + // Add a filter + cy.findByRole('navigation', { name: 'Account management' }) + .findByRole('searchbox') + .type('engine') + + // See only filtered group + getGroupList() + .findAllByRole('listitem') + .should('have.length', 1) + .and('contain', 'engineering') + }) + + it('Shows message if no group matches the query', () => { + // See all groups + getGroupList().findAllByRole('listitem').should('have.length', 2) + + // Add a filter + cy.findByRole('navigation', { name: 'Account management' }) + .findByRole('searchbox') + .type('testing') + + // See that no group is found + getGroupList() + .findAllByRole('listitem') + .should('have.length', 1) + .and('contain', 'No groups matching') + }) + + it('Can filter the account list', () => { + // See all accounts + getUserList() + .find('[data-cy-user-row]') + .should('have.length.gte', 3) + + // Add a filter + cy.findByRole('navigation', { name: 'Account management' }) + .findByRole('searchbox') + .type('jan') + + // see that only one account matches + getUserList() + .find('[data-cy-user-row]') + .should('have.length', 1) + getUserListRow('jane') + .should('exist') + }) + + it('Show message if no account matches', () => { + // See all accounts + getUserList() + .find('[data-cy-user-row]') + .should('have.length.gte', 3) + + // Add a filter + cy.findByRole('navigation', { name: 'Account management' }) + .findByRole('searchbox') + .type('testing') + + // see that no list is shown + getUserList().should('not.exist') + cy.get('main').should('contain.text', 'No accounts') + }) + + it('Reset query on navigation', () => { + // See all accounts + getUserList() + .find('[data-cy-user-row]') + .should('have.length.gte', 3) + + // Add a filter + cy.findByRole('navigation', { name: 'Account management' }) + .findByRole('searchbox') + .type('testing') + + // see that no list is shown + getUserList().should('not.exist') + + // navigate to admins group + cy.findByRole('navigation', { name: 'Account management' }) + .findByRole('link', { name: /Admins/ }) + .click() + + // see the query is reset + cy.findByRole('navigation', { name: 'Account management' }) + .findByRole('searchbox') + .should('have.value', '') + + // the the list is visible again + getUserList() + .should('be.visible') + .find('[data-cy-user-row]') + .should('have.length.gte', 1) + }) +}) diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index 1574a03705f..0cc57c90585 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -76,6 +76,12 @@ declare global { * Default is the post-setup state */ restoreDB(snapshot?: string): Cypress.Chainable, + + /** + * Remove the user data directory for listed users + * @param user user ids + */ + removeUserData(user: string[]): Cypress.Chainable, } } } @@ -288,6 +294,15 @@ Cypress.Commands.add('runOccCommand', (command: string, options?: Partial<Cypres return cy.exec(`docker exec --user www-data ${env} nextcloud-cypress-tests-server php ./occ ${command}`, options) }) +Cypress.Commands.add('removeUserData', (users: string[]) => { + if (users.some((user) => user.includes('/') || user.startsWith('.'))) { + throw new Error('user id contains invalid character') + } + users = users.map((user) => `"data/${user}"`) + + return cy.exec(`docker exec --user www-data nextcloud-cypress-tests-server rm -fr ${users.join(' ')}`) +}) + Cypress.Commands.add('backupDB', (): Cypress.Chainable<string> => { const randomString = Math.random().toString(36).substring(7) cy.exec(`docker exec --user www-data nextcloud-cypress-tests-server cp /var/www/html/data/owncloud.db /var/www/html/data/owncloud.db-${randomString}`) |