Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MImranAsghar committed May 12, 2021
1 parent f8f957b commit fedaefb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
11 changes: 9 additions & 2 deletions __tests__/WebAnnotation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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', () => {
Expand Down
22 changes: 12 additions & 10 deletions src/AnnotationCreation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down

0 comments on commit fedaefb

Please sign in to comment.