From 94cc4f29504090d30d38a9c87171dc54902df4f1 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 20 Feb 2025 15:53:08 +0100 Subject: [PATCH] refactor: refs #8581 enhance fillInForm --- test/cypress/support/commands.js | 64 +++++++++++++++++--------------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/test/cypress/support/commands.js b/test/cypress/support/commands.js index aa4a1219e..fc84412ae 100755 --- a/test/cypress/support/commands.js +++ b/test/cypress/support/commands.js @@ -142,36 +142,41 @@ Cypress.Commands.add('countSelectOptions', (selector, option) => { cy.get('.q-menu .q-item').should('have.length', option); }); -Cypress.Commands.add('fillInForm', (obj, form = '.q-form > .q-card') => { - cy.waitForElement(form); - cy.get(`${form} input`).each(([el]) => { - cy.wrap(el) - .invoke('attr', 'aria-label') - .then((ariaLabel) => { - const field = obj[ariaLabel]; - if (!field) return; +Cypress.Commands.add( + 'fillInForm', + (obj, { form = '.q-form > .q-card', attr = 'aria-label' }) => { + cy.waitForElement(form); + cy.get(`${form} input`).each(([el]) => { + cy.wrap(el) + .invoke('attr', attr) + .then((ariaLabel) => { + const field = obj[ariaLabel]; + if (!field) return; - const { type, val } = field; - switch (type) { - case 'select': - cy.selectOption(el, val); - break; - case 'date': - cy.get(el).type(val.split('-').join('')); - break; - case 'time': - cy.get(el).click(); - cy.get('.q-time .q-time__clock').contains(val.h).click(); - cy.get('.q-time .q-time__clock').contains(val.m).click(); - cy.get('.q-time .q-time__link').contains(val.x).click(); - break; - default: - cy.wrap(el).type(val); - break; - } - }); - }); -}); + const { type, val } = field; + switch (type) { + case 'select': + cy.selectOption(el, val); + break; + case 'date': + cy.get(el).type( + `{selectall}{backspace}${val.split('-').join('')}`, + ); + break; + case 'time': + cy.get(el).click(); + cy.get('.q-time .q-time__clock').contains(val.h).click(); + cy.get('.q-time .q-time__clock').contains(val.m).click(); + cy.get('.q-time .q-time__link').contains(val.x).click(); + break; + default: + cy.wrap(el).type(`{selectall}{backspace}${val}`); + break; + } + }); + }); + }, +); Cypress.Commands.add('checkOption', (selector) => { cy.get(selector).find('.q-checkbox__inner').click(); @@ -381,6 +386,7 @@ Cypress.Commands.add('clickButtonWith', (type, value) => { Cypress.Commands.add('clickButtonWithIcon', (iconClass) => { cy.get(`.q-icon.${iconClass}`).parent().click(); }); + Cypress.Commands.add('clickButtonWithText', (buttonText) => { cy.get('.q-btn').contains(buttonText).click(); });