Skip to content

Commit

Permalink
Fix: Remove clickHandler from DrawingModeController (#280)
Browse files Browse the repository at this point in the history
  • Loading branch information
pramodsum committed Nov 4, 2018
1 parent feedc87 commit 0c7fe0f
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 99 deletions.
27 changes: 0 additions & 27 deletions src/controllers/DrawingModeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,33 +73,6 @@ class DrawingModeController extends AnnotationModeController {
this.redoButtonEl = this.getButton(SELECTOR_ANNOTATION_BUTTON_DRAW_REDO);
}

/** @inheritdoc */
bindDOMListeners(): void {
// $FlowFixMe
this.handleSelection = this.handleSelection.bind(this);
this.annotatedElement.addEventListener('click', this.handleSelection);
}

/** @inheritdoc */
unbindDOMListeners(): void {
this.annotatedElement.removeEventListener('click', this.handleSelection);
}

/** @inheritdoc */
bindListeners(): void {
super.bindListeners();
this.unbindDOMListeners();
}

/** @inheritdoc */
unbindListeners(): void {
super.unbindListeners();
this.bindDOMListeners();

disableElement(this.undoButtonEl);
disableElement(this.redoButtonEl);
}

/**
* Prevents click events from triggering other annotation types
*
Expand Down
72 changes: 0 additions & 72 deletions src/controllers/__tests__/DrawingModeController-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,78 +87,6 @@ describe('controllers/DrawingModeController', () => {
});
});

describe('bindDOMListeners()', () => {
beforeEach(() => {
controller.annotatedElement.addEventListener = jest.fn();
});

it('should bind DOM listeners for desktop devices', () => {
controller.hasTouch = false;
controller.bindDOMListeners();
expect(controller.annotatedElement.addEventListener).toBeCalledWith('click', expect.any(Function));
});

it('should bind DOM listeners for touch enabled devices', () => {
controller.hasTouch = true;
controller.bindDOMListeners();
expect(controller.annotatedElement.addEventListener).toBeCalledWith('click', expect.any(Function));
});
});

describe('unbindDOMListeners()', () => {
beforeEach(() => {
controller.annotatedElement.removeEventListener = jest.fn();
});

it('should unbind DOM listeners for desktop devices', () => {
controller.hasTouch = false;
controller.unbindDOMListeners();
expect(controller.annotatedElement.removeEventListener).toBeCalledWith('click', expect.any(Function));
});

it('should unbind DOM listeners for touch enabled devices', () => {
controller.hasTouch = true;
controller.unbindDOMListeners();
expect(controller.annotatedElement.removeEventListener).toBeCalledWith('click', expect.any(Function));
});
});

describe('bindListeners()', () => {
it('should disable undo and redo buttons', () => {
controller.unbindDOMListeners = jest.fn();
const handlerObj = {
type: 'event',
func: jest.fn(),
eventObj: {
addEventListener: jest.fn()
}
};
controller.setupHandlers = jest.fn(() => {
controller.handlers = [handlerObj];
});
expect(controller.handlers.length).toEqual(0);

controller.bindListeners();
expect(controller.unbindDOMListeners).toBeCalled();
});
});

describe('unbindListeners()', () => {
it('should disable undo and redo buttons', () => {
util.disableElement = jest.fn();
controller.bindDOMListeners = jest.fn();

controller.annotatedElement = document.createElement('div');
controller.undoButtonEl = 'test1';
controller.redoButtonEl = 'test2';

controller.unbindListeners();
expect(util.disableElement).toBeCalledWith(controller.undoButtonEl);
expect(util.disableElement).toBeCalledWith(controller.redoButtonEl);
expect(controller.bindDOMListeners);
});
});

describe('setupHandlers()', () => {
it('should successfully contain draw mode handlers if undo and redo buttons exist', () => {
controller.annotatedElement = {};
Expand Down

0 comments on commit 0c7fe0f

Please sign in to comment.