From 299aa3632348ef17c18f88b655f61b75b030ee34 Mon Sep 17 00:00:00 2001 From: Lutz Helm <helm@ub.uni-leipzig.de> Date: Fri, 26 Mar 2021 18:01:34 +0100 Subject: [PATCH] Fix #46: expect annotation without target selector --- __tests__/AnnotationCreation.test.js | 12 ++++++++++++ src/AnnotationCreation.js | 22 ++++++++++++---------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/__tests__/AnnotationCreation.test.js b/__tests__/AnnotationCreation.test.js index b3bfeb0..5f79a82 100644 --- a/__tests__/AnnotationCreation.test.js +++ b/__tests__/AnnotationCreation.test.js @@ -36,4 +36,16 @@ describe('AnnotationCreation', () => { wrapper = createWrapper(); expect(wrapper.dive().find(TextEditor).length).toBe(1); }); + it('can handle annotations without target selector', () => { + wrapper = createWrapper({ + annotation: { + body: { + purpose: 'commenting', + value: 'Foo bar', + }, + target: {}, + }, + }); + wrapper.dive(); + }); }); diff --git a/src/AnnotationCreation.js b/src/AnnotationCreation.js index c58f445..54d09c6 100644 --- a/src/AnnotationCreation.js +++ b/src/AnnotationCreation.js @@ -50,16 +50,18 @@ class AnnotationCreation extends Component { } else { annoState.annoBody = props.annotation.body.value; } - 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; + } } } this.state = { -- GitLab