Skip to content

Commit

Permalink
fix(doc zoom): Move zoom control update to pagerender handler (#1097)
Browse files Browse the repository at this point in the history
  • Loading branch information
ConradJChan authored Nov 11, 2019
1 parent b04e7e6 commit 085131e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/lib/viewers/doc/DocBaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,6 @@ class DocBaseViewer extends BaseViewer {
});
}
this.pdfViewer.currentScaleValue = newScale;
this.zoomControls.setCurrentScale(newScale);
}

/**
Expand Down Expand Up @@ -1176,6 +1175,8 @@ class DocBaseViewer extends BaseViewer {
return;
}

this.zoomControls.setCurrentScale(this.pdfViewer.currentScale);

// Page rendered event
this.emit('pagerender', pageNumber);

Expand Down
13 changes: 8 additions & 5 deletions src/lib/viewers/doc/__tests__/DocBaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -921,10 +921,6 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
docBase.pdfViewer = {
currentScale: 8.9,
};
docBase.zoomControls = {
setCurrentScale: sandbox.stub(),
removeListener: sandbox.stub(),
};
stubs.emit = sandbox.stub(docBase, 'emit');
});

Expand All @@ -940,7 +936,6 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
docBase.pdfViewer.currentScale = 1;
docBase.zoomIn(1);
expect(docBase.pdfViewer.currentScaleValue).to.equal(DEFAULT_SCALE_DELTA);
expect(docBase.zoomControls.setCurrentScale).to.have.been.calledWith(DEFAULT_SCALE_DELTA);
});

it('should emit the zoom event', () => {
Expand Down Expand Up @@ -1804,6 +1799,10 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
currentScale: 0.5,
currentScaleValue: 0.5,
};
docBase.zoomControls = {
setCurrentScale: sandbox.stub(),
removeListener: sandbox.stub(),
};
docBase.event = {
pageNumber: 1,
};
Expand All @@ -1819,11 +1818,13 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
docBase.pagerenderedHandler(docBase.event);
expect(stubs.emit).to.be.calledWith('pagerender');
expect(stubs.emit).to.be.calledWith('scale', { pageNum: 1, scale: 0.5 });
expect(docBase.zoomControls.setCurrentScale).to.be.calledWith(docBase.pdfViewer.currentScale);
});

it('should emit handleAssetAndRepLoad event if not already emitted', () => {
docBase.pagerenderedHandler(docBase.event);
expect(stubs.emit).to.be.calledWith(VIEWER_EVENT.progressEnd);
expect(docBase.zoomControls.setCurrentScale).to.be.calledWith(docBase.pdfViewer.currentScale);
});

it('should hide the preload and init thumbnails if no pages were previously rendered', () => {
Expand All @@ -1833,12 +1834,14 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
expect(stubs.hidePreload).to.be.called;
expect(docBase.somePageRendered).to.be.true;
expect(docBase.resize).to.be.called;
expect(docBase.zoomControls.setCurrentScale).to.be.calledWith(docBase.pdfViewer.currentScale);
});

it('should not init thumbnails if not enabled', () => {
docBase.options.enableThumbnailsSidebar = false;
docBase.pagerenderedHandler(docBase.event);
expect(stubs.initThumbnails).not.to.be.called;
expect(docBase.zoomControls.setCurrentScale).to.be.calledWith(docBase.pdfViewer.currentScale);
});
});

Expand Down

0 comments on commit 085131e

Please sign in to comment.