feat: refs #8581 add validation commands for file downloads and PDF checks in Cypress tests
This commit is contained in:
parent
4e87c596d1
commit
415c6f2177
|
@ -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();
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue