Skip to content

Commit

Permalink
feat(annotations): Fix typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingze Xiao committed Mar 26, 2020
1 parent 1b095b2 commit dbba2b7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
11 changes: 5 additions & 6 deletions src/lib/AnnotationControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ export default class AnnotationControls {
/** @property {bool} - Region comment mode active state */
private isRegionActive = false;

/** @property {HTMLElement} - Region comment button element */
private regionButtonElement: HTMLElement = new HTMLButtonElement();

/**
* [constructor]
*
Expand All @@ -42,11 +39,13 @@ export default class AnnotationControls {
* @return {void}
*/
private handleRegionClick = (onRegionClick: Function) => (event: MouseEvent): void => {
const regionButtonElement = event.target as HTMLButtonElement;

this.isRegionActive = !this.isRegionActive;
if (this.isRegionActive) {
this.regionButtonElement.classList.add(CLASS_BUTTON_ACTIVE);
regionButtonElement.classList.add(CLASS_BUTTON_ACTIVE);
} else {
this.regionButtonElement.classList.remove(CLASS_BUTTON_ACTIVE);
regionButtonElement.classList.remove(CLASS_BUTTON_ACTIVE);
}

onRegionClick({ isRegionActive: this.isRegionActive, event });
Expand All @@ -60,7 +59,7 @@ export default class AnnotationControls {
*/
public init({ onRegionClick = noop }: Options = {}): void {
const groupElement = this.controls.addGroup(CLASS_ANNOTATIONS_GROUP);
this.regionButtonElement = this.controls.add(
this.controls.add(
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
__('region_comment'),
Expand Down
14 changes: 6 additions & 8 deletions src/lib/__tests__/AnnotationControls-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,19 @@ describe('lib/AnnotationControls', () => {

describe('handleRegionClick()', () => {
beforeEach(() => {
stubs.event = sandbox.stub({});
stubs.classListAdd = sandbox.stub();
stubs.classListRemove = sandbox.stub();
stubs.add = sandbox.stub(annotationControls.controls, 'add').returns({
classList: {
add: stubs.classListAdd,
remove: stubs.classListRemove,
stubs.event = sandbox.stub({
target: {
classList: {
add: stubs.classListAdd,
remove: stubs.classListRemove,
},
},
});
});

it('should activate region button then deactivate', () => {
annotationControls.init({ onRegionClick: stubs.onRegionClick });

expect(annotationControls.isRegionActive).to.be.false;

annotationControls.handleRegionClick(stubs.onRegionClick)(stubs.event);
Expand All @@ -87,7 +86,6 @@ describe('lib/AnnotationControls', () => {
});

it('should call onRegionClick', () => {
annotationControls.init({ onRegionClick: stubs.onRegionClick });
annotationControls.handleRegionClick(stubs.onRegionClick)(stubs.event);

expect(stubs.onRegionClick).to.be.calledWith({
Expand Down

0 comments on commit dbba2b7

Please sign in to comment.