diff --git a/__tests__/WebAnnotation.test.js b/__tests__/WebAnnotation.test.js index e0abaa5cf73929381b7a0d6314d4c7494268f6c1..8d6a5a74cf43d139184ad0767422cba28847e416 100644 --- a/__tests__/WebAnnotation.test.js +++ b/__tests__/WebAnnotation.test.js @@ -3,7 +3,9 @@ import WebAnnotation from '../src/WebAnnotation'; /** */ function createSubject(args = {}) { return new WebAnnotation({ - body: 'body', + body: { + value: 'body', + }, canvasId: 'canvasId', id: 'id', svg: 'svg', @@ -17,10 +19,15 @@ describe('WebAnnotation', () => { let subject = createSubject(); describe('constructor', () => { it('sets instance accessors', () => { - ['body', 'canvasId', 'id', 'svg', 'xywh'].forEach((prop) => { + ['canvasId', 'id', 'svg', 'xywh'].forEach((prop) => { expect(subject[prop]).toBe(prop); }); }); + it('sets instance accessors for body', () => { + ['body'].forEach((prop) => { + expect(subject[prop].value).toBe(prop); + }); + }); }); describe('target', () => { it('with svg and xywh', () => { diff --git a/src/AnnotationCreation.js b/src/AnnotationCreation.js index 287c24c1e4c098139003857d64eb1336e824e103..d16d467c8814d8369cca0bf8bf310b60370de7b3 100644 --- a/src/AnnotationCreation.js +++ b/src/AnnotationCreation.js @@ -86,16 +86,18 @@ class AnnotationCreation extends Component { annoState.image = props.annotation.body.image; } - if (Array.isArray(props.annotation.target.selector)) { - props.annotation.target.selector.forEach((selector) => { - if (selector.type === 'SvgSelector') { - annoState.svg = selector.value; - } else if (selector.type === 'FragmentSelector') { - annoState.xywh = selector.value.replace('xywh=', ''); - } - }); - } else { - annoState.svg = props.annotation.target.selector.value; + if (props.annotation.target.selector) { + if (Array.isArray(props.annotation.target.selector)) { + props.annotation.target.selector.forEach((selector) => { + if (selector.type === 'SvgSelector') { + annoState.svg = selector.value; + } else if (selector.type === 'FragmentSelector') { + annoState.xywh = selector.value.replace('xywh=', ''); + } + }); + } else { + annoState.svg = props.annotation.target.selector.value; + } } }