feat: add custom Cypress commands for table row manipulation

This commit is contained in:
Javier Segarra 2025-03-24 01:43:00 +01:00
parent d8bea48b26
commit fd68071a2e
2 changed files with 23 additions and 0 deletions

View File

@ -0,0 +1,3 @@
Cypress.Commands.add('firstRow', (field, index = 1) =>
cy.get(`:nth-child(${index}) > [data-col-field="${field}"]`),
);

View File

@ -29,7 +29,12 @@
// import { registerCommands } from '@quasar/quasar-app-extension-testing-e2e-cypress';
import moment from 'moment';
import waitUntil from './waitUntil';
// Importar dinámicamente todos los archivos con el sufijo .commands.js dentro de la carpeta src/test/cypress/integration
const requireCommands = require.context('../integration', true, /\.commands\.js$/);
// Iterar sobre cada archivo y requerirlo
requireCommands.keys().forEach(requireCommands);
// Common comma
Cypress.Commands.add('waitUntil', { prevSubject: 'optional' }, waitUntil);
Cypress.Commands.add('resetDB', () => {
@ -618,3 +623,18 @@ Cypress.Commands.add('checkQueryParams', (expectedParams = {}) => {
Cypress.Commands.add('waitTableScrollLoad', () =>
cy.waitForElement('[data-q-vs-anchor]'),
);
Cypress.Commands.add('countTableRows', (operator = 'gt', value = 0) => {
const element = 'data-row-index';
cy.get('body').then(($body) => {
const hasRows = $body.find(`td[${element}]`).length > 0;
if (!hasRows) expect(0).to.be[operator](value);
else
cy.get(`td[${element}]`)
.last()
.invoke('attr', element)
.then((lastIndex) => {
const totalRows = parseInt(lastIndex) + 1;
expect(totalRows).to.be[operator](value);
});
});
});