Skip to content

Commit

Permalink
Fix: Check correct options when passing in BoxAnnotations instance (#584
Browse files Browse the repository at this point in the history
)
  • Loading branch information
pramodsum authored Jan 17, 2018
1 parent e3d0f5c commit 30e171e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
8 changes: 6 additions & 2 deletions src/lib/viewers/BaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
};
Expand Down
12 changes: 7 additions & 5 deletions src/lib/viewers/__tests__/BaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 30e171e

Please sign in to comment.