From 55841d795f643bbc712d49e64e59a4766fa2064d Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 14 Feb 2025 01:41:06 +0100 Subject: [PATCH 01/31] test: init e2e_monitorTicket --- cypress.config.js | 1 - src/components/VnTable/VnTable.vue | 2 + src/pages/Item/components/ItemProposal.vue | 8 +- .../integration/monitor/monitorTicket.spec.js | 210 ++++++++++++++++++ test/cypress/support/commands.js | 13 ++ 5 files changed, 231 insertions(+), 3 deletions(-) create mode 100644 test/cypress/integration/monitor/monitorTicket.spec.js diff --git a/cypress.config.js b/cypress.config.js index a9e27fcfd..f43bd0dec 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -15,7 +15,6 @@ export default defineConfig({ video: false, specPattern: 'test/cypress/integration/**/*.spec.js', experimentalRunAllSpecs: false, - watchForFileChanges: false, reporter: 'cypress-mochawesome-reporter', reporterOptions: { charts: true, diff --git a/src/components/VnTable/VnTable.vue b/src/components/VnTable/VnTable.vue index 7e0757f6c..2e57c9cd7 100644 --- a/src/components/VnTable/VnTable.vue +++ b/src/components/VnTable/VnTable.vue @@ -614,6 +614,7 @@ const checkbox = ref(null); /> + { + beforeEach(() => { + cy.login('developer'); + cy.viewport(1920, 720); + cy.visit('/#/monitor/tickets'); + cy.domContentLoad(); + cy.waitForElement('.q-page'); + cy.intercept('GET', '**/SalesMonitors/salesFilter*').as('filterRequest'); + cy.openFilterPanel(); + }); + + it('should filter by column headers and update URL params', () => { + // Interceptar las llamadas de filtrado + cy.intercept('GET', '**/SalesMonitors/salesFilter*').as('filterRequest'); + + // Array de pruebas para diferentes columnas + const testCases = [ + // { + // columnName: 'id', + // value: '123', + // expectedParam: { id: '123' }, + // }, + { + columnName: 'clientFk', + value: 'cave', + expectedParam: { clientFk: { like: '%cave%' } }, + }, + // { + // columnName: 'packing', + // value: 'H', + // expectedParam: { packing: 'H' }, + // }, + ]; + + // Probar cada columna + // testCases.forEach(({ columnName, value, expectedParam }) => { + // // Encontrar el input del filtro y escribir el valor + // cy.get(`[data-cy="column-filter-${columnName}"]`) + // .click() + // .type(`${value}{enter}`); + + // Verificar que la URL se actualizó con el parámetro + // cy.url().should('include', encodeURIComponent(JSON.stringify(expectedParam))); + + // Verificar que la petición HTTP incluye el parámetro correcto + // cy.wait('@filterRequest').then((interception) => { + // expect(interception.request.url).to.include( + // encodeURIComponent(JSON.stringify(expectedParam)), + // ); + // }); + + // Limpiar el filtro para la siguiente prueba + // cy.get(`[data-cy="column-filter-${columnName}"]`).clear(); + // }); + /* ==== Generated with Cypress Studio ==== */ cy.get( + '[data-cy="column-filter-id"] > [data-v-532139db=""] > .column > [dense="true"] > .q-field > .q-field__inner > .q-field__control > .q-field__control-container > [data-cy="_input"]', + ).type('13'); + cy.get( + '[data-cy="column-filter-id"] > [data-v-532139db=""] > .column > [dense="true"] > .q-field > .q-field__inner > .q-field__control > .q-field__append > .q-icon', + ).click(); + // cy.get( + // '[data-cy="column-filter-clientFk"] > [data-v-532139db=""] > .column > .q-field > .q-field__inner > .q-field__control > .q-field__control-container > .q-field__native > [data-cy="_select"]', + // ).clear('cave{enter}'); + // cy.get( + // '[data-cy="column-filter-clientFk"] > [data-v-532139db=""] > .column > .q-field > .q-field__inner > .q-field__control > .q-field__control-container > .q-field__native > [data-cy="_select"]', + // ).type('cave{enter}'); + // cy.get( + // '[data-cy="column-filter-clientFk"] > [data-v-532139db=""] > .column > .q-field > .q-field__inner > .q-field__control > .q-field__control-container > .q-field__native > [data-cy="_select"]', + // ).clear('c'); + // cy.get( + // '[data-cy="column-filter-clientFk"] > [data-v-532139db=""] > .column > .q-field > .q-field__inner > .q-field__control > .q-field__control-container > .q-field__native > [data-cy="_select"]', + // ).type('Bar'); + // cy.get( + // '[data-cy="column-filter-clientFk"] > [data-v-532139db=""] > .column > .q-field > .q-field__inner > .q-field__control > .q-field__control-container > .q-field__native > [data-cy="_select"]', + // ).clear('Ba'); + cy.dataCy('vnTable_filter_btn').click(); + cy.get( + '[data-cy="column-filter-clientFk"] > [data-v-532139db=""] > .column > .q-field > .q-field__inner > .q-field__control > .q-field__control-container > .q-field__native > [data-cy="_select"]', + { timeout: 3000 }, + ).type('1101', { timeout: 3000, force: true }); + cy.get('[role="listbox"]') + .find('.q-item') + .find('.q-item__label') + .contains('Bruce Wayne') + .click(); + + cy.get( + '[data-cy="column-filter-clientFk"] > [data-v-532139db=""] > .column > .q-field > .q-field__inner > .q-field__control > :nth-child(2) > .q-icon', + ).click(); + cy.get( + '[data-cy="column-filter-id"] > [data-v-532139db=""] > .column > [dense="true"] > .q-field > .q-field__inner > .q-field__control > .q-field__control-container > [data-cy="_input"]', + ).clear('1'); + + /* ==== End Cypress Studio ==== */ + /* ==== Generated with Cypress Studio ==== */ + cy.get( + '[data-cy="column-filter-clientFk"] > [data-v-532139db=""] > .column > .q-field > .q-field__inner > .q-field__control > .q-field__control-container > .q-field__native > [data-cy="_select"]', + ).clear('1'); + cy.get( + '[data-cy="column-filter-clientFk"] > [data-v-532139db=""] > .column > .q-field > .q-field__inner > .q-field__control > .q-field__control-container > .q-field__native > [data-cy="_select"]', + { timeout: 3000 }, + ).type('1101'); + cy.get('.q-item__label--caption').click(); + cy.get( + '[data-cy="column-filter-salesPersonFk"] > [data-v-532139db=""] > .column > .q-field > .q-field__inner > .q-field__control > .q-field__control-container > .q-field__native > [data-cy="_select"]', + ).click(); + cy.get( + '#f_0ab28e51-61ef-42fd-98cf-5c145672132a_1 > .q-item__section > :nth-child(1)', + ).click(); + cy.get( + '[data-cy="column-filter-provinceFk"] > [data-v-532139db=""] > .column > .q-field > .q-field__inner > .q-field__control > .q-field__control-container > .q-field__native > [data-cy="_select"]', + ).click(); + cy.get('#f_7e2e6ebc-5a8e-40e6-a436-b301a249090e_2 > .q-item__section').click(); + cy.get( + '[data-cy="column-filter-state"] > [data-v-532139db=""] > .column > .q-field > .q-field__inner > .q-field__control > .q-field__control-container > .q-field__native > [data-cy="_select"]', + ).click(); + cy.get('.q-table__top').click(); + cy.get( + '[data-cy="column-filter-state"] > [data-v-532139db=""] > .column > .q-field > .q-field__inner > .q-field__control > .q-field__control-container > .q-field__native > [data-cy="_select"]', + ).click(); + cy.get( + '#f_e05db3bc-1bae-4398-8e06-a9395e8f9e30_13 > .q-item__section > :nth-child(1)', + ).click(); + cy.get('.q-ml-sm > .q-btn__content > .q-icon').click(); + /* ==== End Cypress Studio ==== */ + }); + + 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); + + // order id + cy.get('[data-cy="Order id_input"]').type(7); + cy.searchInFilterPanel(); + requestParams('orderFk', '7'); + countRows('eq', 1); + + // Scope days + cy.get('[data-cy="Days onward_input"]').type(2); + cy.searchInFilterPanel(); + requestParams('scopeDays', '2'); + countRows('eq', 1); + + // 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); + + 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); + + // 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 ==== */ + }); +}); +function requestParams(key, value, options = { inWhere: false, like: false }) { + // cy.wait(2000); + cy.wait('@filterRequest').then((interception) => { + if (!key) return; + const { query } = interception.request; + cy.log('Request query:', query, options); + if (!options.inWhere) + // Verificamos que existe la propiedad clientFk y su valor + expect(query).to.have.property(key, value); + else { + // Verificamos que existe la propiedad where y dentro de ella la propiedad clientFk y su valor + const filter = JSON.parse(query.filter); + if (options.like) + expect(filter.where).to.have.deep.property(key, { + like: `%${value}%`, + }); + else { + expect(filter).to.have.property('where'); + expect(filter.where).to.have.property(key, value); + } + } + // Verificación adicional del formato completo si es necesario + // expect(interception.request.query).to.deep.include({ + // filter: expect.any(String), + // from: expect.any(String), + // to: expect.any(String), + // scopeDays: expect.any(String), + // }); + }); +} +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); + }); +} diff --git a/test/cypress/support/commands.js b/test/cypress/support/commands.js index aa4a1219e..f9e4258a0 100755 --- a/test/cypress/support/commands.js +++ b/test/cypress/support/commands.js @@ -286,6 +286,19 @@ Cypress.Commands.add('openRightMenu', (element) => { cy.get('[data-cy="toggle-right-drawer"]').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); +}); + +Cypress.Commands.add('openFilterPanel', () => { + const element = 'vnTable_filter_btn'; + if (element) cy.waitForElement(`[data-cy="${element}"]`); + cy.dataCy(element).click(); +}); Cypress.Commands.add('openLeftMenu', (element) => { if (element) cy.waitForElement(element); cy.get('.q-toolbar > .q-btn--round.q-btn--dense > .q-btn__content > .q-icon').click(); -- 2.40.1 From a7d271bafd11c5bb4de9a8f10ad41663e08fa04a Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 14 Feb 2025 01:53:39 +0100 Subject: [PATCH 02/31] test: add describe for each test --- src/components/ui/VnFilterPanel.vue | 2 + .../integration/monitor/monitorTicket.spec.js | 180 +++++++++++++----- test/cypress/support/commands.js | 13 +- 3 files changed, 147 insertions(+), 48 deletions(-) diff --git a/src/components/ui/VnFilterPanel.vue b/src/components/ui/VnFilterPanel.vue index d6b525dc8..586feed90 100644 --- a/src/components/ui/VnFilterPanel.vue +++ b/src/components/ui/VnFilterPanel.vue @@ -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()" > @@ -224,6 +225,7 @@ const getLocale = (label) => { { 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); + }); + }); } diff --git a/test/cypress/support/commands.js b/test/cypress/support/commands.js index f9e4258a0..e0b4e0b78 100755 --- a/test/cypress/support/commands.js +++ b/test/cypress/support/commands.js @@ -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', () => { -- 2.40.1 From 97c673b5f397cdbd2256f03973d828fea4aa9672 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Sat, 1 Mar 2025 03:13:11 +0100 Subject: [PATCH 03/31] test: check fields --- src/components/VnTable/VnTable.vue | 1 - .../Customer/Card/CustomerDescriptorProxy.vue | 2 +- .../Ticket/Card/TicketDescriptorProxy.vue | 2 +- .../Worker/Card/WorkerDescriptorProxy.vue | 2 +- src/pages/Zone/Card/ZoneDescriptorProxy.vue | 2 +- .../integration/monitor/monitorTicket.spec.js | 125 +++++------------- 6 files changed, 40 insertions(+), 94 deletions(-) diff --git a/src/components/VnTable/VnTable.vue b/src/components/VnTable/VnTable.vue index 721923a24..ad3a0adca 100644 --- a/src/components/VnTable/VnTable.vue +++ b/src/components/VnTable/VnTable.vue @@ -704,7 +704,6 @@ const rowCtrlClickFunction = computed(() => { diff --git a/src/pages/Ticket/Card/TicketDescriptorProxy.vue b/src/pages/Ticket/Card/TicketDescriptorProxy.vue index 583ba35e7..ba8367e81 100644 --- a/src/pages/Ticket/Card/TicketDescriptorProxy.vue +++ b/src/pages/Ticket/Card/TicketDescriptorProxy.vue @@ -10,7 +10,7 @@ const $props = defineProps({ }); diff --git a/src/pages/Worker/Card/WorkerDescriptorProxy.vue b/src/pages/Worker/Card/WorkerDescriptorProxy.vue index 5f71abbea..baa9aa571 100644 --- a/src/pages/Worker/Card/WorkerDescriptorProxy.vue +++ b/src/pages/Worker/Card/WorkerDescriptorProxy.vue @@ -11,7 +11,7 @@ const $props = defineProps({ diff --git a/test/cypress/integration/monitor/clientActions.spec.js b/test/cypress/integration/monitor/clientActions.spec.js new file mode 100644 index 000000000..f413332f3 --- /dev/null +++ b/test/cypress/integration/monitor/clientActions.spec.js @@ -0,0 +1,61 @@ +describe('Monitor Clients actions', () => { + beforeEach(() => { + cy.login('developer'); + cy.visit('/#/monitor/clients-actions'); + cy.waitForElement('.q-page'); + cy.intercept('GET', '**/SalesMonitors/ordersFilter*').as('ordersFilter'); + cy.intercept('GET', '**/SalesMonitors/clientsFilter*').as('clientsFilter'); + }); + it.only('Should load layout', () => { + cy.get('.q-page').should('be.visible'); + + cy.firstRow('clientFk').find('span').should('have.class', 'link').click(); + cy.dataCy('CustomerDescriptor').should('exist'); + cy.firstRow('departmentFk', 2).find('span').should('have.class', 'link').click(); + cy.dataCy('DepartmentDescriptor').should('exist'); + + cy.dataCy('clientsOnWebsite') + .find(' .q-ml-md') + .should('have.text', 'Clients on website'); + cy.dataCy('recentOrderActions') + .find('.q-ml-md') + .should('have.text', 'Recent order actions'); + cy.get('[data-cy="From_inputDate"]').should('have.value', '01/01/2001'); + cy.get('[data-cy="To_inputDate"]').should('have.value', '01/01/2001'); + cy.get('[data-cy="recentOrderActions"]') + .find('[data-cy="column-filter-clientFk"]') + .find(' [data-cy="_select"]') + .click(); + cy.get('.q-menu :nth-child(1) >.q-item__section').click(); + cy.countTableRows('eq', 0); + + cy.get('[data-cy="recentOrderActions"]') + .find( + '[data-cy="column-filter-clientFk"] .q-field .q-field__control > :nth-child(2)', + ) + .click(); + cy.get('[data-cy="recentOrderActions"]') + .find('[data-cy="column-filter-departmentFk"]') + .find(' [data-cy="_select"]') + .click(); + cy.get('[data-cy="recentOrderActions"]') + .find('[data-cy="column-filter-departmentFk"]') + .find(' [data-cy="_select"]') + .type('VIP'); + cy.wait(1000); + cy.get('.q-menu :nth-child(1) >.q-item__section').click(); + cy.countTableRows('eq', 13); + + cy.get('[data-cy="recentOrderActions"]') + .find('[data-cy="column-filter-clientFk"]') + .find(' [data-cy="_select"]') + .click(); + cy.get('[data-cy="recentOrderActions"]') + .find('[data-cy="column-filter-clientFk"]') + .find(' [data-cy="_select"]') + .type('bru'); + cy.wait(1000); + cy.get('.q-menu :nth-child(1) >.q-item__section').click(); + cy.countTableRows('eq', 3); + }); +}); diff --git a/test/cypress/integration/monitor/monitorTicket.spec.js b/test/cypress/integration/monitor/monitorTicket.spec.js index a8e125368..0955679b1 100644 --- a/test/cypress/integration/monitor/monitorTicket.spec.js +++ b/test/cypress/integration/monitor/monitorTicket.spec.js @@ -12,15 +12,11 @@ describe('Monitor Tickets Table', () => { it('should open new tab when ctrl+click on client link', () => { cy.intercept('GET', '**/SalesMonitors/salesFilter*').as('filterRequest'); - // Mock window.open behavior since Cypress doesn't support multiple tabs cy.window().then((win) => { cy.stub(win, 'open').as('windowOpen'); }); - // Find and ctrl+click the client link in first row cy.get(firstRow('provinceFk')).click({ ctrlKey: true }); - - // Verify window.open was called with correct URL cy.get('@windowOpen').should('be.calledWithMatch', /\/ticket\/\d+\/sale/); }); it('should filter by column headers and update URL params', () => { @@ -42,101 +38,88 @@ describe('Monitor Tickets Table', () => { // Client id - clientFk cy.get('[data-cy="Client id_input"]').type('1101'); cy.searchInFilterPanel(); - requestParams('clientFk', '1101'); - countRows('eq', 7); + cy.url().should('include', 'clientFk'); + cy.countTableRows('eq', 7); // cy.cleanFilterPanel(); - // TODO: order id cy.get('[data-cy="Order id_input"]').type(7); cy.searchInFilterPanel(); - // requestParams('orderFk', '7'); cy.url().should('include', 'orderFk'); - countRows('eq', 1); + cy.countTableRows('eq', 1); // cy.cleanFilterPanel(); - // TODO: Scope days - // cy.get('[data-cy="Days onward_input"]').type(2); - // cy.searchInFilterPanel(); - // requestParams('scopeDays', '2'); - // countRows('eq', 27); + cy.get('[data-cy="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.searchInFilterPanel(); - // requestParams('nickname', 'test', { inWhere: true, like: false }); cy.url().should('include', 'nickname'); - countRows('eq', 2); + cy.countTableRows('eq', 2); // cy.cleanFilterPanel(); // Invoice cy.get('[data-cy="Invoice_input"]').type('test'); cy.searchInFilterPanel(); - // requestParams('refFk', 'test'); cy.url().should('include', 'refFk'); - countRows('eq', 0); + cy.countTableRows('eq', 0); // cy.cleanFilterPanel(); // Agency cy.get('[data-cy="Agency_select"]').click(); cy.get('.q-item__label').contains('inhouse pickup').click(); cy.searchInFilterPanel(); - // requestParams('agencyModeFk', '1'); cy.url().should('include', 'agencyModeFk'); - countRows('eq', 6); + cy.countTableRows('eq', 6); // cy.cleanFilterPanel(); // State cy.get('[data-cy="State_select"]').click(); cy.get('.q-item__label').contains('Libre').click(); cy.searchInFilterPanel(); - // requestParams('ts.stateFk', 2, { inWhere: true }); cy.url().should('include', 'stateFk'); - countRows('eq', 11); + cy.countTableRows('eq', 13); // cy.cleanFilterPanel(); // AlertLevel cy.get('[data-cy="Grouped State_select"]').click(); cy.get('.q-item__label').contains('Free').click(); cy.searchInFilterPanel(); - // requestParams('alertLevel', '0'); cy.url().should('include', 'alertLevel'); - countRows('eq', 16); + cy.countTableRows('eq', 18); // cy.cleanFilterPanel(); // Country cy.get('[data-cy="Country_select"]').click(); cy.get('.q-item__label').contains('España').click(); cy.searchInFilterPanel(); - // requestParams('countryFk', '1'); cy.url().should('include', 'countryFk'); - countRows('eq', 26); + cy.countTableRows('eq', 28); // cy.cleanFilterPanel(); // Province cy.get('[data-cy="Warehouse_select"]').click(); cy.get('.q-item__label').contains('Warehouse Two').click(); cy.searchInFilterPanel(); - // requestParams('warehouseFk', '2'); cy.url().should('include', 'warehouseFk'); - countRows('eq', 1); + cy.countTableRows('eq', 1); // cy.cleanFilterPanel(); // Department cy.selectOption('[data-cy="Department_select"]', 'EQUIPO ESPAÑA LEVANTE'); cy.searchInFilterPanel(); - // requestParams('departmentFk', '150'); cy.url().should('include', 'departmentFk'); - // countRows('eq', 27); // cy.cleanFilterPanel(); // ITP cy.get('[data-cy="ITP_select"]').click(); cy.get('.q-item__label').contains('H').click(); cy.searchInFilterPanel(); - // requestParams('packing', 'H'); cy.url().should('include', 'packing'); - countRows('eq', 5); + cy.countTableRows('eq', 5); }); it('Cols', () => { @@ -194,36 +177,3 @@ function checkScopeDays(scopeDays) { ); }); } -function requestParams(key, value, options = { inWhere: false, like: false }) { - cy.wait('@filterRequest').then((interception) => { - if (!key) return; - const { query } = interception.request; - if (!options.inWhere) expect(query).to.have.property(key, value); - else { - const filter = JSON.parse(query.filter); - if (options.like) - expect(filter.where).to.have.deep.property(key, { - like: `%${value}%`, - }); - else { - expect(filter).to.have.property('where'); - expect(filter.where).to.have.property(key, value); - } - } - }); -} -function countRows(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); - }); - }); -} -- 2.40.1 From 351f291086fdc09879410037e119bf76bf012a69 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 24 Mar 2025 11:15:25 +0100 Subject: [PATCH 15/31] test: remove timeout --- .../integration/monitor/clientActions.spec.js | 62 ++++++++----------- .../integration/monitor/monitorTicket.spec.js | 17 +++-- .../vnComponent/vnSelect.commands.js | 3 + 3 files changed, 37 insertions(+), 45 deletions(-) create mode 100644 test/cypress/integration/vnComponent/vnSelect.commands.js diff --git a/test/cypress/integration/monitor/clientActions.spec.js b/test/cypress/integration/monitor/clientActions.spec.js index f413332f3..5208c6410 100644 --- a/test/cypress/integration/monitor/clientActions.spec.js +++ b/test/cypress/integration/monitor/clientActions.spec.js @@ -1,3 +1,5 @@ +const clientFk = `[data-cy="recentOrderActions"] [data-cy="column-filter-clientFk"]`; +const departmentFk = `[data-cy="recentOrderActions"] [data-cy="column-filter-departmentFk"]`; describe('Monitor Clients actions', () => { beforeEach(() => { cy.login('developer'); @@ -6,12 +8,19 @@ describe('Monitor Clients actions', () => { cy.intercept('GET', '**/SalesMonitors/ordersFilter*').as('ordersFilter'); cy.intercept('GET', '**/SalesMonitors/clientsFilter*').as('clientsFilter'); }); - it.only('Should load layout', () => { + it('Should load layout', () => { cy.get('.q-page').should('be.visible'); - cy.firstRow('clientFk').find('span').should('have.class', 'link').click(); + cy.dataCy('recentOrderActions').within(() => { + cy.firstRow('clientFk').find('span').should('have.class', 'link').click(); + }); cy.dataCy('CustomerDescriptor').should('exist'); - cy.firstRow('departmentFk', 2).find('span').should('have.class', 'link').click(); + cy.dataCy('recentOrderActions').within(() => { + cy.firstRow('departmentFk', 2) + .find('span') + .should('have.class', 'link') + .click(); + }); cy.dataCy('DepartmentDescriptor').should('exist'); cy.dataCy('clientsOnWebsite') @@ -22,40 +31,23 @@ describe('Monitor Clients actions', () => { .should('have.text', 'Recent order actions'); cy.get('[data-cy="From_inputDate"]').should('have.value', '01/01/2001'); cy.get('[data-cy="To_inputDate"]').should('have.value', '01/01/2001'); - cy.get('[data-cy="recentOrderActions"]') - .find('[data-cy="column-filter-clientFk"]') - .find(' [data-cy="_select"]') - .click(); - cy.get('.q-menu :nth-child(1) >.q-item__section').click(); + cy.get(`${clientFk} [data-cy="_select"]`).click(); + cy.clickOption(); cy.countTableRows('eq', 0); - cy.get('[data-cy="recentOrderActions"]') - .find( - '[data-cy="column-filter-clientFk"] .q-field .q-field__control > :nth-child(2)', - ) - .click(); - cy.get('[data-cy="recentOrderActions"]') - .find('[data-cy="column-filter-departmentFk"]') - .find(' [data-cy="_select"]') - .click(); - cy.get('[data-cy="recentOrderActions"]') - .find('[data-cy="column-filter-departmentFk"]') - .find(' [data-cy="_select"]') - .type('VIP'); - cy.wait(1000); - cy.get('.q-menu :nth-child(1) >.q-item__section').click(); - cy.countTableRows('eq', 13); + cy.get(`${clientFk} .q-field .q-field__control > :nth-child(2)`).click(); + cy.get(`${departmentFk} [data-cy="_select"]`).type('VIP').trigger('enter'); + cy.intercept('GET', '**/Departments*').as('filterDepartment'); + cy.wait('@filterDepartment').then(() => { + cy.clickOption(); + cy.countTableRows('eq', 13); + }); - cy.get('[data-cy="recentOrderActions"]') - .find('[data-cy="column-filter-clientFk"]') - .find(' [data-cy="_select"]') - .click(); - cy.get('[data-cy="recentOrderActions"]') - .find('[data-cy="column-filter-clientFk"]') - .find(' [data-cy="_select"]') - .type('bru'); - cy.wait(1000); - cy.get('.q-menu :nth-child(1) >.q-item__section').click(); - cy.countTableRows('eq', 3); + cy.get(`${clientFk} [data-cy="_select"]`).type('Bruce Banner'); + cy.intercept('GET', '**/Clients*').as('filterClient'); + cy.wait('@filterClient').then(() => { + cy.clickOption(); + cy.countTableRows('eq', 3); + }); }); }); diff --git a/test/cypress/integration/monitor/monitorTicket.spec.js b/test/cypress/integration/monitor/monitorTicket.spec.js index 0955679b1..d34561271 100644 --- a/test/cypress/integration/monitor/monitorTicket.spec.js +++ b/test/cypress/integration/monitor/monitorTicket.spec.js @@ -19,20 +19,17 @@ describe('Monitor Tickets Table', () => { cy.get(firstRow('provinceFk')).click({ ctrlKey: true }); cy.get('@windowOpen').should('be.calledWithMatch', /\/ticket\/\d+\/sale/); }); - it('should filter by column headers and update URL params', () => { + it.only('should filter by column headers and update URL params', () => { cy.intercept('GET', '**/SalesMonitors/salesFilter*').as('filterRequest'); - cy.dataCy('column-filter-id').find(' [data-cy="_input"]').type('13'); + cy.dataCy('column-filter-id').find('[data-cy="_input"]').type('13'); cy.dataCy('column-filter-id').find(' .q-icon').click(); cy.openRightMenu(); - cy.dataCy('column-filter-clientFk') - .find('[data-cy="_select"]', { timeout: 3000 }) - .type('1101', { timeout: 3000, force: true }); - cy.get('[role="listbox"]') - .find('.q-item') - .find('.q-item__label') - .contains('Bruce Wayne') - .click(); + cy.dataCy('column-filter-clientFk').find('[data-cy="_select"]').type('1101'); + cy.intercept('GET', '**/Clients*').as('filterClient'); + cy.wait('@filterClient').then(() => { + cy.clickOption(); + }); }); it('should filter by filter panel', () => { // Client id - clientFk diff --git a/test/cypress/integration/vnComponent/vnSelect.commands.js b/test/cypress/integration/vnComponent/vnSelect.commands.js new file mode 100644 index 000000000..017b6e7ea --- /dev/null +++ b/test/cypress/integration/vnComponent/vnSelect.commands.js @@ -0,0 +1,3 @@ +Cypress.Commands.add('clickOption', (index = 1) => + cy.get(`.q-menu :nth-child(${index}) >.q-item__section`).click(), +); -- 2.40.1 From 38d16b56a942cacc1e442293943dd75cf2978150 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 26 Mar 2025 10:12:13 +0100 Subject: [PATCH 16/31] feat: remove FetchData --- src/pages/Monitor/Ticket/MonitorTickets.vue | 101 +++++------------- .../integration/monitor/monitorTicket.spec.js | 2 +- 2 files changed, 30 insertions(+), 73 deletions(-) diff --git a/src/pages/Monitor/Ticket/MonitorTickets.vue b/src/pages/Monitor/Ticket/MonitorTickets.vue index 03d751595..aa25fb969 100644 --- a/src/pages/Monitor/Ticket/MonitorTickets.vue +++ b/src/pages/Monitor/Ticket/MonitorTickets.vue @@ -1,7 +1,6 @@