-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(drawing): add annotation module
- Loading branch information
Showing
15 changed files
with
189 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { | ||
bdlBoxBlue, | ||
bdlGreenLight, | ||
bdlWatermelonRed, | ||
bdlYellorange, | ||
bdlYellow, | ||
bdlGrimace, | ||
} from 'box-ui-elements/es/styles/variables'; | ||
import Cache from './Cache'; | ||
|
||
export const ANNOTATION_COLOR_KEY = 'annotation-color'; | ||
|
||
export const AnnotationColor = { | ||
BOX_BLUE: bdlBoxBlue, | ||
GREEN_LIGHT: bdlGreenLight, | ||
WATERMELON_RED: bdlWatermelonRed, | ||
YELLORANGE: bdlYellorange, | ||
YELLOW: bdlYellow, | ||
GRIMACE: bdlGrimace, | ||
}; | ||
|
||
export default class AnnotationModule { | ||
private cache: Cache; | ||
|
||
constructor({ cache }: { cache: Cache }) { | ||
this.cache = cache; | ||
} | ||
|
||
public getColor = (): string => (this.cache.get(ANNOTATION_COLOR_KEY) as string) || bdlBoxBlue; | ||
|
||
public setColor = (color: string): void => this.cache.set(ANNOTATION_COLOR_KEY, color, true); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { bdlBoxBlue } from 'box-ui-elements/es/styles/variables'; | ||
import AnnotationModule from '../AnnotationModule'; | ||
import Cache from '../Cache'; | ||
|
||
describe('lib/AnnotationModule', () => { | ||
test('getColor', () => { | ||
const cache = new Cache(); | ||
const annotationModule = new AnnotationModule({ cache }); | ||
|
||
expect(annotationModule.getColor()).toBe(bdlBoxBlue); | ||
}); | ||
|
||
test('setColor', () => { | ||
const cache = new Cache(); | ||
const color = '#fff'; | ||
const annotationModule = new AnnotationModule({ cache }); | ||
|
||
annotationModule.setColor(color); | ||
|
||
expect(annotationModule.getColor()).toBe(color); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 15 additions & 21 deletions
36
src/lib/viewers/controls/color-picker/ColorPickerControl.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 20 additions & 16 deletions
36
src/lib/viewers/controls/color-picker/__tests__/ColorPickerControl-test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,45 @@ | ||
import * as React from 'react'; | ||
import { shallow, ShallowWrapper } from 'enzyme'; | ||
import { AnnotationMode } from '../../annotations/types'; | ||
import ColorPickerControl from '../ColorPickerControl'; | ||
|
||
describe('ColorPickerControl', () => { | ||
const onAnnotationColorClick = jest.fn(); | ||
const defaultColor = '#fff'; | ||
|
||
const getWrapper = (props = {}): ShallowWrapper => | ||
shallow(<ColorPickerControl onAnnotationColorClick={onAnnotationColorClick} {...props} />); | ||
shallow(<ColorPickerControl colors={[defaultColor]} onColorSelect={jest.fn()} {...props} />); | ||
|
||
const getToggleButton = (wrapper: ShallowWrapper): ShallowWrapper => wrapper.find('.bp-ColorPickerControl-button'); | ||
const getColorPickerPalette = (wrapper: ShallowWrapper): ShallowWrapper => | ||
wrapper.find('[data-testid="bp-ColorPickerPalette"]'); | ||
|
||
describe('render', () => { | ||
test('should render null if annotationMode is not AnnotationMode.DRAWING', () => { | ||
const wrapper = getWrapper({ annotationMode: AnnotationMode.REGION }); | ||
|
||
expect(wrapper.isEmptyRender()).toBe(true); | ||
}); | ||
const getToggleButton = (wrapper: ShallowWrapper): ShallowWrapper => | ||
wrapper.find('[data-testid="bp-ColorPickerControl-button"]'); | ||
|
||
describe('render', () => { | ||
test('should not render ColorPickerPalette when the component is first mounted', () => { | ||
const wrapper = getWrapper(); | ||
|
||
expect(wrapper.find('ColorPickerPalette').exists()).toBe(false); | ||
expect(getColorPickerPalette(wrapper).exists()).toBe(false); | ||
}); | ||
|
||
test('should render ColorPickerPalette when the toggle button is clicked', () => { | ||
const wrapper = getWrapper({ annotationMode: AnnotationMode.DRAWING }); | ||
const wrapper = getWrapper(); | ||
|
||
getToggleButton(wrapper).simulate('click'); | ||
|
||
expect(wrapper.find('ColorPickerPalette').exists()).toBe(true); | ||
expect(getColorPickerPalette(wrapper).exists()).toBe(true); | ||
}); | ||
}); | ||
|
||
test('should render the toggle button with bp-is-active set to true if isActive is true', () => { | ||
const wrapper = getWrapper({ annotationMode: AnnotationMode.DRAWING, isActive: true }); | ||
describe('handleSelect', () => { | ||
test('should close the palette and call onColorSelect if a color is selected', () => { | ||
const onColorSelect = jest.fn(); | ||
const wrapper = getWrapper({ onColorSelect }); | ||
|
||
getToggleButton(wrapper).simulate('click'); | ||
getColorPickerPalette(wrapper).simulate('select', defaultColor); | ||
|
||
expect(getToggleButton(wrapper).hasClass('bp-is-active')).toBe(true); | ||
expect(getColorPickerPalette(wrapper).exists()).toBe(false); | ||
expect(onColorSelect).toHaveBeenCalledWith(defaultColor); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.