55 lines
1.9 KiB
JavaScript
55 lines
1.9 KiB
JavaScript
Cypress.Commands.add('getRow', (index = 1) =>
|
|
cy.get(`.vnTable .q-virtual-scroll__content tr:nth-child(${index})`),
|
|
);
|
|
Cypress.Commands.add('getRowCol', (field, index = 1) =>
|
|
cy.getRow(index).find(`[data-col-field="${field}"]`),
|
|
);
|
|
|
|
Cypress.Commands.add('vnTableCreateBtn', () =>
|
|
cy.dataCy('vnTableCreateBtn').should('exist').click(),
|
|
);
|
|
|
|
Cypress.Commands.add('waitTableScrollLoad', () =>
|
|
cy.waitForElement('[data-q-vs-anchor]'),
|
|
);
|
|
|
|
Cypress.Commands.add('tableActions', (n = 0, child = 1) =>
|
|
cy.get(
|
|
`:nth-child(${child}) > .q-table--col-auto-width > [data-cy="tableAction-${n}"] > .q-btn__content > .q-icon`,
|
|
),
|
|
);
|
|
|
|
Cypress.Commands.add('validateVnTableRows', (opts = {}) => {
|
|
let { cols = [] } = opts;
|
|
const { rows = [] } = opts;
|
|
if (!Array.isArray(cols)) cols = [cols];
|
|
const rowSelector = rows.length
|
|
? rows.map((row) => `> :nth-child(${row})`).join(', ')
|
|
: '> *';
|
|
cy.get(`[data-cy="vnTable"] .q-virtual-scroll__content`).within(() => {
|
|
cy.get(`${rowSelector}`).each(($el) => {
|
|
for (const { name, type = 'string', val, operation = 'equal' } of cols) {
|
|
cy.wrap($el)
|
|
.find(`[data-cy="vnTableCell_${name}"]`)
|
|
.invoke('text')
|
|
.then((text) => {
|
|
if (type === 'string')
|
|
expect(text.trim().toLowerCase()).to[operation](
|
|
val.toLowerCase(),
|
|
);
|
|
if (type === 'number') cy.checkNumber(text, val, operation);
|
|
if (type === 'date') cy.checkDate(text, val, operation);
|
|
});
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
Cypress.Commands.add('colField', (name, index = null, key = 'data-col-field') => {
|
|
if (index) {
|
|
cy.get(`:nth-child(${index}) > [${key}="${name}"]`);
|
|
} else {
|
|
cy.get(`[${key}="${name}"]`);
|
|
}
|
|
});
|