From 643dbcc9048281dc0a86f27b485252609dd2210e Mon Sep 17 00:00:00 2001 From: Jack Chen Date: Mon, 11 Jan 2021 13:39:53 -0800 Subject: [PATCH 1/3] fix(drawing): emit color event when color picker is opened --- src/lib/viewers/BaseViewer.js | 5 +++++ src/lib/viewers/__tests__/BaseViewer-test.js | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/lib/viewers/BaseViewer.js b/src/lib/viewers/BaseViewer.js index 716dc31cc..24c024fb2 100644 --- a/src/lib/viewers/BaseViewer.js +++ b/src/lib/viewers/BaseViewer.js @@ -1122,6 +1122,11 @@ class BaseViewer extends EventEmitter { this.containerEl.classList.add(className); } } + + if (mode === AnnotationMode.DRAWING) { + const color = this.annotationModule.getColor(); + this.annotator.emit(ANNOTATOR_EVENT.setColor, color); + } }; /** diff --git a/src/lib/viewers/__tests__/BaseViewer-test.js b/src/lib/viewers/__tests__/BaseViewer-test.js index f58e52c32..e2719e520 100644 --- a/src/lib/viewers/__tests__/BaseViewer-test.js +++ b/src/lib/viewers/__tests__/BaseViewer-test.js @@ -1779,6 +1779,12 @@ describe('lib/viewers/BaseViewer', () => { destroy: jest.fn(), setMode: jest.fn(), }; + base.annotationModule.cache = { + get: jest.fn().mockReturnValue('#000'), + }; + base.annotator = { + emit: jest.fn(), + }; base.containerEl = document.createElement('div'); base.areNewAnnotationsEnabled = jest.fn().mockReturnValue(true); }); @@ -1820,6 +1826,14 @@ describe('lib/viewers/BaseViewer', () => { expect(base.containerEl).not.toHaveClass(constants.CLASS_ANNOTATIONS_CREATE_REGION); }); }); + + test('should call emit if mode is AnnotationMode.DRAWING', () => { + jest.spyOn(base, 'areNewAnnotationsEnabled').mockReturnValue(true); + + base.processAnnotationModeChange(AnnotationMode.DRAWING); + + expect(base.annotator.emit).toBeCalledWith(ANNOTATOR_EVENT.setColor, '#000'); + }); }); describe('getInitialAnnotationMode()', () => { From ab33d07478b5cf7bbdd9a512ba2bf3b2ef66ab56 Mon Sep 17 00:00:00 2001 From: Jack Chen Date: Mon, 11 Jan 2021 14:41:03 -0800 Subject: [PATCH 2/3] fix(drawing): inline color variable --- src/lib/viewers/BaseViewer.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lib/viewers/BaseViewer.js b/src/lib/viewers/BaseViewer.js index 24c024fb2..43d24625d 100644 --- a/src/lib/viewers/BaseViewer.js +++ b/src/lib/viewers/BaseViewer.js @@ -1124,8 +1124,7 @@ class BaseViewer extends EventEmitter { } if (mode === AnnotationMode.DRAWING) { - const color = this.annotationModule.getColor(); - this.annotator.emit(ANNOTATOR_EVENT.setColor, color); + this.annotator.emit(ANNOTATOR_EVENT.setColor, this.annotationModule.getColor()); } }; From 52a08e362b596c7dd04617a2cddfab1ceb2d8be1 Mon Sep 17 00:00:00 2001 From: Jack Chen Date: Mon, 11 Jan 2021 14:59:29 -0800 Subject: [PATCH 3/3] fix(drawing): always emit setColor event on processAnnotationModeChange --- src/lib/viewers/BaseViewer.js | 4 +--- src/lib/viewers/__tests__/BaseViewer-test.js | 23 +++++++++++++------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/lib/viewers/BaseViewer.js b/src/lib/viewers/BaseViewer.js index 43d24625d..bf9881a94 100644 --- a/src/lib/viewers/BaseViewer.js +++ b/src/lib/viewers/BaseViewer.js @@ -1123,9 +1123,7 @@ class BaseViewer extends EventEmitter { } } - if (mode === AnnotationMode.DRAWING) { - this.annotator.emit(ANNOTATOR_EVENT.setColor, this.annotationModule.getColor()); - } + this.annotator.emit(ANNOTATOR_EVENT.setColor, this.annotationModule.getColor()); }; /** diff --git a/src/lib/viewers/__tests__/BaseViewer-test.js b/src/lib/viewers/__tests__/BaseViewer-test.js index e2719e520..22b7797b9 100644 --- a/src/lib/viewers/__tests__/BaseViewer-test.js +++ b/src/lib/viewers/__tests__/BaseViewer-test.js @@ -529,16 +529,19 @@ describe('lib/viewers/BaseViewer', () => { jest.spyOn(base, 'disableAnnotationControls'); jest.spyOn(base, 'processAnnotationModeChange'); - base.annotator = { - emit: jest.fn(), - toggleAnnotationMode: jest.fn(), - }; base.annotationControls = { destroy: jest.fn(), resetControls: jest.fn(), setMode: jest.fn(), toggle: jest.fn(), }; + base.annotationModule.cache = { + get: jest.fn().mockReturnValue('#000'), + }; + base.annotator = { + emit: jest.fn(), + toggleAnnotationMode: jest.fn(), + }; base.handleFullscreenEnter(); @@ -1047,15 +1050,19 @@ describe('lib/viewers/BaseViewer', () => { jest.spyOn(base, 'areNewAnnotationsEnabled').mockReturnValue(true); jest.spyOn(base, 'processAnnotationModeChange'); - base.annotator = { - toggleAnnotationMode: jest.fn(), - }; base.annotationControls = { destroy: jest.fn(), resetControls: jest.fn(), setMode: jest.fn(), toggle: jest.fn(), }; + base.annotationModule.cache = { + get: jest.fn().mockReturnValue('#000'), + }; + base.annotator = { + emit: jest.fn(), + toggleAnnotationMode: jest.fn(), + }; base.disableAnnotationControls(); @@ -1827,7 +1834,7 @@ describe('lib/viewers/BaseViewer', () => { }); }); - test('should call emit if mode is AnnotationMode.DRAWING', () => { + test('should call emit', () => { jest.spyOn(base, 'areNewAnnotationsEnabled').mockReturnValue(true); base.processAnnotationModeChange(AnnotationMode.DRAWING);