Skip to content

Commit

Permalink
fix: adding e2e test instead for download errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Priyajeet Hora committed Oct 10, 2019
1 parent a7da11e commit 9f36375
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib/viewers/error/PreviewErrorViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ class PreviewErrorViewer extends BaseViewer {
addDownloadButton() {
this.downloadBtnEl = this.infoEl.appendChild(document.createElement('button'));
this.downloadBtnEl.className = 'bp-btn bp-btn-primary';
this.downloadBtnEl.dataset.testid = 'preview-error-download-btn';
this.downloadBtnEl.textContent = __('download');
this.downloadBtnEl.addEventListener('click', this.download);
}
Expand Down
39 changes: 39 additions & 0 deletions test/integration/sanity/Download.e2e.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// <reference types='Cypress' />
describe('Download disabled while preview is already open', () => {
const token = Cypress.env('ACCESS_TOKEN');
const fileIdBad = Cypress.env('FILE_ID_BAD');

beforeEach(() => {
cy.visit('/');
});

it('should give generic download error when trying to download and its forbidden', () => {
cy.showPreview(token, fileIdBad, { showDownload: true });
cy.route({
method: 'GET',
url: `**/files/${fileIdBad}?fields=download_url`,
status: 403,
response: {},
});

cy.getByTestId('preview-error-download-btn').should('be.visible');
cy.getByTestId('preview-error-download-btn').click();
cy.contains('Sorry! You can’t download this file.');
});

it('should give shield error when trying to download and access policy prevents download', () => {
cy.showPreview(token, fileIdBad, { showDownload: true });
cy.route({
method: 'GET',
url: `**/files/${fileIdBad}?fields=download_url`,
status: 403,
response: {
code: 'forbidden_by_policy',
},
});

cy.getByTestId('preview-error-download-btn').should('be.visible');
cy.getByTestId('preview-error-download-btn').click();
cy.contains('Downloading of this content has been disabled based on an access policy.');
});
});

0 comments on commit 9f36375

Please sign in to comment.