From fedaefb45e1e4e24146a165ec693aef742cc329d Mon Sep 17 00:00:00 2001 From: "imranasghar96@hotmail.com" <imranasghar96@hotmail.com> Date: Wed, 12 May 2021 04:47:34 -0400 Subject: [PATCH] Update tests --- __tests__/WebAnnotation.test.js | 11 +++++++++-- src/AnnotationCreation.js | 22 ++++++++++++---------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/__tests__/WebAnnotation.test.js b/__tests__/WebAnnotation.test.js index e0abaa5..8d6a5a7 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 287c24c..d16d467 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; + } } } -- GitLab