Skip to content

Commit

Permalink
Fix: Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pramodsum committed Nov 2, 2018
1 parent a5b9438 commit cdc30af
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 61 deletions.
4 changes: 0 additions & 4 deletions src/AnnotationThread.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,6 @@ class AnnotationThread extends EventEmitter {

this.element = null;
}

// $FlowFixMe
const { page } = this.location;
this.emit(THREAD_EVENT.render, { page });
}

/**
Expand Down
9 changes: 0 additions & 9 deletions src/__tests__/AnnotationThread-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,6 @@ describe('AnnotationThread', () => {
it('should unbind listeners and remove thread element and broadcast that the thread was deleted', () => {
thread.destroy();
expect(thread.unbindDOMListeners).toBeCalled();
expect(thread.emit).not.toBeCalledWith(THREAD_EVENT.threadDelete);
expect(thread.unmountPopover).toBeCalled();
});

it('should emit annotationthreaddeleted only if thread is not in a pending state', () => {
thread.state = STATES.inactive;
thread.destroy();
expect(thread.unbindDOMListeners).toBeCalled();
expect(thread.emit).toBeCalledWith(THREAD_EVENT.threadDelete);
expect(thread.unmountPopover).toBeCalled();
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/Annotator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ describe('Annotator', () => {

expect(thread.state).toEqual(STATES.active);
expect(thread.save).toBeCalledWith(TYPES.point, 'text');
expect(annotator.emit).toBeCalledWith(THREAD_EVENT.threadSave, expect.any(Object));
expect(annotator.emit).toBeCalledWith(THREAD_EVENT.save, expect.any(Object));
expect(result).not.toBeNull();
expect(thread.renderAnnotationPopover).toBeCalled();
});
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/AnnotationModeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ class AnnotationModeController extends EventEmitter {
this.visibleThreadID = null;
break;
case THREAD_EVENT.render:
if (eventData.page) {
if (eventData && eventData.page) {
this.renderPage(eventData.page);
} else {
this.render();
Expand Down
1 change: 0 additions & 1 deletion src/controllers/DrawingModeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ class DrawingModeController extends AnnotationModeController {

this.currentThread = undefined;
this.selectedThread = thread;
// this.registerThread(thread);
this.unbindListeners();

// Clear existing canvases
Expand Down
15 changes: 4 additions & 11 deletions src/controllers/__tests__/AnnotationModeController-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,9 @@ describe('controllers/AnnotationModeController', () => {

it('should internally keep track of the registered thread', () => {
// eslint-disable-next-line new-cap
const pageThreads = {
all: jest.fn().mockReturnValue([thread]),
remove: jest.fn()
};
const pageThreads = new rbush();
pageThreads.all = jest.fn().mockReturnValue([thread]);
pageThreads.remove = jest.fn();

controller.annotations = { 1: pageThreads };

Expand Down Expand Up @@ -468,19 +467,13 @@ describe('controllers/AnnotationModeController', () => {
});

it('should re-render the annotations on render', () => {
controller.handleThreadEvents(thread, { event: THREAD_EVENT.render, eventData: 1 });
controller.handleThreadEvents(thread, { event: THREAD_EVENT.render, eventData: { page: 1 } });
expect(controller.renderPage).toBeCalled();

controller.handleThreadEvents(thread, { event: THREAD_EVENT.render });
expect(controller.render).toBeCalled();
});

it('should unregister thread on threadDelete', () => {
controller.handleThreadEvents(thread, { event: THREAD_EVENT.threadDelete, data: {} });
expect(controller.unregisterThread).toBeCalled();
expect(controller.emit).toBeCalledWith(THREAD_EVENT.threadDelete, expect.any(Object));
});

it('should unregister thread on deleteError', () => {
controller.handleThreadEvents(thread, { event: THREAD_EVENT.deleteError, data: {} });
expect(controller.emit).toBeCalledWith(CONTROLLER_EVENT.error, controller.localized.deleteError);
Expand Down
1 change: 0 additions & 1 deletion src/controllers/__tests__/DrawingModeController-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ describe('controllers/DrawingModeController', () => {
});
expect(controller.unbindListeners).toBeCalled();
expect(controller.bindListeners).toBeCalled();
expect(controller.registerThread).toBeCalled();
expect(controller.currentThread).toBeUndefined();
expect(thread.handleStart).not.toBeCalled();
expect(thread.removeListener).toBeCalledWith('threadevent', expect.any(Function));
Expand Down
35 changes: 18 additions & 17 deletions src/doc/DocHighlightThread.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ class DocHighlightThread extends AnnotationThread {
this.canComment = canComment;
}

/**
* [destructor]
*
* @return {void}
*/
destroy() {
this.threadID = null;

// $FlowFixMe
const { page } = this.location;
this.emit(THREAD_EVENT.render, { page });
super.destroy();

if (this.state === STATES.pending) {
window.getSelection().removeAllRanges();
}
}

/**
* Cancels the first comment on the thread
*
Expand Down Expand Up @@ -64,23 +82,6 @@ class DocHighlightThread extends AnnotationThread {
this.cancelFirstComment();
};

/**
* [destructor]
*
* @return {void}
*/
destroy() {
this.threadID = null;

// $FlowFixMe
this.emit(THREAD_EVENT.render, this.location.page);
super.destroy();

if (this.state === STATES.pending) {
window.getSelection().removeAllRanges();
}
}

/**
* Hides the highlight by cutting out the annotation from context. Note
* that if there are any overlapping highlights, this will cut out
Expand Down
10 changes: 1 addition & 9 deletions src/doc/__tests__/DocHighlightThread-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,10 @@ describe('doc/DocHighlightThread', () => {
describe('destroy()', () => {
it('should destroy the thread', () => {
thread.emit = jest.fn();
thread.state = STATES.pending;

// This stubs out a parent method by forcing the method we care about
// in the prototype of the prototype of DocHighlightThread (ie
// AnnotationThread's prototype) to be a stub
Object.defineProperty(Object.getPrototypeOf(DocHighlightThread.prototype), 'destroy', {
value: jest.fn()
});

thread.destroy();
expect(thread.element).toBeUndefined();
expect(thread.emit).toBeCalledWith(THREAD_EVENT.render, 1);
expect(thread.emit).toBeCalledWith(THREAD_EVENT.render, { page: thread.location.page });
});
});

Expand Down
10 changes: 4 additions & 6 deletions src/drawing/DrawingThread.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,13 @@ class DrawingThread extends AnnotationThread {
window.cancelAnimationFrame(this.lastAnimationRequestId);
}

if (this.state !== STATES.pending) {
// $FlowFixMe
const { page } = this.location;
this.emit(THREAD_EVENT.render, { page });
}

this.unmountPopover();
this.reset();
super.destroy();

// $FlowFixMe
const { page } = this.location;
this.emit(THREAD_EVENT.render, { page });
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/drawing/__tests__/DrawingThread-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ describe('drawing/DrawingThread', () => {
expect(thread.getBrowserRectangularBoundary).toBeCalled();
expect(thread.concreteContext.clearRect).toBeCalled();
expect(thread.clearBoundary).toBeCalled();
expect(thread.delete).toBeCalledWith({ id: '123abc' });
expect(thread.pathContainer).toEqual(null);
});
});
Expand Down

0 comments on commit cdc30af

Please sign in to comment.