From 30e171e3bbd54f926d91d0da1d1af396a5472cdd Mon Sep 17 00:00:00 2001 From: Sumedha Pramod Date: Wed, 17 Jan 2018 10:21:55 -0800 Subject: [PATCH] Fix: Check correct options when passing in BoxAnnotations instance (#584) --- src/lib/viewers/BaseViewer.js | 8 ++++++-- src/lib/viewers/__tests__/BaseViewer-test.js | 12 +++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/lib/viewers/BaseViewer.js b/src/lib/viewers/BaseViewer.js index 496914dae..ff69b43e9 100644 --- a/src/lib/viewers/BaseViewer.js +++ b/src/lib/viewers/BaseViewer.js @@ -769,9 +769,13 @@ class BaseViewer extends EventEmitter { */ areAnnotationsEnabled() { // Respect viewer-specific annotation option if it is set - if (window.BoxAnnotations && this.options.boxAnnotations instanceof window.BoxAnnotations) { + if ( + window.BoxAnnotations && + this.options.boxAnnotations instanceof window.BoxAnnotations && + this.options.boxAnnotations.viewerOptions + ) { const { boxAnnotations, viewer } = this.options; - const annotatorConfig = boxAnnotations.options[viewer.NAME]; + const annotatorConfig = boxAnnotations.viewerOptions[viewer.NAME]; this.viewerConfig = { enabled: annotatorConfig && (annotatorConfig.enabled || annotatorConfig.enabledTypes.length > 0) }; diff --git a/src/lib/viewers/__tests__/BaseViewer-test.js b/src/lib/viewers/__tests__/BaseViewer-test.js index a9be57a1e..60d665b59 100644 --- a/src/lib/viewers/__tests__/BaseViewer-test.js +++ b/src/lib/viewers/__tests__/BaseViewer-test.js @@ -912,7 +912,7 @@ describe('lib/viewers/BaseViewer', () => { expect(base.areAnnotationsEnabled()).to.equal(true); }); - it('should use the global show annotations boolean if the viewer param is not specified', () => { + it('should use the global showAnnotations boolean if the viewer param is not specified', () => { stubs.getViewerOption.withArgs('annotations').returns(null); base.options.showAnnotations = true; expect(base.areAnnotationsEnabled()).to.equal(true); @@ -929,25 +929,27 @@ describe('lib/viewers/BaseViewer', () => { base.options.viewer = { NAME: 'viewerName' }; base.options.boxAnnotations = sinon.createStubInstance(window.BoxAnnotations); + const boxAnnotations = base.options.boxAnnotations; // No enabled annotators in options - base.options.boxAnnotations.options = {}; + boxAnnotations.options = { 'nope': 'wrong options type' }; + boxAnnotations.viewerOptions = undefined; expect(base.areAnnotationsEnabled()).to.equal(false); // All default types enabled - base.options.boxAnnotations.options = { + boxAnnotations.viewerOptions = { 'viewerName': { enabled: true } }; expect(base.areAnnotationsEnabled()).to.equal(true); // No specified enabled types - base.options.boxAnnotations.options = { + boxAnnotations.viewerOptions = { 'viewerName': { enabledTypes: [] } }; expect(base.areAnnotationsEnabled()).to.equal(false); // Specified types enabled - base.options.boxAnnotations.options = { + boxAnnotations.viewerOptions = { 'viewerName': { enabledTypes: [ 'point' ] } }; expect(base.areAnnotationsEnabled()).to.equal(true);