From d7d1ce842f1da9b3d8824d24889f5b3ca47c96f5 Mon Sep 17 00:00:00 2001 From: Sumedha Pramod Date: Thu, 7 Feb 2019 11:30:22 -0800 Subject: [PATCH] Fix: Toggle highlight comment to plain highlight on cancel - Toggles an annotation between a plain highlight and highlight comment based on the number of comments saved on the annotation at the time when the cancel button was clicked --- src/doc/DocHighlightThread.js | 12 ++++--- src/doc/__tests__/DocHighlightThread-test.js | 35 ++++++++++++++++++++ 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/doc/DocHighlightThread.js b/src/doc/DocHighlightThread.js index 6c0a7eb10..ebe284a87 100644 --- a/src/doc/DocHighlightThread.js +++ b/src/doc/DocHighlightThread.js @@ -54,11 +54,12 @@ class DocHighlightThread extends AnnotationThread { } } - /** - * Cancels the first comment on the thread - * - * @return {void} - */ + /** @override */ + cancelUnsavedAnnotation = () => { + this.cancelFirstComment(); + }; + + /** @override */ cancelFirstComment() { // Reset type from highlight-comment to highlight if (this.comments.length <= 0) { @@ -66,6 +67,7 @@ class DocHighlightThread extends AnnotationThread { } this.reset(); + this.emit(THREAD_EVENT.cancel); // Clear and reset mobile annotations dialog if (util.shouldDisplayMobileUI(this.container)) { diff --git a/src/doc/__tests__/DocHighlightThread-test.js b/src/doc/__tests__/DocHighlightThread-test.js index 4b477cdcb..ab88bf0b9 100644 --- a/src/doc/__tests__/DocHighlightThread-test.js +++ b/src/doc/__tests__/DocHighlightThread-test.js @@ -68,6 +68,41 @@ describe('doc/DocHighlightThread', () => { }); }); + describe('cancelFirstComment()', () => { + beforeEach(() => { + thread.type = TYPES.highlight_comment; + thread.reset = jest.fn(); + thread.emit = jest.fn(); + thread.unmountPopover = jest.fn(); + thread.renderAnnotationPopover = jest.fn(); + thread.destroy = jest.fn(); + util.shouldDisplayMobileUI = jest.fn().mockReturnValue(false); + util.isPlainHighlight = jest.fn().mockReturnValue(false); + }); + + it('should reset the highlight type if annotation has no comments', () => { + thread.cancelFirstComment(); + expect(thread.type).toEqual(TYPES.highlight); + }); + + it('should unmount popover when user is on mobile', () => { + util.shouldDisplayMobileUI = jest.fn().mockReturnValue(true); + thread.cancelFirstComment(); + expect(thread.unmountPopover).toBeCalled(); + }); + + it('should re-render popover when annotation toggles from highlight comment to plain highlight', () => { + util.isPlainHighlight = jest.fn().mockReturnValue(true); + thread.cancelFirstComment(); + expect(thread.renderAnnotationPopover).toBeCalled(); + }); + + it('should destroy any other annotations', () => { + thread.cancelFirstComment(); + expect(thread.destroy).toBeCalled(); + }); + }); + describe('hide()', () => { it('should erase highlight thread from the UI', () => { thread.draw = jest.fn();