Skip to content

Commit

Permalink
fix(drawing): emit color event when color picker is opened (#1315)
Browse files Browse the repository at this point in the history
* fix(drawing): emit color event when color picker is opened
  • Loading branch information
ChenCodes authored Jan 12, 2021
1 parent 800971a commit 39bff92
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/lib/viewers/BaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,8 @@ class BaseViewer extends EventEmitter {
this.containerEl.classList.add(className);
}
}

this.annotator.emit(ANNOTATOR_EVENT.setColor, this.annotationModule.getColor());
};

/**
Expand Down
35 changes: 28 additions & 7 deletions src/lib/viewers/__tests__/BaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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()', () => {
Expand Down

0 comments on commit 39bff92

Please sign in to comment.