Skip to content

Commit

Permalink
Fix: Prevent overwrite of cached page on presentation preview init (#916
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Jeremy Press authored Feb 11, 2019
1 parent 214e366 commit 9256dcc
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"create-react-class": "^15.6.2",
"css-loader": "^0.28.7",
"cssnano-cli": "^1.0.5",
"cypress": "^3.1.4",
"cypress": "^3.1.5",
"eslint": "^4.12.1",
"eslint-config-airbnb": "^16.1.0",
"eslint-config-prettier": "^2.9.0",
Expand Down
9 changes: 1 addition & 8 deletions src/lib/viewers/doc/PresentationViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,7 @@ class PresentationViewer extends DocBaseViewer {
*/
overwritePdfViewerBehavior() {
// Overwrite scrollPageIntoView for presentations since we have custom pagination behavior
this.pdfViewer.scrollPageIntoView = (pageObj) => {
let pageNum = pageObj;
if (typeof pageNum !== 'number') {
pageNum = pageObj.pageNumber || 1;
}

this.setPage(pageNum);
};
this.pdfViewer.scrollPageIntoView = () => {};

// Overwrite _getVisiblePages for presentations to always calculate instead of fetching visible
// elements since we lay out presentations differently
Expand Down
3 changes: 1 addition & 2 deletions src/lib/viewers/doc/__tests__/PresentationViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,12 +496,11 @@ describe('lib/viewers/doc/PresentationViewer', () => {
const page = {
pageNumber: 3
};
Object.defineProperty(DocBaseViewer.prototype, 'initViewer', { value: sandbox.stub() });

presentation.overwritePdfViewerBehavior();
presentation.pdfViewer.scrollPageIntoView(page);

expect(setPageStub).to.be.calledWith(page.pageNumber);
expect(setPageStub).to.not.be.called;
});

it('should overwrite the _getVisiblePages method', () => {
Expand Down
19 changes: 6 additions & 13 deletions test/integration/document/Controls.e2e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ describe('Preview Document Controls', () => {
const token = Cypress.env('ACCESS_TOKEN');
const fileId = Cypress.env('FILE_ID_DOC');

/* eslint-disable */
const showControls = () => {
cy.getByTestId('bp').trigger('mouseover');
cy.getByTestId('controls-wrapper').should('be.visible');
};
/* eslint-enable */

beforeEach(() => {
cy.visit('/');
cy.showPreview(token, fileId);
Expand All @@ -25,7 +18,7 @@ describe('Preview Document Controls', () => {
cy.wrap($page[0].scrollHeight).as('originalHeight');
});

showControls();
cy.showControls();

cy.getByTitle('Zoom out').click();

Expand All @@ -40,7 +33,7 @@ describe('Preview Document Controls', () => {
cy.wrap(zoomedOutHeight).as('zoomedOutHeight');
});

showControls();
cy.showControls();

cy.getByTitle('Zoom in').click();

Expand All @@ -58,14 +51,14 @@ describe('Preview Document Controls', () => {
cy.contains('The Content Platform for Your Apps');
cy.get('@currentPage').invoke('text').should('equal', '1');

showControls();
cy.showControls();
cy.getByTitle('Next page').click();

cy.getPreviewPage(2).should('be.visible');
cy.contains('Discover how your business can use Box Platform');
cy.get('@currentPage').invoke('text').should('equal', '2');

showControls();
cy.showControls();
cy.getByTitle('Previous page').click();

cy.getPreviewPage(1).should('be.visible');
Expand All @@ -78,7 +71,7 @@ describe('Preview Document Controls', () => {
cy.contains('The Content Platform for Your Apps');
cy.get('@currentPage').invoke('text').should('equal', '1');

showControls();
cy.showControls();
cy.getByTitle('Click to enter page number').click();
cy.getByTestId('page-num-input').should('be.visible').type('2').blur();

Expand All @@ -94,7 +87,7 @@ describe('Preview Document Controls', () => {
// it('Should handle going fullscreen', () => {
// cy.getPreviewPage(1).should('be.visible');
// cy.contains('The Content Platform for Your Apps');
// showControls();
// cy.showControls();
// cy.getByTitle('Enter fullscreen').should('be.visible').click();
// cy.getByTitle('Exit fullscreen').should('be.visible');
// });
Expand Down
28 changes: 28 additions & 0 deletions test/integration/document/PresentationViewer.e2e.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// <reference types="Cypress" />
describe('Presentation Viewer', () => {
const token = Cypress.env('ACCESS_TOKEN');
const fileId = Cypress.env('FILE_ID_PRESENTATION');


beforeEach(() => {
cy.visit('/');
cy.showPreview(token, fileId);
});

it('Should initialize preview on the same page it was closed on', () => {
// Assert document content is present
cy.contains('For Teaching Economics');

cy.showControls();

// Navigate to the second page so it gets cached
cy.getByTitle('Next page').click();

// Refreshes preview
cy.reload();

cy.getPreviewPage(2).should('be.visible');

});

});
6 changes: 6 additions & 0 deletions test/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ Cypress.Commands.add('showPreview', (token, fileId, options) => {
// Wait for .bp to load viewer
return cy.getByTestId('bp').should('have.class', 'bp-loaded');
});


Cypress.Commands.add('showControls', () => {
cy.getByTestId('bp').trigger('mouseover');
cy.getByTestId('controls-wrapper').should('be.visible');
})
2 changes: 2 additions & 0 deletions test/support/constants.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Cypress.env({
ACCESS_TOKEN: 'edRiUpeLD9A1nLyWqc1gZOt2OnSNNYp9',
FILE_ID_DOC: '287707140303',
FILE_ID_PRESENTATION: '286114524434',
FILE_ID_MP3: '286509191779',
FILE_ID_VIDEO: '286114565199',
FILE_ID_VIDEO_SUBTITLES_TRACKS: '286840567797',
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2945,7 +2945,7 @@ custom-event@~1.0.0:
resolved "https://registry.yarnpkg.com/custom-event/-/custom-event-1.0.1.tgz#5d02a46850adf1b4a317946a3928fccb5bfd0425"
integrity sha1-XQKkaFCt8bSjF5RqOSj8y1v9BCU=

cypress@^3.1.4:
cypress@^3.1.5:
version "3.1.5"
resolved "https://registry.yarnpkg.com/cypress/-/cypress-3.1.5.tgz#5227b2ce9306c47236d29e703bad9055d7218042"
integrity sha512-jzYGKJqU1CHoNocPndinf/vbG28SeU+hg+4qhousT/HDBMJxYgjecXOmSgBX/ga9/TakhqSrIrSP2r6gW/OLtg==
Expand Down

0 comments on commit 9256dcc

Please sign in to comment.