Skip to content

Commit

Permalink
Chore: end to end test
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Press committed Mar 25, 2019
1 parent 0139cd9 commit c295026
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@

<div class='preview-container' data-testid="preview-container"> </div>
<script>
// Create preview first so events can be bound before 'show'
/* global Box */
preview = new Box.Preview();

function setProperty(selector) {
// Get new value, fallback to local storage
var inputValue = document.querySelector('#' + selector + '-set')
Expand All @@ -91,10 +95,8 @@
return;
}

/* global Box */
preview = new Box.Preview();

var previewOptions = options || {
apiHost: 'https://api.jpress.inside-box.net/',
enableThumbnailsSidebar: true,
showAnnotations: true,
showDownload: true,
Expand Down
62 changes: 62 additions & 0 deletions test/integration/sanity/DeletedReps.e2e.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// <reference types="Cypress" />
describe('Previewing a file with Deleted Representations', () => {
const token = Cypress.env('ACCESS_TOKEN');

const fileIdDoc = Cypress.env('FILE_ID_DOC');
const presentationIdDoc = Cypress.env('FILE_ID_PRESENTATION');

const REPS_ERROR = 'error_deleted_reps';

const helpers = {
checkDeletedRepError: () => {
cy.window().then((win) => {
win.preview.addListener('preview_error', (data) => {
cy.expect(data.error.code).to.equal(REPS_ERROR);
})
});
}
}

beforeEach(() => {
cy.server();
// Make the representation content call to always return a 202 with no body

// Mocking requests for non original reps
cy.route({
method: 'GET',
url: '**/internal_files/**',
status: 202,
response: {}
}).as('bar');

// Mocking requests for original reps
cy.route({
method: 'GET',
url: '**/content?**',
status: 202,
response: {}
}).as('bas');

cy.visit('/', {
onBeforeLoad (win) {
// Workaround for fetch detection in cypress mocking. https://github.com/cypress-io/cypress/issues/95
delete win.fetch //eslint-disable-line
}
})
});

describe('Document Viewers', () => {
it('Should correctly handle a document with deleted reps', () => {
helpers.checkDeletedRepError();

cy.showPreview(token, fileIdDoc, { showAnnotations: false });

});

it('Should correctly handle a presentation with deleted reps', () => {
helpers.checkDeletedRepError();

cy.showPreview(token, presentationIdDoc, { showAnnotations: false });
});
});
});

0 comments on commit c295026

Please sign in to comment.