feat: refs #8581 add validateForm command for form validation with date handling
This commit is contained in:
parent
73f3a2c98d
commit
813e677a12
|
@ -27,6 +27,7 @@
|
||||||
// DO NOT REMOVE
|
// DO NOT REMOVE
|
||||||
// Imports Quasar Cypress AE predefined commands
|
// Imports Quasar Cypress AE predefined commands
|
||||||
// import { registerCommands } from '@quasar/quasar-app-extension-testing-e2e-cypress';
|
// import { registerCommands } from '@quasar/quasar-app-extension-testing-e2e-cypress';
|
||||||
|
import moment from 'moment';
|
||||||
Cypress.Commands.add('waitUntil', { prevSubject: 'optional' }, require('./waitUntil'));
|
Cypress.Commands.add('waitUntil', { prevSubject: 'optional' }, require('./waitUntil'));
|
||||||
Cypress.Commands.add('resetDB', () => {
|
Cypress.Commands.add('resetDB', () => {
|
||||||
cy.exec('pnpm run resetDatabase');
|
cy.exec('pnpm run resetDatabase');
|
||||||
|
@ -107,7 +108,7 @@ function selectItem(selector, option, ariaControl, hasWrite = true) {
|
||||||
getItems(ariaControl).then((items) => {
|
getItems(ariaControl).then((items) => {
|
||||||
const matchingItem = items
|
const matchingItem = items
|
||||||
.toArray()
|
.toArray()
|
||||||
.find((item) => item.innerText.includes(option));
|
.find((item) => item.innerText.toLowerCase().includes(option.toLowerCase()));
|
||||||
if (matchingItem) return cy.wrap(matchingItem).click();
|
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, { delay: 0 });
|
||||||
|
@ -149,8 +150,8 @@ Cypress.Commands.add(
|
||||||
cy.get(`${form} input`).each(([el]) => {
|
cy.get(`${form} input`).each(([el]) => {
|
||||||
cy.wrap(el)
|
cy.wrap(el)
|
||||||
.invoke('attr', attr)
|
.invoke('attr', attr)
|
||||||
.then((ariaLabel) => {
|
.then((key) => {
|
||||||
const field = obj[ariaLabel];
|
const field = obj[key];
|
||||||
if (!field) return;
|
if (!field) return;
|
||||||
|
|
||||||
const { type, val } = field;
|
const { type, val } = field;
|
||||||
|
@ -178,6 +179,39 @@ Cypress.Commands.add(
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Cypress.Commands.add(
|
||||||
|
'validateForm',
|
||||||
|
(obj, { form = '.q-form > .q-card', attr = 'data-cy' }) => {
|
||||||
|
cy.waitForElement(form);
|
||||||
|
cy.get(`${form} input`).each(([el]) => {
|
||||||
|
cy.wrap(el)
|
||||||
|
.invoke('attr', attr)
|
||||||
|
.then((key) => {
|
||||||
|
const field = obj[key];
|
||||||
|
if (!field) return;
|
||||||
|
|
||||||
|
const { type, val } = field;
|
||||||
|
cy.get(el)
|
||||||
|
.invoke('val')
|
||||||
|
.then((elVal) => {
|
||||||
|
switch (type) {
|
||||||
|
case 'date':
|
||||||
|
const elDate = moment(elVal, 'DD-MM-YYYY');
|
||||||
|
const mockDate = moment(val, 'DD-MM-YYYY');
|
||||||
|
expect(elDate.isSame(mockDate, 'day')).to.be.true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
expect(elVal.toLowerCase()).to.equal(
|
||||||
|
val.toLowerCase(),
|
||||||
|
);
|
||||||
|
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();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue