Skip to content

Commit

Permalink
feat(annotator): Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingze Xiao committed Sep 15, 2020
1 parent 8c2a011 commit 3ea29f7
Showing 1 changed file with 39 additions and 9 deletions.
48 changes: 39 additions & 9 deletions src/lib/viewers/__tests__/BaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import intl from '../../i18n';
import * as util from '../../util';
import * as icons from '../../icons/icons';
import * as constants from '../../constants';
import { AnnotationInput } from '../../AnnotationControlsFSM';
import { AnnotationMode } from '../../AnnotationControls';
import { EXCLUDED_EXTENSIONS } from '../../extensions';
import { VIEWER_EVENT, LOAD_METRIC, ERROR_CODE } from '../../events';
import { AnnotationMode } from '../../AnnotationControls';
import Timer from '../../Timer';
import Api from '../../api';

Expand Down Expand Up @@ -1113,6 +1114,7 @@ describe('lib/viewers/BaseViewer', () => {
describe('createAnnotator()', () => {
const annotatorMock = {};
const annotationsOptions = {
initialMode: AnnotationMode.NONE,
intl: {
language: 'en-US',
locale: 'en-US',
Expand Down Expand Up @@ -1203,6 +1205,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: AnnotationMode.REGION }));
});

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

Expand Down Expand Up @@ -1808,7 +1824,7 @@ describe('lib/viewers/BaseViewer', () => {
base.handleAnnotationCreateEvent(event);

expect(base.annotator.emit).to.be.calledWith('annotations_active_set', '123');
expect(base.annotationControls.setMode).to.be.calledWith('none');
expect(base.annotationControls.setMode).to.be.calledWith(AnnotationMode.NONE);
});
});

Expand All @@ -1818,9 +1834,9 @@ describe('lib/viewers/BaseViewer', () => {
destroy: sandbox.stub(),
setMode: sandbox.stub(),
};
base.handleAnnotationCreatorChangeEvent({ status: 'create', type: 'highlight' });
base.handleAnnotationCreatorChangeEvent({ status: AnnotationInput.CREATE, type: AnnotationMode.HIGHLIGHT });

expect(base.annotationControls.setMode).to.be.calledWith('highlight');
expect(base.annotationControls.setMode).to.be.calledWith(AnnotationMode.HIGHLIGHT);
});
});

Expand All @@ -1832,7 +1848,7 @@ describe('lib/viewers/BaseViewer', () => {

base.handleAnnotationControlsEscape();

expect(base.annotator.toggleAnnotationMode).to.be.calledWith('none');
expect(base.annotator.toggleAnnotationMode).to.be.calledWith(AnnotationMode.NONE);
});
});

Expand All @@ -1844,15 +1860,29 @@ describe('lib/viewers/BaseViewer', () => {
};
});

it('should call toggleAnnotationMode', () => {
it('should call toggleAnnotationMode and setMode', () => {
base.annotator = {
toggleAnnotationMode: sandbox.stub(),
};

base.handleAnnotationControlsClick({ mode: 'region' });
base.handleAnnotationControlsClick({ mode: AnnotationMode.REGION });

expect(base.annotator.toggleAnnotationMode).to.be.calledWith(AnnotationMode.REGION);
expect(base.annotationControls.setMode).to.be.calledWith(AnnotationMode.REGION);
});

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

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

expect(base.annotator.toggleAnnotationMode).to.be.calledWith('region');
expect(base.annotationControls.setMode).to.be.calledWith('region');
base.options.enableAnnotationsDiscoverability = true;
base.handleAnnotationControlsClick({ mode: AnnotationMode.NONE });
expect(base.annotator.toggleAnnotationMode).to.be.calledWith(AnnotationMode.REGION);
});
});
});

0 comments on commit 3ea29f7

Please sign in to comment.