Skip to content

Commit

Permalink
Fix: Check to see if viewers want to show annotations (#843)
Browse files Browse the repository at this point in the history
  • Loading branch information
Conrad Chan authored Sep 19, 2018
1 parent d8f34fd commit 2aa9914
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/lib/viewers/BaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ class BaseViewer extends EventEmitter {
*/
loadBoxAnnotations() {
if (
!this.options.showAnnotations ||
!this.areAnnotationsEnabled() ||
(window.BoxAnnotations && this.options.boxAnnotations instanceof window.BoxAnnotations)
) {
return Promise.resolve();
Expand All @@ -856,7 +856,7 @@ class BaseViewer extends EventEmitter {
* @return {void}
*/
createAnnotator() {
if (!this.options.showAnnotations) {
if (!this.areAnnotationsEnabled()) {
return;
}

Expand Down
17 changes: 13 additions & 4 deletions src/lib/viewers/__tests__/BaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1014,14 +1014,14 @@ describe('lib/viewers/BaseViewer', () => {
expect(base.loadAssets).to.not.be.calledWith(['annotations.js']);
});

it('should load the annotations assets if showAnnotations option is true', () => {
base.options.showAnnotations = true;
it('should load the annotations assets if annotations are enabled true', () => {
sandbox.stub(base, 'areAnnotationsEnabled').returns(true);
base.loadBoxAnnotations();
expect(base.loadAssets).to.be.calledWith(['annotations.js'], ['annotations.css'], false);
});

it('should not load the annotations assets if showAnnotations option is false', () => {
base.options.showAnnotations = false;
it('should not load the annotations assets if annotations are not enabled', () => {
sandbox.stub(base, 'areAnnotationsEnabled').returns(false);
base.loadBoxAnnotations();
expect(base.loadAssets).to.not.be.called;
});
Expand Down Expand Up @@ -1049,13 +1049,22 @@ describe('lib/viewers/BaseViewer', () => {
sandbox.stub(base, 'initAnnotations');
});

it('should not create the annotator if annotations are not enabled', () => {
sandbox.stub(base, 'areAnnotationsEnabled').returns(false);
base.createAnnotator();
expect(base.annotatorConf).to.be.undefined;
expect(base.annotator).to.be.undefined;
});

it('should determine and instantiate the annotator', () => {
sandbox.stub(base, 'areAnnotationsEnabled').returns(true);
base.createAnnotator();
expect(base.annotatorConf).to.equal(conf);
expect(base.annotator).to.equal(annotatorMock);
});

it('should not instantiate an instance of BoxAnnotations if one is already passed in', () => {
sandbox.stub(base, 'areAnnotationsEnabled').returns(true);
base.options.boxAnnotations = {
determineAnnotator: sandbox.stub().returns(conf)
};
Expand Down

0 comments on commit 2aa9914

Please sign in to comment.