From 9256dcc6e4b1fd43373360cdd39ca10656a14fea Mon Sep 17 00:00:00 2001 From: Jeremy Press Date: Mon, 11 Feb 2019 12:59:28 -0800 Subject: [PATCH] Fix: Prevent overwrite of cached page on presentation preview init (#916) --- package.json | 2 +- src/lib/viewers/doc/PresentationViewer.js | 9 +----- .../doc/__tests__/PresentationViewer-test.js | 3 +- .../integration/document/Controls.e2e.test.js | 19 ++++--------- .../document/PresentationViewer.e2e.test.js | 28 +++++++++++++++++++ test/support/commands.js | 6 ++++ test/support/constants.js | 2 ++ yarn.lock | 2 +- 8 files changed, 46 insertions(+), 25 deletions(-) create mode 100644 test/integration/document/PresentationViewer.e2e.test.js diff --git a/package.json b/package.json index 9a87cd746..ee9c561ec 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/lib/viewers/doc/PresentationViewer.js b/src/lib/viewers/doc/PresentationViewer.js index cf282d4b4..c355c1516 100644 --- a/src/lib/viewers/doc/PresentationViewer.js +++ b/src/lib/viewers/doc/PresentationViewer.js @@ -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 diff --git a/src/lib/viewers/doc/__tests__/PresentationViewer-test.js b/src/lib/viewers/doc/__tests__/PresentationViewer-test.js index 68ed995a8..4823e600d 100644 --- a/src/lib/viewers/doc/__tests__/PresentationViewer-test.js +++ b/src/lib/viewers/doc/__tests__/PresentationViewer-test.js @@ -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', () => { diff --git a/test/integration/document/Controls.e2e.test.js b/test/integration/document/Controls.e2e.test.js index 2cf7c2bc7..9d3c282b2 100644 --- a/test/integration/document/Controls.e2e.test.js +++ b/test/integration/document/Controls.e2e.test.js @@ -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); @@ -25,7 +18,7 @@ describe('Preview Document Controls', () => { cy.wrap($page[0].scrollHeight).as('originalHeight'); }); - showControls(); + cy.showControls(); cy.getByTitle('Zoom out').click(); @@ -40,7 +33,7 @@ describe('Preview Document Controls', () => { cy.wrap(zoomedOutHeight).as('zoomedOutHeight'); }); - showControls(); + cy.showControls(); cy.getByTitle('Zoom in').click(); @@ -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'); @@ -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(); @@ -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'); // }); diff --git a/test/integration/document/PresentationViewer.e2e.test.js b/test/integration/document/PresentationViewer.e2e.test.js new file mode 100644 index 000000000..438ceae5c --- /dev/null +++ b/test/integration/document/PresentationViewer.e2e.test.js @@ -0,0 +1,28 @@ +// +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'); + + }); + +}); diff --git a/test/support/commands.js b/test/support/commands.js index 086d12ba2..6e9f5b920 100644 --- a/test/support/commands.js +++ b/test/support/commands.js @@ -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'); +}) diff --git a/test/support/constants.js b/test/support/constants.js index 1bf5d323f..35fb46b31 100644 --- a/test/support/constants.js +++ b/test/support/constants.js @@ -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', diff --git a/yarn.lock b/yarn.lock index 5a98986a4..1344f23e3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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==