Skip to content

Commit

Permalink
feat(highlight): Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingze Xiao committed Jul 30, 2020
1 parent cc79e58 commit d6c0280
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/common/BaseAnnotator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export default class BaseAnnotator extends EventEmitter {
this.init(scale, rotationAngle);
};

protected handleSetActive = (annotationId: string | null): void => {
public handleSetActive = (annotationId: string | null): void => {
this.setActiveId(annotationId);
};

Expand Down
19 changes: 18 additions & 1 deletion src/document/__tests__/DocumentAnnotator-test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BaseManager from '../../common/BaseManager';
import DocumentAnnotator from '../DocumentAnnotator';
import RegionManager from '../../region/RegionManager';
import { Annotation } from '../../@types';
import { Annotation, Event } from '../../@types';
import { annotations as regions } from '../../region/__mocks__/data';
import { fetchAnnotationsAction } from '../../store';
import { scrollToLocation } from '../../utils/scroll';
Expand Down Expand Up @@ -66,6 +66,23 @@ describe('DocumentAnnotator', () => {
}
});

describe('event handlers', () => {
beforeEach(() => {
annotator.annotatedEl = container.querySelector('.bp-doc') as HTMLElement;

jest.spyOn(annotator.annotatedEl.classList, 'add');
jest.spyOn(annotator.annotatedEl.classList, 'remove');
});

test('should add/remove highlight class', () => {
annotator.emit(Event.ANNOTATIONS_MODE_CHANGE, { mode: 'highlight' });
expect(annotator.annotatedEl?.classList.add).toHaveBeenCalledWith('ba-is-highlighting');

annotator.emit(Event.ANNOTATIONS_MODE_CHANGE, { mode: 'region' });
expect(annotator.annotatedEl?.classList.remove).toHaveBeenCalledWith('ba-is-highlighting');
});
});

describe('getPageManagers()', () => {
test('should create new managers given a new page element', () => {
const managers = annotator.getPageManagers(getPage());
Expand Down

0 comments on commit d6c0280

Please sign in to comment.