aboutsummaryrefslogtreecommitdiffstats
path: root/cypress/e2e
diff options
context:
space:
mode:
authorFerdinand Thiessen <opensource@fthiessen.de>2023-10-18 15:02:32 +0200
committerFerdinand Thiessen <opensource@fthiessen.de>2023-10-19 16:17:19 +0200
commitadd1d922baf94dd8bfa2e9a4cb1e26d30f42b1e4 (patch)
tree21502415d3d2e541595b3bc961364b1e8308ba19 /cypress/e2e
parentb6c35b3be0a2c2a26e6409990a3855c36fa06ce9 (diff)
downloadnextcloud-server-add1d922baf94dd8bfa2e9a4cb1e26d30f42b1e4.tar.gz
nextcloud-server-add1d922baf94dd8bfa2e9a4cb1e26d30f42b1e4.zip
fix(cypress): Replace flaky password-confirmation hack with conditional testing for the password modal
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Diffstat (limited to 'cypress/e2e')
-rw-r--r--cypress/e2e/settings/users.cy.ts44
-rw-r--r--cypress/e2e/settings/usersUtils.ts24
-rw-r--r--cypress/e2e/settings/users_groups.cy.ts32
-rw-r--r--cypress/e2e/settings/users_modify.cy.ts24
4 files changed, 42 insertions, 82 deletions
diff --git a/cypress/e2e/settings/users.cy.ts b/cypress/e2e/settings/users.cy.ts
index 1f29ee1db41..faa69892e8c 100644
--- a/cypress/e2e/settings/users.cy.ts
+++ b/cypress/e2e/settings/users.cy.ts
@@ -19,7 +19,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
-
+/// <reference types="cypress-if" />
import { User } from '@nextcloud/cypress'
const admin = new User('admin', 'admin')
@@ -37,7 +37,7 @@ describe('Settings: Create and delete users', function() {
cy.login(admin)
cy.listUsers().then((users) => {
cy.login(admin)
- if (users.includes('john')) {
+ if ((users as string[]).includes('john')) {
// ensure created user is deleted
cy.deleteUser(john).login(admin)
// ensure deleted user is not present
@@ -67,18 +67,8 @@ describe('Settings: Create and delete users', function() {
cy.get('button[type="submit"]').click()
})
- // Ignore failure if modal is not shown
- cy.once('fail', (error) => {
- expect(error.name).to.equal('AssertionError')
- expect(error).to.have.property('node', '.modal-container')
- })
- // Make sure no confirmation modal is shown on top of the New user modal
- cy.get('body').find('.modal-container').then(($modals) => {
- if ($modals.length > 1) {
- cy.wrap($modals.first()).find('input[type="password"]').type(admin.password)
- cy.wrap($modals.first()).find('button').contains('Confirm').click()
- }
- })
+ // Make sure no confirmation modal is shown
+ handlePasswordConfirmation(admin.password)
// see that the created user is in the list
cy.get('tbody.user-list__body tr[data-test="john"]').within(() => {
@@ -112,18 +102,8 @@ describe('Settings: Create and delete users', function() {
cy.get('button[type="submit"]').click()
})
- // Ignore failure if modal is not shown
- cy.once('fail', (error) => {
- expect(error.name).to.equal('AssertionError')
- expect(error).to.have.property('node', '.modal-container')
- })
- // Make sure no confirmation modal is shown on top of the New user modal
- cy.get('body').find('.modal-container').then(($modals) => {
- if ($modals.length > 1) {
- cy.wrap($modals.first()).find('input[type="password"]').type(admin.password)
- cy.wrap($modals.first()).find('button').contains('Confirm').click()
- }
- })
+ // Make sure no confirmation modal is shown
+ handlePasswordConfirmation(admin.password)
// see that the created user is in the list
cy.get('tbody.user-list__body tr[data-test="john"]').within(() => {
@@ -151,18 +131,8 @@ describe('Settings: Create and delete users', function() {
// And confirmation dialog accepted
cy.get('.oc-dialog button').contains(`Delete ${jdoe.userId}`).click()
- // Ignore failure if modal is not shown
- cy.once('fail', (error) => {
- expect(error.name).to.equal('AssertionError')
- expect(error).to.have.property('node', '.modal-container')
- })
// Make sure no confirmation modal is shown
- cy.get('body').find('.modal-container').then(($modal) => {
- if ($modal.length > 0) {
- cy.wrap($modal).find('input[type="password"]').type(admin.password)
- cy.wrap($modal).find('button').contains('Confirm').click()
- }
- })
+ handlePasswordConfirmation(admin.password)
// deleted clicked the user is not shown anymore
cy.get(`tbody.user-list__body tr[data-test="${jdoe.userId}"]`).should('not.exist')
diff --git a/cypress/e2e/settings/usersUtils.ts b/cypress/e2e/settings/usersUtils.ts
index 60ca42db7d9..1e325fab47d 100644
--- a/cypress/e2e/settings/usersUtils.ts
+++ b/cypress/e2e/settings/usersUtils.ts
@@ -31,3 +31,27 @@ export function assertNotExistOrNotVisible(element: JQuery<HTMLElement>) {
expect(doesNotExist || isNotVisible, 'does not exist or is not visible').to.be.true
}
+
+/**
+ * Handle the confirm password dialog (if needed)
+ * @param adminPassword The admin password for the dialog
+ */
+export function handlePasswordConfirmation(adminPassword = 'admin') {
+ const handleModal = (context: Cypress.Chainable) => {
+ return context.contains('.modal-container', 'Confirm your password')
+ .if()
+ .if('visible')
+ .within(() => {
+ cy.get('input[type="password"]').type(adminPassword)
+ cy.get('button').contains('Confirm').click()
+ })
+ }
+
+ return cy.get('body')
+ .if()
+ .then(() => handleModal(cy.get('body')))
+ .else()
+ // Handle if inside a cy.within
+ .root().closest('body')
+ .then(($body) => handleModal(cy.wrap($body)))
+}
diff --git a/cypress/e2e/settings/users_groups.cy.ts b/cypress/e2e/settings/users_groups.cy.ts
index f1e698175ee..0d90722c124 100644
--- a/cypress/e2e/settings/users_groups.cy.ts
+++ b/cypress/e2e/settings/users_groups.cy.ts
@@ -21,6 +21,7 @@
*/
import { User } from '@nextcloud/cypress'
+import { handlePasswordConfirmation } from './usersUtils'
const admin = new User('admin', 'admin')
@@ -46,18 +47,8 @@ describe('Settings: Create and delete groups', () => {
cy.get('input[placeholder="Group name"] ~ button').click()
})
- // Ignore failure if modal is not shown
- cy.once('fail', (error) => {
- expect(error.name).to.equal('AssertionError')
- expect(error).to.have.property('node', '.modal-container')
- })
// Make sure no confirmation modal is shown
- cy.get('body').find('.modal-container').then(($modals) => {
- if ($modals.length > 0) {
- cy.wrap($modals.first()).find('input[type="password"]').type(admin.password)
- cy.wrap($modals.first()).find('button').contains('Confirm').click()
- }
- })
+ handlePasswordConfirmation(admin.password)
// see that the created group is in the list
cy.get('ul.app-navigation__list').within(() => {
@@ -82,18 +73,13 @@ describe('Settings: Create and delete groups', () => {
// And confirmation dialog accepted
cy.get('.modal-container button').contains('Confirm').click()
- // Ignore failure if modal is not shown
- cy.once('fail', (error) => {
- expect(error.name).to.equal('AssertionError')
- expect(error).to.have.property('node', '.modal-container')
- })
- // Make sure no confirmation modal is shown on top of the Remove group modal
- cy.get('body').find('.modal-container').then(($modals) => {
- if ($modals.length > 1) {
- cy.wrap($modals.first()).find('input[type="password"]').type(admin.password)
- cy.wrap($modals.first()).find('button').contains('Confirm').click()
- }
- })
+ // Make sure no confirmation modal is shown
+ cy.get('body').contains('.modal-container', 'Confirm your password')
+ .if('visible')
+ .then(($modal) => {
+ cy.wrap($modal).find('input[type="password"]').type(admin.password)
+ cy.wrap($modal).find('button').contains('Confirm').click()
+ })
// deleted group is not shown anymore
cy.get('ul.app-navigation__list').within(() => {
diff --git a/cypress/e2e/settings/users_modify.cy.ts b/cypress/e2e/settings/users_modify.cy.ts
index ce5b0834edc..987e21971fe 100644
--- a/cypress/e2e/settings/users_modify.cy.ts
+++ b/cypress/e2e/settings/users_modify.cy.ts
@@ -66,18 +66,8 @@ describe('Settings: Change user properties', function() {
cy.get('input[data-test="displayNameField"]').should('have.value', 'John Doe')
cy.get('input[data-test="displayNameField"] ~ button').click()
- // Ignore failure if modal is not shown
- cy.once('fail', (error) => {
- expect(error.name).to.equal('AssertionError')
- expect(error).to.have.property('node', '.modal-container')
- })
// Make sure no confirmation modal is shown
- cy.root().closest('body').find('.modal-container').then(($modal) => {
- if ($modal.length > 0) {
- cy.wrap($modal).find('input[type="password"]').type(admin.password)
- cy.wrap($modal).find('button').contains('Confirm').click()
- }
- })
+ handlePasswordConfirmation(admin.password)
// see that the display name cell is done loading
cy.get('.user-row-text-field.icon-loading-small').should('exist')
@@ -104,18 +94,8 @@ describe('Settings: Change user properties', function() {
cy.get('input[type="password"]').should('have.value', '123456')
cy.get('input[type="password"] ~ button').click()
- // Ignore failure if modal is not shown
- cy.once('fail', (error) => {
- expect(error.name).to.equal('AssertionError')
- expect(error).to.have.property('node', '.modal-container')
- })
// Make sure no confirmation modal is shown
- cy.root().closest('body').find('.modal-container').then(($modal) => {
- if ($modal.length > 0) {
- cy.wrap($modal).find('input[type="password"]').type(admin.password)
- cy.wrap($modal).find('button').contains('Confirm').click()
- }
- })
+ handlePasswordConfirmation(admin.password)
// see that the password cell for user user0 is done loading
cy.get('.user-row-text-field.icon-loading-small').should('exist')