feat: refs #8581 add validation commands for file downloads and PDF checks in Cypress tests

This commit is contained in:
Jorge Penadés 2025-02-28 09:25:04 +01:00
parent 4e87c596d1
commit 415c6f2177
1 changed files with 36 additions and 0 deletions

View File

@ -515,3 +515,39 @@ Cypress.Commands.add('selectDescriptorOption', (opt = 1) => {
Cypress.Commands.add('validateCheckbox', (selector, expectedVal = 'true') => {
cy.get(selector).should('have.attr', 'aria-checked', expectedVal.toString());
});
Cypress.Commands.add('validateDownload', (trigger, opts = {}) => {
const {
url = /api\/dms\/\d+\/downloadFile\?access_token=.+/,
type = 'text/plain',
alias = 'download',
} = opts;
cy.intercept('GET', url).as(alias);
trigger();
cy.wait(`@${alias}`).then(({ response }) => {
expect(response.statusCode).to.equal(200);
expect(response.headers['content-type']).to.include(type);
});
});
Cypress.Commands.add('validatePdfDownload', (match, trigger) => {
cy.window().then((win) => {
cy.stub(win, 'open')
.callsFake(() => null)
.as('pdf');
});
trigger();
cy.get('@pdf')
.should('be.calledOnce')
.then((stub) => {
const [url] = stub.getCall(0).args;
expect(url).to.match(match);
cy.request(url).then((response) =>
expect(response.headers['content-type']).to.include('application/pdf'),
);
});
});
Cypress.Commands.add('clicDescriptorAction', (index = 1) => {
cy.get(`[data-cy="descriptor_actions"] .q-btn:nth-of-type(${index})`).click();
});