refactor: streamline table interaction methods and update test cases

This commit is contained in:
Javier Segarra 2025-03-28 02:20:51 +01:00
parent 269427e08c
commit cf8923a2d4
5 changed files with 43 additions and 50 deletions

View File

@ -706,14 +706,6 @@ const rowCtrlClickFunction = computed(() => {
dense
:options="tableModes.filter((mode) => !mode.disable)"
/>
<QBtn
data-cy="vnTable_filter_btn"
icon="filter_alt"
class="bg-vn-section-color q-ml-sm"
dense
@click="stateStore.toggleRightDrawer()"
/>
</template>
<template #header-cell="{ col }">
<QTh

View File

@ -12,11 +12,11 @@ describe('Monitor Clients actions', () => {
cy.get('.q-page').should('be.visible');
cy.dataCy('recentOrderActions').within(() => {
cy.firstRow('clientFk').find('span').should('have.class', 'link').click();
cy.getRowCol('clientFk').find('span').should('have.class', 'link').click();
});
cy.dataCy('CustomerDescriptor').should('exist');
cy.dataCy('recentOrderActions').within(() => {
cy.firstRow('departmentFk', 2)
cy.getRowCol('departmentFk', 2)
.find('span')
.should('have.class', 'link')
.click();
@ -33,7 +33,7 @@ describe('Monitor Clients actions', () => {
cy.dataCy('To_inputDate').should('have.value', '01/01/2001');
cy.get(`${clientFk} [data-cy="_select"]`).click();
cy.clickOption();
cy.countTableRows('eq', 0);
cy.countTableRows('eq', 3);
cy.get(`${clientFk} .q-field .q-field__control > :nth-child(2)`).click();
cy.get(`${departmentFk} [data-cy="_select"]`).type('VIP').trigger('enter');

View File

@ -1,13 +1,11 @@
const firstRow = (field, index = 1) =>
`:nth-child(${index}) > [data-col-field="${field}"]`;
describe('Monitor Tickets Table', () => {
beforeEach(() => {
cy.viewport(1920, 1080);
cy.login('developer');
cy.visit('/#/monitor/tickets');
cy.waitForElement('.q-page');
cy.intercept('GET', '**/SalesMonitors/salesFilter*').as('filterRequest');
cy.openFilterPanel();
cy.openRightMenu();
});
it('should open new tab when ctrl+click on client link', () => {
cy.intercept('GET', '**/SalesMonitors/salesFilter*').as('filterRequest');
@ -16,7 +14,7 @@ describe('Monitor Tickets Table', () => {
cy.stub(win, 'open').as('windowOpen');
});
cy.get(firstRow('provinceFk')).click({ ctrlKey: true });
cy.getRowCol('provinceFk').click({ ctrlKey: true });
cy.get('@windowOpen').should('be.calledWithMatch', /\/ticket\/\d+\/sale/);
});
it('should filter by column headers and update URL params', () => {
@ -33,40 +31,42 @@ describe('Monitor Tickets Table', () => {
});
it('should filter by filter panel', () => {
// Client id - clientFk
cy.get('[data-cy="Client id_input"]').type('1101');
cy.dataCy('Client id_input').type('1101');
cy.searchInFilterPanel();
cy.url().should('include', 'clientFk');
cy.countTableRows('eq', 7);
//
cy.cleanFilterPanel();
cy.get('[data-cy="Order id_input"]').type(7);
// Order id - orderFk
cy.dataCy('Order id_input').type(7);
cy.searchInFilterPanel();
cy.url().should('include', 'orderFk');
cy.countTableRows('eq', 1);
//
cy.cleanFilterPanel();
cy.get('[data-cy="Days onward_input"]').type(2);
// Days onward - scopeDays
cy.dataCy('Days onward_input').type(2);
cy.searchInFilterPanel();
cy.url().should('include', 'scopeDays');
cy.countTableRows('eq', 27);
//
cy.cleanFilterPanel();
// Nickname
cy.get('[data-cy="Nickname_input"]').type('test');
cy.dataCy('Nickname_input').type('test');
cy.searchInFilterPanel();
cy.url().should('include', 'nickname');
cy.countTableRows('eq', 2);
//
cy.cleanFilterPanel();
// Invoice
cy.get('[data-cy="Invoice_input"]').type('test');
cy.dataCy('Invoice_input').type('test');
cy.searchInFilterPanel();
cy.url().should('include', 'refFk');
cy.countTableRows('eq', 0);
//
cy.cleanFilterPanel();
// Agency
cy.get('[data-cy="Agency_select"]').click();
cy.dataCy('Agency_select').click();
cy.get('.q-item__label').contains('inhouse pickup').click();
cy.searchInFilterPanel();
cy.url().should('include', 'agencyModeFk');
@ -74,7 +74,7 @@ describe('Monitor Tickets Table', () => {
//
cy.cleanFilterPanel();
// State
cy.get('[data-cy="State_select"]').click();
cy.dataCy('State_select').click();
cy.get('.q-item__label').contains('Libre').click();
cy.searchInFilterPanel();
cy.url().should('include', 'stateFk');
@ -82,7 +82,7 @@ describe('Monitor Tickets Table', () => {
//
cy.cleanFilterPanel();
// AlertLevel
cy.get('[data-cy="Grouped State_select"]').click();
cy.dataCy('Grouped State_select').click();
cy.get('.q-item__label').contains('Free').click();
cy.searchInFilterPanel();
cy.url().should('include', 'alertLevel');
@ -90,7 +90,7 @@ describe('Monitor Tickets Table', () => {
//
cy.cleanFilterPanel();
// Country
cy.get('[data-cy="Country_select"]').click();
cy.dataCy('Country_select').click();
cy.get('.q-item__label').contains('España').click();
cy.searchInFilterPanel();
cy.url().should('include', 'countryFk');
@ -98,7 +98,7 @@ describe('Monitor Tickets Table', () => {
//
cy.cleanFilterPanel();
// Province
cy.get('[data-cy="Warehouse_select"]').click();
cy.dataCy('Warehouse_select').click();
cy.get('.q-item__label').contains('Warehouse Two').click();
cy.searchInFilterPanel();
cy.url().should('include', 'warehouseFk');
@ -112,7 +112,7 @@ describe('Monitor Tickets Table', () => {
//
cy.cleanFilterPanel();
// ITP
cy.get('[data-cy="ITP_select"]').click();
cy.dataCy('ITP_select').click();
cy.get('.q-item__label').contains('H').click();
cy.searchInFilterPanel();
cy.url().should('include', 'packing');
@ -120,23 +120,20 @@ describe('Monitor Tickets Table', () => {
});
it('Cols', () => {
cy.get(firstRow('totalProblems'));
cy.getRowCol('totalProblems');
cy.get(firstRow('id')).find('span').should('have.class', 'link').click();
cy.getRowCol('id').find('span').should('have.class', 'link').click();
cy.dataCy('TicketDescriptor').should('exist');
cy.get(firstRow('zoneFk')).find('span').should('have.class', 'link').click();
cy.getRowCol('zoneFk').find('span').should('have.class', 'link').click();
cy.dataCy('ZoneDescriptor').should('exist');
cy.get(firstRow('clientFk')).find('span').should('have.class', 'link').click();
cy.getRowCol('clientFk').find('span').should('have.class', 'link').click();
cy.dataCy('CustomerDescriptor').should('exist');
cy.get(firstRow('departmentFk'))
.find('span')
.should('have.class', 'link')
.click();
cy.getRowCol('departmentFk').find('span').should('have.class', 'link').click();
cy.dataCy('DepartmentDescriptor').should('exist');
cy.get(firstRow('shippedDate')).find('.q-badge');
cy.getRowCol('shippedDate').find('.q-badge');
cy.get(
':nth-child(1) > .q-table--col-auto-width > [data-cy="tableAction-0"] > .q-btn__content > .q-icon',
).click({ ctrlKey: true });

View File

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

View File

@ -352,25 +352,18 @@ Cypress.Commands.add('openListSummary', (row) => {
cy.get('.card-list-body .actions .q-btn:nth-child(2)').eq(row).click();
});
Cypress.Commands.add('openRightMenu', (element) => {
if (element) cy.waitForElement(element);
cy.get('[data-cy="toggle-right-drawer"]').click();
Cypress.Commands.add('openRightMenu', (element = 'toggle-right-drawer') => {
if (element) cy.waitForElement(`[data-cy="${element}"]`);
cy.dataCy(element).click();
});
Cypress.Commands.add('cleanFilterPanel', () => {
const element = 'clearFilters';
Cypress.Commands.add('cleanFilterPanel', (element = 'clearFilters') => {
cy.get('#filterPanelForm').scrollIntoView();
if (element) cy.waitForElement(`[data-cy="${element}"]`);
cy.dataCy(element).click();
});
Cypress.Commands.add('searchInFilterPanel', () => {
const element = 'search';
if (element) cy.waitForElement(`[data-cy="${element}"]`);
cy.dataCy(element).click();
});
Cypress.Commands.add('openFilterPanel', () => {
const element = 'vnTable_filter_btn';
Cypress.Commands.add('searchInFilterPanel', (element = 'vnFilterPanel_search') => {
if (element) cy.waitForElement(`[data-cy="${element}"]`);
cy.dataCy(element).click();
});