diff --git a/src/lib/viewers/BaseViewer.js b/src/lib/viewers/BaseViewer.js index 44b0a984d..c94bd84b1 100644 --- a/src/lib/viewers/BaseViewer.js +++ b/src/lib/viewers/BaseViewer.js @@ -686,19 +686,17 @@ class BaseViewer extends EventEmitter { // Annotator object will still be sent along with the viewer in the load event also. this.emit('annotator', this.annotator); - // Add a custom listener for entering/exit annotations mode using the app's custom annotations buttons - this.addListener('toggleannotationmode', (data) => { - this.annotator.toggleAnnotationHandler(data); - }); + // Add a custom listener for entering/exit annotations mode using the app's + // custom annotations buttons + this.addListener('toggleannotationmode', (data) => this.annotator.toggleAnnotationMode(data)); // Add a custom listener for events related to scaling/orientation changes this.addListener('scale', (data) => { this.annotator.emit(ANNOTATOR_EVENT.scale, data); }); - this.addListener('scrolltoannotation', (data) => { - this.annotator.scrollToAnnotation(data); - }); + // Add a custom listener to scroll to the specified annotation + this.addListener('scrolltoannotation', (data) => this.annotator.scrollToAnnotation(data)); // Add a custom listener for events emmited by the annotator this.annotator.addListener('annotatorevent', this.handleAnnotatorEvents); diff --git a/src/lib/viewers/__tests__/BaseViewer-test.js b/src/lib/viewers/__tests__/BaseViewer-test.js index c951e0587..6db1ab856 100644 --- a/src/lib/viewers/__tests__/BaseViewer-test.js +++ b/src/lib/viewers/__tests__/BaseViewer-test.js @@ -836,7 +836,6 @@ describe('lib/viewers/BaseViewer', () => { locale: 'en-US' } }; - base.addListener = sandbox.stub(); base.scale = 1.5; base.annotator = { init: sandbox.stub(), @@ -845,12 +844,13 @@ describe('lib/viewers/BaseViewer', () => { base.annotatorConf = { CONSTRUCTOR: sandbox.stub().returns(base.annotator) }; - sandbox.stub(base, 'emit'); - - base.initAnnotations(); }); it('should initialize the annotator', () => { + sandbox.stub(base, 'emit'); + base.addListener = sandbox.stub(); + base.initAnnotations(); + expect(base.annotator.init).to.be.calledWith(1.5); expect(base.addListener).to.be.calledWith('toggleannotationmode', sinon.match.func); expect(base.addListener).to.be.calledWith('scale', sinon.match.func); @@ -858,6 +858,14 @@ describe('lib/viewers/BaseViewer', () => { expect(base.annotator.addListener).to.be.calledWith('annotatorevent', sinon.match.func); expect(base.emit).to.be.calledWith('annotator', base.annotator); }); + + it('should call the correct handler to toggle annotation modes', () => { + base.initAnnotations(); + base.annotator.toggleAnnotationMode = sandbox.stub(); + + base.emit('toggleannotationmode', 'mode'); + expect(base.annotator.toggleAnnotationMode).to.be.called; + }) }); describe('areAnnotationsEnabled()', () => {