refactor: refs #8581 enhance fillInForm

This commit is contained in:
Jorge Penadés 2025-02-20 15:53:08 +01:00
parent e0459f2016
commit 94cc4f2950
1 changed files with 35 additions and 29 deletions

View File

@ -142,11 +142,13 @@ Cypress.Commands.add('countSelectOptions', (selector, option) => {
cy.get('.q-menu .q-item').should('have.length', option); cy.get('.q-menu .q-item').should('have.length', option);
}); });
Cypress.Commands.add('fillInForm', (obj, form = '.q-form > .q-card') => { Cypress.Commands.add(
'fillInForm',
(obj, { form = '.q-form > .q-card', attr = 'aria-label' }) => {
cy.waitForElement(form); cy.waitForElement(form);
cy.get(`${form} input`).each(([el]) => { cy.get(`${form} input`).each(([el]) => {
cy.wrap(el) cy.wrap(el)
.invoke('attr', 'aria-label') .invoke('attr', attr)
.then((ariaLabel) => { .then((ariaLabel) => {
const field = obj[ariaLabel]; const field = obj[ariaLabel];
if (!field) return; if (!field) return;
@ -157,7 +159,9 @@ Cypress.Commands.add('fillInForm', (obj, form = '.q-form > .q-card') => {
cy.selectOption(el, val); cy.selectOption(el, val);
break; break;
case 'date': case 'date':
cy.get(el).type(val.split('-').join('')); cy.get(el).type(
`{selectall}{backspace}${val.split('-').join('')}`,
);
break; break;
case 'time': case 'time':
cy.get(el).click(); cy.get(el).click();
@ -166,12 +170,13 @@ Cypress.Commands.add('fillInForm', (obj, form = '.q-form > .q-card') => {
cy.get('.q-time .q-time__link').contains(val.x).click(); cy.get('.q-time .q-time__link').contains(val.x).click();
break; break;
default: default:
cy.wrap(el).type(val); cy.wrap(el).type(`{selectall}{backspace}${val}`);
break; break;
} }
}); });
}); });
}); },
);
Cypress.Commands.add('checkOption', (selector) => { Cypress.Commands.add('checkOption', (selector) => {
cy.get(selector).find('.q-checkbox__inner').click(); cy.get(selector).find('.q-checkbox__inner').click();
@ -381,6 +386,7 @@ Cypress.Commands.add('clickButtonWith', (type, value) => {
Cypress.Commands.add('clickButtonWithIcon', (iconClass) => { Cypress.Commands.add('clickButtonWithIcon', (iconClass) => {
cy.get(`.q-icon.${iconClass}`).parent().click(); cy.get(`.q-icon.${iconClass}`).parent().click();
}); });
Cypress.Commands.add('clickButtonWithText', (buttonText) => { Cypress.Commands.add('clickButtonWithText', (buttonText) => {
cy.get('.q-btn').contains(buttonText).click(); cy.get('.q-btn').contains(buttonText).click();
}); });