refactor: refs #8581 simplify fillInForm and validateForm

This commit is contained in:
Jorge Penadés 2025-02-20 18:02:07 +01:00
parent c3b6f79965
commit c041877f65
1 changed files with 54 additions and 53 deletions

View File

@ -143,9 +143,8 @@ 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( Cypress.Commands.add('fillInForm', (obj, opts = {}) => {
'fillInForm', const { form = '.q-form > .q-card', attr = 'aria-label' } = opts;
(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)
@ -153,6 +152,8 @@ Cypress.Commands.add(
.then((key) => { .then((key) => {
const field = obj[key]; const field = obj[key];
if (!field) return; if (!field) return;
if (typeof field == 'string')
return cy.wrap(el).type(`{selectall}{backspace}${field}`);
const { type, val } = field; const { type, val } = field;
switch (type) { switch (type) {
@ -176,12 +177,10 @@ Cypress.Commands.add(
} }
}); });
}); });
}, });
);
Cypress.Commands.add( Cypress.Commands.add('validateForm', (obj, opts = {}) => {
'validateForm', const { form = '.q-form > .q-card', attr = 'data-cy' } = opts;
(obj, { form = '.q-form > .q-card', attr = 'data-cy' }) => {
cy.waitForElement(form); cy.waitForElement(form);
cy.get(`${form} input`).each(([el]) => { cy.get(`${form} input`).each(([el]) => {
cy.wrap(el) cy.wrap(el)
@ -194,6 +193,9 @@ Cypress.Commands.add(
cy.get(el) cy.get(el)
.invoke('val') .invoke('val')
.then((elVal) => { .then((elVal) => {
if (typeof field == 'string')
expect(elVal.toLowerCase()).to.equal(field.toLowerCase());
else
switch (type) { switch (type) {
case 'date': case 'date':
const elDate = moment(elVal, 'DD-MM-YYYY'); const elDate = moment(elVal, 'DD-MM-YYYY');
@ -209,8 +211,7 @@ Cypress.Commands.add(
}); });
}); });
}); });
}, });
);
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();