Skip to content

Commit

Permalink
Fix: Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pramodsum committed Nov 15, 2018
1 parent 0ae26c9 commit e5b9bdf
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
5 changes: 4 additions & 1 deletion src/controllers/DrawingModeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ class DrawingModeController extends AnnotationModeController {
* @return {void}
*/
cancelDrawing(): void {
this.destroyThread(this.currentThread);
if (this.currentThread) {
this.destroyThread(this.currentThread);
}

this.exit();
}

Expand Down
5 changes: 4 additions & 1 deletion src/controllers/PointModeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ class PointModeController extends AnnotationModeController {
this.annotatedElement.classList.remove(CLASS_ANNOTATION_POINT_MODE);

const thread = this.getThreadByID(this.pendingThreadID);
this.destroyThread(thread);
if (thread) {
this.destroyThread(thread);
}

this.pendingThreadID = null;
}

Expand Down
19 changes: 4 additions & 15 deletions src/controllers/__tests__/DrawingModeController-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,31 +88,20 @@ describe('controllers/DrawingModeController', () => {
});

describe('cancelDrawing()', () => {
beforeEach(() => {
controller.exit = jest.fn();
controller.unregisterThread = jest.fn();
thread = new DrawingThread();
});

it('should exit drawing mode', () => {
controller.cancelDrawing();
expect(controller.exit).toBeCalled();
expect(controller.unregisterThread).not.toBeCalled();
});

it('should destroy the current thread', () => {
controller.exit = jest.fn();
controller.destroyThread = jest.fn();
controller.currentThread = thread;

controller.cancelDrawing();
expect(controller.exit).toBeCalled();
expect(controller.unregisterThread).toBeCalled();
expect(controller.currentThread.destroy).toBeCalled();
expect(controller.destroyThread).toBeCalled();
});
});

describe('postDrawing()', () => {
beforeEach(() => {
controller.exit = jest.fn();
thread = new DrawingThread();
thread.state = STATES.pending;
});

Expand Down
7 changes: 4 additions & 3 deletions src/controllers/__tests__/PointModeController-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,23 @@ describe('controllers/PointModeController', () => {
});

describe('resetMode()', () => {
beforeEach(() => {
it('should reset annotation mode', () => {
// Set up annotation mode
controller.annotatedElement = document.createElement('div');
controller.annotatedElement.classList.add(CLASS_ANNOTATION_MODE);
controller.headerElement = document.createElement('div');

controller.buttonEl = document.createElement('button');
controller.buttonEl.classList.add(CLASS_ACTIVE);
});
controller.getThreadByID = jest.fn().mockReturnValue(thread);
controller.destroyThread = jest.fn();

it('should reset annotation mode', () => {
controller.buttonEl = document.createElement('button');
controller.buttonEl.classList.add(CLASS_ACTIVE);
controller.resetMode();
expect(controller.buttonEl.classList).not.toContain(CLASS_ACTIVE);
expect(controller.hadPendingThreads).toBeFalsy();
expect(controller.destroyThread).toBeCalledWith(thread);
});
});

Expand Down

0 comments on commit e5b9bdf

Please sign in to comment.