diff --git a/src/lib/viewers/BaseViewer.js b/src/lib/viewers/BaseViewer.js index 7b4955688..bb64723f5 100644 --- a/src/lib/viewers/BaseViewer.js +++ b/src/lib/viewers/BaseViewer.js @@ -345,7 +345,9 @@ class BaseViewer extends EventEmitter { document.defaultView.addEventListener('resize', this.debouncedResizeHandler); this.addListener('load', (event) => { - ({ scale: this.scale = 1 } = event); + if (event && event.scale) { + this.scale = event.scale; + } if (this.annotationsPromise) { this.annotationsPromise.then(this.loadAnnotator); diff --git a/src/lib/viewers/__tests__/BaseViewer-test.js b/src/lib/viewers/__tests__/BaseViewer-test.js index 1b131bb02..39ce8cc41 100644 --- a/src/lib/viewers/__tests__/BaseViewer-test.js +++ b/src/lib/viewers/__tests__/BaseViewer-test.js @@ -278,6 +278,40 @@ describe('lib/viewers/BaseViewer', () => { expect(document.defaultView.addEventListener).to.be.calledWith('resize', base.debouncedResizeHandler); expect(base.addListener).to.be.calledWith('load', sinon.match.func); }); + + it('should load the annotator when load is emitted with scale', (done) => { + sandbox.stub(fullscreen, 'addListener'); + sandbox.stub(document.defaultView, 'addEventListener'); + sandbox.stub(base, 'loadAnnotator'); + base.annotationsPromise = { + then: (arg) => { + expect(base.scale).to.equal(1.5); + expect(arg).to.equal(base.loadAnnotator); + done(); + } + }; + + base.addCommonListeners(); + expect(base.scale).to.equal(1); + base.emit('load', { + scale: 1.5 + }); + }); + + it('should load the annotator when load is emitted without an event', (done) => { + sandbox.stub(fullscreen, 'addListener'); + sandbox.stub(document.defaultView, 'addEventListener'); + sandbox.stub(base, 'loadAnnotator'); + base.annotationsPromise = { + then: (arg) => { + expect(arg).to.equal(base.loadAnnotator); + done(); + } + }; + + base.addCommonListeners(); + base.emit('load'); + }); }); describe('toggleFullscreen()', () => {