nextcloud/cypress/e2e/settings/usersUtils.ts
Ferdinand Thiessen 2e0b001a41 refactor(appstore): adjust frontend for new API location
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
2026-05-05 10:41:04 +02:00

76 lines
2.4 KiB
TypeScript

/**
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import type { User } from '@nextcloud/e2e-test-server/cypress'
/**
* Assert that `element` does not exist or is not visible
* Useful in cases such as when NcModal is opened/closed rapidly
*
* @param element Element that is inspected
*/
export function assertNotExistOrNotVisible(element: JQuery<HTMLElement>) {
const doesNotExist = element.length === 0
const isNotVisible = !element.is(':visible')
expect(doesNotExist || isNotVisible, 'does not exist or is not visible').to.be.true
}
/**
* Get the settings users list
*
* @return Cypress chainable object
*/
export function getUserList() {
return cy.get('[data-cy-user-list]')
}
/**
* Get the row entry for given userId within the settings users list
*
* @param userId the user to query
* @return Cypress chainable object
*/
export function getUserListRow(userId: string) {
return getUserList().find(`[data-cy-user-row="${userId}"]`)
}
/**
*
* @param selector
*/
export function waitLoading(selector: string) {
// We need to make sure the element is loading, otherwise the "done loading" will succeed even if we did not start loading.
// But Cypress might also be simply too slow to catch the loading phase. Thats why we need to wait in this case.
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.get(`${selector}[data-loading]`).if().should('exist').else().wait(1000)
// https://github.com/NoriSte/cypress-wait-until/issues/75#issuecomment-572685623
cy.waitUntil(() => Cypress.$(selector).length > 0 && !Cypress.$(selector).attr('data-loading')?.length, { timeout: 10000 })
}
/**
* Open the edit dialog for a user by clicking the Edit action on their row
*
* @param user The user whose edit dialog to open
*/
export function openEditDialog(user: User) {
getUserListRow(user.userId).should('exist')
.find('[data-cy-user-list-action-edit]')
.click({ force: true })
// Wait for the dialog to appear
cy.get('.edit-dialog [data-test="form"]').should('be.visible')
}
/**
* Save the currently open edit dialog by clicking the Save button
* and wait for the dialog to close
*/
export function saveEditDialog() {
cy.get('[data-test="submit"]').click()
// Wait for dialog to close
cy.get('.edit-dialog').should('not.exist')
}
export { handlePasswordConfirmation } from '../core-utils.ts'