diff --git a/cypress/e2e/core-utils.ts b/cypress/e2e/core-utils.ts index d0fd049e8b0..c01ee05a61e 100644 --- a/cypress/e2e/core-utils.ts +++ b/cypress/e2e/core-utils.ts @@ -10,6 +10,32 @@ export function getUnifiedSearchModal() { return cy.get('#unified-search') } +/** + * 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', 'Authentication required') + .if() + .within(() => { + cy.get('input[type="password"]') + .type(adminPassword) + cy.findByRole('button', { name: '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))) +} + /** * Open the unified search modal */