diff --git a/test/cypress/support/commands.js b/test/cypress/support/commands.js index 3eb5024a7..a36a4f8cd 100755 --- a/test/cypress/support/commands.js +++ b/test/cypress/support/commands.js @@ -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(); +});