From c1637a74b400c956e7df6921c0ba36f6d2406b8d Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Sun, 2 Mar 2025 22:08:02 +0100 Subject: [PATCH] feat: add commands --- test/cypress/support/commands.js | 34 ++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/test/cypress/support/commands.js b/test/cypress/support/commands.js index aa4a1219e..6bda02d41 100755 --- a/test/cypress/support/commands.js +++ b/test/cypress/support/commands.js @@ -54,8 +54,10 @@ Cypress.Commands.add('login', (user) => { }); }); -Cypress.Commands.add('domContentLoad', (element, timeout = 5000) => { +Cypress.Commands.overwrite('visit', (originalFn, url, options) => { + originalFn(url, options); cy.waitUntil(() => cy.document().then((doc) => doc.readyState === 'complete')); + cy.waitUntil(() => cy.get('main').should('exist')); }); Cypress.Commands.add('waitForElement', (element, timeout = 5000) => { cy.get(element, { timeout }).should('be.visible').and('not.be.disabled'); @@ -110,7 +112,7 @@ function selectItem(selector, option, ariaControl, hasWrite = true) { .find((item) => item.innerText.includes(option)); if (matchingItem) return cy.wrap(matchingItem).click(); - if (hasWrite) cy.get(selector).clear().type(option, { delay: 0 }); + if (hasWrite) cy.get(selector).clear().type(option); return selectItem(selector, option, ariaControl, false); }); } @@ -327,12 +329,14 @@ Cypress.Commands.add('openUserPanel', () => { }); Cypress.Commands.add('checkNotification', (text) => { - cy.get('.q-notification') + cy.get('.q-notification', { timeout: 10000 }) .should('be.visible') - .last() - .then(($lastNotification) => { - if (!Cypress.$($lastNotification).text().includes(text)) - throw new Error(`Notification not found: "${text}"`); + .should('have.length.greaterThan', 0) + .should(($elements) => { + const found = $elements + .toArray() + .some((el) => Cypress.$(el).text().includes(text)); + expect(found).to.be.true; }); }); @@ -379,8 +383,22 @@ Cypress.Commands.add('clickButtonWith', (type, value) => { } }); Cypress.Commands.add('clickButtonWithIcon', (iconClass) => { - cy.get(`.q-icon.${iconClass}`).parent().click(); + cy.waitForElement('[data-cy="descriptor_actions"]'); + cy.get('[data-cy="loading-spinner"]', { timeout: 10000 }).should('not.be.visible'); + cy.get('.q-btn') + .filter((index, el) => Cypress.$(el).find('.q-icon.' + iconClass).length > 0) + .then(($btn) => { + cy.wrap($btn).click(); + }); }); Cypress.Commands.add('clickButtonWithText', (buttonText) => { cy.get('.q-btn').contains(buttonText).click(); }); + +Cypress.Commands.add('colField', (name, index = null) => { + if (index) { + cy.get(`:nth-child(${index}) > [data-col-field="${name}"]`); + } else { + cy.get(`[data-col-field="${name}"]`); + } +});