Skip to content

Commit

Permalink
Fix: startAt should disable document preload (#714)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanDeMicco authored Mar 13, 2018
1 parent ac73b92 commit 8c38180
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/lib/viewers/doc/DocBaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,13 @@ class DocBaseViewer extends BaseViewer {
const { file } = this.options;
const isWatermarked = file && file.watermark_info && file.watermark_info.is_watermarked;

// Don't show preload if there's a cached page since preloads are only for the 1st page
// Don't show preload if there's a cached page or startAt is set and > 1 since preloads are only for the 1st page
// Also don't show preloads for watermarked files
if (!this.preloader || isWatermarked || this.getCachedPage() !== 1) {
if (
!this.preloader ||
isWatermarked ||
((this.startPageNum && this.startPageNum !== 1) || this.getCachedPage() !== 1)
) {
return;
}

Expand Down
14 changes: 11 additions & 3 deletions src/lib/viewers/doc/__tests__/DocBaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,14 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
docBase.showPreload();
});

it('should not do anything if startAt is not page 1', () => {
sandbox.stub(docBase, 'getCachedPage').returns(1);
docBase.startPageNum = 3;
sandbox.mock(docBase.preloader).expects('showPreload').never();

docBase.showPreload();
});

it('should not do anything if file is watermarked', () => {
docBase.options.file = {
watermark_info: {
Expand Down Expand Up @@ -870,17 +878,17 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
expect(docBase.startLoadTimer).to.be.called;

});

it('should handle any download error', () => {
stubs.handleDownloadError = sandbox.stub(docBase, 'handleDownloadError');
const doc = {
url: 'url'
};

docBase.options.location = {
locale: 'en-US'
};

const getDocumentStub = sandbox.stub(PDFJS, 'getDocument').returns(Promise.reject(doc));

return docBase.initViewer('url').catch(() => {
Expand Down

0 comments on commit 8c38180

Please sign in to comment.