Skip to content

Commit

Permalink
feat(annotations): Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingze Xiao committed Sep 15, 2020
1 parent 8c2a011 commit 14dc275
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/lib/viewers/__tests__/BaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,7 @@ describe('lib/viewers/BaseViewer', () => {
describe('createAnnotator()', () => {
const annotatorMock = {};
const annotationsOptions = {
initialMode: 'none',
intl: {
language: 'en-US',
locale: 'en-US',
Expand Down Expand Up @@ -1203,6 +1204,20 @@ describe('lib/viewers/BaseViewer', () => {
expect(base.createAnnotatorOptions).to.be.calledWith(sinon.match(annotationsOptions));
});

it('should create annotator with initial mode region if discoverability is enabled', () => {
sandbox.stub(base, 'areAnnotationsEnabled').returns(true);
sandbox.stub(base, 'createAnnotatorOptions');

base.options.boxAnnotations = {
determineAnnotator: sandbox.stub().returns(conf),
};
base.options.enableAnnotationsDiscoverability = true;

base.createAnnotator();

expect(base.createAnnotatorOptions).to.be.calledWith(sinon.match({ initialMode: 'region' }));
});

it('should emit annotator_create event', () => {
sandbox.stub(base, 'areAnnotationsEnabled').returns(true);

Expand Down Expand Up @@ -1844,7 +1859,7 @@ describe('lib/viewers/BaseViewer', () => {
};
});

it('should call toggleAnnotationMode', () => {
it('should call toggleAnnotationMode and setMode', () => {
base.annotator = {
toggleAnnotationMode: sandbox.stub(),
};
Expand All @@ -1854,5 +1869,19 @@ describe('lib/viewers/BaseViewer', () => {
expect(base.annotator.toggleAnnotationMode).to.be.calledWith('region');
expect(base.annotationControls.setMode).to.be.calledWith('region');
});

it('should call toggleAnnotationMode with appropriate mode if discoverability is enabled', () => {
base.annotator = {
toggleAnnotationMode: sandbox.stub(),
};

base.options.enableAnnotationsDiscoverability = false;
base.handleAnnotationControlsClick({ mode: 'none' });
expect(base.annotator.toggleAnnotationMode).to.be.calledWith('none');

base.options.enableAnnotationsDiscoverability = true;
base.handleAnnotationControlsClick({ mode: 'none' });
expect(base.annotator.toggleAnnotationMode).to.be.calledWith('region');
});
});
});

0 comments on commit 14dc275

Please sign in to comment.