refactor: refs #8581 enhance fillInForm
This commit is contained in:
parent
e0459f2016
commit
94cc4f2950
|
@ -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();
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue