Skip to content

Commit

Permalink
Fix: toggleannotationmode event to trigger the right method (#478)
Browse files Browse the repository at this point in the history
  • Loading branch information
pramodsum authored Nov 9, 2017
1 parent 1229c0e commit f27bb07
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
12 changes: 5 additions & 7 deletions src/lib/viewers/BaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 12 additions & 4 deletions src/lib/viewers/__tests__/BaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,6 @@ describe('lib/viewers/BaseViewer', () => {
locale: 'en-US'
}
};
base.addListener = sandbox.stub();
base.scale = 1.5;
base.annotator = {
init: sandbox.stub(),
Expand All @@ -845,19 +844,28 @@ 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);
expect(base.addListener).to.be.calledWith('scrolltoannotation', sinon.match.func);
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()', () => {
Expand Down

0 comments on commit f27bb07

Please sign in to comment.