feat: refs #8581 add checkQueryParams command to validate URL query parameters
gitea/salix-front/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Jorge Penadés 2025-03-05 12:28:43 +01:00
parent 7b4b5c892a
commit 9b04fc3bc8
2 changed files with 46 additions and 23 deletions

View File

@ -84,39 +84,33 @@ describe('InvoiceInDescriptor', () => {
}); });
}); });
describe.only('corrective', () => { describe('corrective', () => {
const originalId = 1;
beforeEach(() => { beforeEach(() => {
cy.login('administrative'); cy.login('administrative');
});
it('should create a correcting invoice and redirect to original invoice', () => {
const originalId = 1;
cy.visit(`/#/invoice-in/${originalId}/summary`); cy.visit(`/#/invoice-in/${originalId}/summary`);
cy.intercept('POST', '/api/InvoiceIns/corrective').as('corrective'); });
const regex = new RegExp(`InvoiceIns/${originalId}\\?filter=.*`); it('should create a correcting invoice and redirect to original invoice', () => {
cy.intercept('GET', regex).as('getOriginal'); createCorrective(originalId, {
createCorrective({ class: 'R5', type: 'sustitución', reason: 'VAT' }); class: 'R5',
cy.wait('@corrective').then(({ response }) => { type: 'sustitución',
const correctingId = response.body; reason: 'VAT',
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);
}); });
redirect(originalId); redirect(originalId);
}); });
it('should create a correcting invoice and navigate to list filtered by corrective', () => { it('should create a correcting invoice and navigate to list filtered by corrective', () => {
const originalId = 1; createCorrective(originalId, {
cy.visit(`/#/invoice-in/${originalId}/summary`); class: 'R3',
const regex = new RegExp(`InvoiceIns/${originalId}\\?filter=.*`); type: 'diferencias',
cy.intercept('GET', regex).as('getOriginal'); reason: 'customer',
createCorrective({ class: 'R3', type: 'diferencias', reason: 'customer' }); });
redirect(originalId); redirect(originalId);
cy.clicDescriptorAction(4); cy.clicDescriptorAction(4);
cy.url().should('to.match', /invoice-in\/list\?table=\{.*correctedFk*\}/); cy.checkQueryParams({ table: { subkey: 'correctedFk', val: originalId } });
cy.validateVnTableRows({ cy.validateVnTableRows({
cols: [ 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; const { type, reason, class: classVal } = opts;
cy.selectDescriptorOption(4); cy.selectDescriptorOption(4);
cy.selectOption('[data-cy="invoiceInDescriptorMenu_class"]', classVal); cy.selectOption('[data-cy="invoiceInDescriptorMenu_class"]', classVal);
cy.selectOption('[data-cy="invoiceInDescriptorMenu_type"]', type); cy.selectOption('[data-cy="invoiceInDescriptorMenu_type"]', type);
cy.selectOption('[data-cy="invoiceInDescriptorMenu_reason"]', reason); cy.selectOption('[data-cy="invoiceInDescriptorMenu_reason"]', reason);
cy.dataCy('saveCorrectiveInvoice').click(); 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) { function redirect(subtitle) {

View File

@ -563,3 +563,19 @@ Cypress.Commands.add('validatePdfDownload', (match, trigger) => {
Cypress.Commands.add('clicDescriptorAction', (index = 1) => { Cypress.Commands.add('clicDescriptorAction', (index = 1) => {
cy.get(`[data-cy="descriptor_actions"] .q-btn:nth-of-type(${index})`).click(); 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);
}
});
});