From 39bff92d976bf775ec6ff49ed0127e6116e4958b Mon Sep 17 00:00:00 2001 From: Jack Chen Date: Mon, 11 Jan 2021 17:36:23 -0800 Subject: [PATCH] fix(drawing): emit color event when color picker is opened (#1315) * fix(drawing): emit color event when color picker is opened --- src/lib/viewers/BaseViewer.js | 2 ++ src/lib/viewers/__tests__/BaseViewer-test.js | 35 ++++++++++++++++---- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/lib/viewers/BaseViewer.js b/src/lib/viewers/BaseViewer.js index 716dc31cc..bf9881a94 100644 --- a/src/lib/viewers/BaseViewer.js +++ b/src/lib/viewers/BaseViewer.js @@ -1122,6 +1122,8 @@ class BaseViewer extends EventEmitter { this.containerEl.classList.add(className); } } + + 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 f58e52c32..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(); @@ -1779,6 +1786,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 +1833,14 @@ describe('lib/viewers/BaseViewer', () => { expect(base.containerEl).not.toHaveClass(constants.CLASS_ANNOTATIONS_CREATE_REGION); }); }); + + test('should call emit', () => { + jest.spyOn(base, 'areNewAnnotationsEnabled').mockReturnValue(true); + + base.processAnnotationModeChange(AnnotationMode.DRAWING); + + expect(base.annotator.emit).toBeCalledWith(ANNOTATOR_EVENT.setColor, '#000'); + }); }); describe('getInitialAnnotationMode()', () => {