diff --git a/test/cypress/integration/invoiceIn/invoiceInDescriptor.spec.js b/test/cypress/integration/invoiceIn/invoiceInDescriptor.spec.js index 382a5f7f8..e24aa2bcc 100644 --- a/test/cypress/integration/invoiceIn/invoiceInDescriptor.spec.js +++ b/test/cypress/integration/invoiceIn/invoiceInDescriptor.spec.js @@ -84,39 +84,33 @@ describe('InvoiceInDescriptor', () => { }); }); - describe.only('corrective', () => { + describe('corrective', () => { + const originalId = 1; + beforeEach(() => { cy.login('administrative'); - }); - it('should create a correcting invoice and redirect to original invoice', () => { - const originalId = 1; cy.visit(`/#/invoice-in/${originalId}/summary`); - cy.intercept('POST', '/api/InvoiceIns/corrective').as('corrective'); + }); - const regex = new RegExp(`InvoiceIns/${originalId}\\?filter=.*`); - cy.intercept('GET', regex).as('getOriginal'); - createCorrective({ class: 'R5', type: 'sustituciĆ³n', reason: 'VAT' }); - cy.wait('@corrective').then(({ response }) => { - const correctingId = response.body; - cy.url().should('include', `/invoice-in/${correctingId}/summary`); - cy.visit(`/#/invoice-in/${correctingId}/corrective`); - cy.dataCy('invoiceInCorrective_class').should('contain.value', 'R'); - cy.dataCy('invoiceInCorrective_type').should('contain.value', type); - cy.dataCy('invoiceInCorrective_reason').should('contain.value', reason); + it('should create a correcting invoice and redirect to original invoice', () => { + createCorrective(originalId, { + class: 'R5', + type: 'sustituciĆ³n', + reason: 'VAT', }); redirect(originalId); }); it('should create a correcting invoice and navigate to list filtered by corrective', () => { - const originalId = 1; - cy.visit(`/#/invoice-in/${originalId}/summary`); - const regex = new RegExp(`InvoiceIns/${originalId}\\?filter=.*`); - cy.intercept('GET', regex).as('getOriginal'); - createCorrective({ class: 'R3', type: 'diferencias', reason: 'customer' }); - + createCorrective(originalId, { + class: 'R3', + type: 'diferencias', + reason: 'customer', + }); redirect(originalId); + cy.clicDescriptorAction(4); - cy.url().should('to.match', /invoice-in\/list\?table=\{.*correctedFk*\}/); + cy.checkQueryParams({ table: { subkey: 'correctedFk', val: originalId } }); cy.validateVnTableRows({ cols: [ { @@ -130,13 +124,26 @@ describe('InvoiceInDescriptor', () => { }); }); -function createCorrective(opts = {}) { +function createCorrective(originalId, opts = {}) { + const regex = new RegExp(`InvoiceIns/${originalId}\\?filter=.*`); + cy.intercept('POST', '/api/InvoiceIns/corrective').as('corrective'); + cy.intercept('GET', regex).as('getOriginal'); const { type, reason, class: classVal } = opts; + cy.selectDescriptorOption(4); cy.selectOption('[data-cy="invoiceInDescriptorMenu_class"]', classVal); cy.selectOption('[data-cy="invoiceInDescriptorMenu_type"]', type); cy.selectOption('[data-cy="invoiceInDescriptorMenu_reason"]', reason); cy.dataCy('saveCorrectiveInvoice').click(); + + cy.wait('@corrective').then(({ response }) => { + const correctingId = response.body; + cy.url().should('include', `/invoice-in/${correctingId}/summary`); + cy.visit(`/#/invoice-in/${correctingId}/corrective`); + cy.dataCy('invoiceInCorrective_class').should('contain.value', classVal); + cy.dataCy('invoiceInCorrective_type').should('contain.value', type); + cy.dataCy('invoiceInCorrective_reason').should('contain.value', reason); + }); } function redirect(subtitle) { diff --git a/test/cypress/support/commands.js b/test/cypress/support/commands.js index 0a81648c0..5bc2d7116 100755 --- a/test/cypress/support/commands.js +++ b/test/cypress/support/commands.js @@ -563,3 +563,19 @@ Cypress.Commands.add('validatePdfDownload', (match, trigger) => { Cypress.Commands.add('clicDescriptorAction', (index = 1) => { cy.get(`[data-cy="descriptor_actions"] .q-btn:nth-of-type(${index})`).click(); }); + +Cypress.Commands.add('checkQueryParams', (expectedParams = {}) => { + cy.url().then((url) => { + const urlParams = new URLSearchParams(url.split('?')[1]); + + for (const key in expectedParams) { + const expected = expectedParams[key]; + const param = JSON.parse(decodeURIComponent(urlParams.get(key))); + + if (typeof expected === 'object') { + const { subkey, val } = expected; + expect(param[subkey]).to.equal(val); + } else expect(param).to.equal(expected); + } + }); +});