Skip to content

Commit

Permalink
Fix: controller.handleAnnotationEvent() not bound correctly (#448)
Browse files Browse the repository at this point in the history
  • Loading branch information
pramodsum authored Oct 23, 2017
1 parent e8f6fd3 commit b11f2dd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
11 changes: 0 additions & 11 deletions src/lib/annotations/AnnotationModeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,6 @@ class AnnotationModeController extends EventEmitter {
/** @property {Array} - The array of annotation handlers */
handlers = [];

/**
* [constructor]
*
* @return {AnnotationModeController} Annotation controller instance
*/
constructor() {
super();

this.handleAnnotationEvent = this.handleAnnotationEvent.bind(this);
}

/**
* Register the annotator and any information associated with the annotator
*
Expand Down
20 changes: 20 additions & 0 deletions src/lib/annotations/__tests__/AnnotationModeController-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import AnnotationModeController from '../AnnotationModeController';
import DocDrawingThread from '../doc/DocDrawingThread';
import * as util from '../annotatorUtil';

let annotationModeController;
Expand Down Expand Up @@ -109,6 +110,25 @@ describe('lib/annotations/AnnotationModeController', () => {
expect(annotationModeController.annotator.bindCustomListenersOnThread).to.be.called;
expect(thread.addListener).to.be.called;
});

// Catches edge case where sometimes the first click upon entering
// Draw annotation mode, the annotator is not registered properly
// with the controller
it('should maintain annotator context when a "threadevent" is fired', () => {
Object.defineProperty(DocDrawingThread.prototype, 'setup', { value: sandbox.stub() });
Object.defineProperty(DocDrawingThread.prototype, 'getThreadEventData', { value: sandbox.stub() });
const thread = new DocDrawingThread({ threadID: 123 });

annotationModeController.handleAnnotationEvent = () => {
expect(annotationModeController.annotator).to.not.be.undefined;
};
annotationModeController.annotator = {
bindCustomListenersOnThread: sandbox.stub()
};

annotationModeController.bindCustomListenersOnThread(thread);
thread.emit('threadevent', {});
});
});

describe('unbindCustomListenersOnThread()', () => {
Expand Down

0 comments on commit b11f2dd

Please sign in to comment.