feat: add commands

This commit is contained in:
Javier Segarra 2025-03-02 22:08:02 +01:00
parent c5f83d43f6
commit c1637a74b4
1 changed files with 26 additions and 8 deletions

View File

@ -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}"]`);
}
});