Skip to content

Commit

Permalink
Fix: disableAnnotationMode cannot be called on disallowed modes (#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
Minh-Ng authored and pramodsum committed Sep 8, 2017
1 parent 23527a8 commit 1d5a172
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/lib/annotations/Annotator.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,9 @@ class Annotator extends EventEmitter {
* @return {void}
*/
disableAnnotationMode(mode, buttonEl) {
if (this.isInAnnotationMode(mode)) {
if (!this.isModeAnnotatable(mode)) {
return;
} else if (this.isInAnnotationMode(mode)) {
this.currentAnnotationMode = null;
this.emit(MODE_EXIT);
}
Expand Down
8 changes: 8 additions & 0 deletions src/lib/annotations/__tests__/Annotator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ describe('lib/annotations/Annotator', () => {
describe('disableAnnotationMode()', () => {
beforeEach(() => {
annotator.currentAnnotationMode = TYPES.point;
stubs.isModeAnnotatable = sandbox.stub(annotator, 'isModeAnnotatable').returns(true);
stubs.isInMode = sandbox.stub(annotator, 'isInAnnotationMode').returns(false);
stubs.emit = sandbox.stub(annotator, 'emit');
stubs.unbindMode = sandbox.stub(annotator, 'unbindModeListeners');
Expand All @@ -387,6 +388,13 @@ describe('lib/annotations/Annotator', () => {
stubs.show = sandbox.stub(annotatorUtil, 'showElement');
});

it('should do nothing when the mode is not annotatable', () => {
stubs.isModeAnnotatable.returns(false);
annotator.annotatedElement = null;

expect(annotator.disableAnnotationMode, TYPES.draw).to.not.throw();
});

it('should exit annotation mode if currently in the specified mode', () => {
stubs.isInMode.returns(true);
annotator.disableAnnotationMode(TYPES.point);
Expand Down

0 comments on commit 1d5a172

Please sign in to comment.