test: add describe for each test
gitea/salix-front/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Javier Segarra 2025-02-14 01:53:39 +01:00
parent 55841d795f
commit a7d271bafd
3 changed files with 147 additions and 48 deletions

View File

@ -207,6 +207,7 @@ const getLocale = (label) => {
color="primary"
style="position: fixed; z-index: 1; right: 0; bottom: 0"
icon="search"
data-cy="search"
@click="search()"
>
<QTooltip bottom anchor="bottom right">
@ -224,6 +225,7 @@ const getLocale = (label) => {
<QItemSection top side>
<QBtn
@click="clearFilters"
data-cy="clearFilters"
color="primary"
dense
flat

View File

@ -124,46 +124,133 @@ describe('Monitor Tickets Table', () => {
cy.get('.q-ml-sm > .q-btn__content > .q-icon').click();
/* ==== End Cypress Studio ==== */
});
describe('should filter by filter panel', () => {
it('clientFk', () => {
// Client id - clientFk
cy.get('[data-cy="Client id_input"]').type('1101');
cy.searchInFilterPanel();
requestParams('clientFk', '1101');
countRows('eq', 7);
});
it.only('should filter by filter panel', () => {
// Client id - clientFk
cy.get('[data-cy="Client id_input"]').type('1101');
cy.searchInFilterPanel();
requestParams('clientFk', '1101');
countRows('eq', 7);
it('orderFk', () => {
// order id
cy.get('[data-cy="Order id_input"]').type(7);
cy.searchInFilterPanel();
requestParams('orderFk', '7');
countRows('eq', 1);
});
// order id
cy.get('[data-cy="Order id_input"]').type(7);
cy.searchInFilterPanel();
requestParams('orderFk', '7');
countRows('eq', 1);
it('scopeDays', () => {
// Scope days
cy.get('[data-cy="Days onward_input"]').type(2);
cy.searchInFilterPanel();
requestParams('scopeDays', '2');
countRows('eq', 27);
});
// Scope days
cy.get('[data-cy="Days onward_input"]').type(2);
cy.searchInFilterPanel();
requestParams('scopeDays', '2');
countRows('eq', 1);
it('salesPersonFk', () => {
// SalesPerson
cy.get('[data-cy="vnWorkerSelect"]').click();
cy.get('.q-item__label').contains('salesPersonNick').click();
cy.searchInFilterPanel();
requestParams('c.salesPersonFk', 18, { inWhere: true });
countRows('eq', 21);
});
// SalesPerson
cy.get('[data-cy="vnWorkerSelect"]').click();
cy.get('.q-item__label').contains('salesPersonNick').click();
cy.searchInFilterPanel();
requestParams('c.salesPersonFk', 18, { inWhere: true });
countRows('eq', 1);
// it('', () => {
// cy.get('.q-mt-xs > .q-item__section--side').click();
// requestParams(null);
// });
cy.get('.q-mt-xs > .q-item__section--side').click();
requestParams(null);
// Nickname
cy.get('[data-cy="Nickname_input"]').type('test');
cy.searchInFilterPanel();
requestParams('t.nickname', 'test', { inWhere: true, like: true });
countRows('eq', 2);
it('nickname', () => {
// Nickname
cy.get('[data-cy="Nickname_input"]').type('test');
cy.searchInFilterPanel();
requestParams('t.nickname', 'test', { inWhere: true, like: true });
countRows('eq', 2);
});
// cy.get('#f_d6f1f8d4-40b7-4e67-a7bb-5f309fe079b8_1 > .q-item__section > .q-item__label--caption').click();
cy.get(
'.q-scrollarea__content > .q-btn--standard > .q-btn__content > .q-icon',
).click();
/* ==== End Cypress Studio ==== */
it.only('refFk', () => {
// Invoice
cy.get('[data-cy="Invoice_input"]').type('test');
cy.searchInFilterPanel();
requestParams('refFk', 'test');
countRows('eq', 0);
});
it('agencyModeFk', () => {
// Agency
cy.get('[data-cy="Agency_select"]').click();
cy.get('.q-item__label').contains('inhouse pickup').click();
cy.searchInFilterPanel();
requestParams('agencyModeFk', '1');
countRows('eq', 6);
});
// it('', () => {
// cy.get('.q-mt-xs > .q-item__section--side').click();
// requestParams(null);
// });
it('state', () => {
// State
cy.get('[data-cy="State_select"]').click();
cy.get('.q-item__label').contains('Libre').click();
cy.searchInFilterPanel();
requestParams('ts.stateFk', 2, { inWhere: true });
countRows('eq', 11);
});
it('alertLevel', () => {
// AlertLevel
cy.get('[data-cy="Grouped State_select"]').click();
cy.get('.q-item__label').contains('Free').click();
cy.searchInFilterPanel();
requestParams('alertLevel', '0');
countRows('eq', 16);
});
// it('', () => {
// cy.get('.q-mt-xs > .q-item__section--side').click();
// requestParams(null);
// });
it('countryFk', () => {
// Country
cy.get('[data-cy="Country_select"]').click();
cy.get('.q-item__label').contains('España').click();
cy.searchInFilterPanel();
requestParams('countryFk', '1');
countRows('eq', 26);
});
it('warehouseFk', () => {
// Province
cy.get('[data-cy="Province_select"]').click();
cy.get('.q-item__label').contains('Province one').click();
cy.searchInFilterPanel();
requestParams('warehouseFk', 1);
countRows('eq', 2);
});
it('department', () => {
// Department
cy.get('[data-cy="Department_select"]').click();
cy.get('.q-item__label').contains('VENTAS').click();
cy.searchInFilterPanel();
requestParams('d.name', 'VENTAS', { inWhere: true });
countRows('eq', 24);
});
it('packing', () => {
// ITP
cy.get('[data-cy="ITP_select"]').click();
cy.get('.q-item__label').contains('H').click();
cy.searchInFilterPanel();
requestParams('packing', 'H');
countRows('eq', 5);
});
});
});
function requestParams(key, value, options = { inWhere: false, like: false }) {
@ -198,13 +285,20 @@ function requestParams(key, value, options = { inWhere: false, like: false }) {
}
function countRows(operator = 'gt', value = 0) {
// Obtener el último data-row-index para saber el total de filas
cy.get('td[data-row-index]')
.last()
.invoke('attr', 'data-row-index')
.then((lastIndex) => {
const totalRows = parseInt(lastIndex) + 1; // Sumamos 1 porque el índice empieza en 0
cy.log(`Total de filas: ${totalRows}`);
expect(totalRows).to.be[operator](value);
// expect(totalRows).to.be.gt(0);
});
const element = 'data-row-index';
cy.get('body').then(($body) => {
const hasRows = $body.find(`td[${element}]`).length > 0;
cy.log('hasRows:', hasRows);
if (!hasRows) expect(0).to.be[operator](value);
else
cy.get(`td[${element}]`)
.last()
.invoke('attr', element)
.then((lastIndex) => {
const totalRows = parseInt(lastIndex) + 1; // Sumamos 1 porque el índice empieza en 0
cy.log(`Total de filas: ${totalRows}`);
expect(totalRows).to.be[operator](value);
// expect(totalRows).to.be.gt(0);
});
});
}

View File

@ -286,12 +286,15 @@ Cypress.Commands.add('openRightMenu', (element) => {
cy.get('[data-cy="toggle-right-drawer"]').click();
});
Cypress.Commands.add('cleanFilterPanel', () => {
const element = 'clearFilters';
if (element) cy.waitForElement(`[data-cy="${element}"]`);
cy.dataCy(element).click();
});
Cypress.Commands.add('searchInFilterPanel', () => {
const element =
'.q-scrollarea__content > .q-btn--standard > .q-btn__content > .q-icon';
if (element) cy.waitForElement(element);
cy.get(element).click();
cy.wait(1000);
const element = 'search';
if (element) cy.waitForElement(`[data-cy="${element}"]`);
cy.dataCy(element).click();
});
Cypress.Commands.add('openFilterPanel', () => {