From 2aa99141cb2a7e2b3527003ec690ce794df00fff Mon Sep 17 00:00:00 2001 From: Conrad Chan Date: Wed, 19 Sep 2018 13:19:47 -0700 Subject: [PATCH] Fix: Check to see if viewers want to show annotations (#843) --- src/lib/viewers/BaseViewer.js | 4 ++-- src/lib/viewers/__tests__/BaseViewer-test.js | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/lib/viewers/BaseViewer.js b/src/lib/viewers/BaseViewer.js index e58d6be70..06ddff709 100644 --- a/src/lib/viewers/BaseViewer.js +++ b/src/lib/viewers/BaseViewer.js @@ -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(); @@ -856,7 +856,7 @@ class BaseViewer extends EventEmitter { * @return {void} */ createAnnotator() { - if (!this.options.showAnnotations) { + if (!this.areAnnotationsEnabled()) { return; } diff --git a/src/lib/viewers/__tests__/BaseViewer-test.js b/src/lib/viewers/__tests__/BaseViewer-test.js index 1f092cc2c..56df6c569 100644 --- a/src/lib/viewers/__tests__/BaseViewer-test.js +++ b/src/lib/viewers/__tests__/BaseViewer-test.js @@ -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; }); @@ -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) };