Select Git revision
-
Loïs Poujade authoredLoïs Poujade authored
WebAnnotation.test.js 4.29 KiB
import WebAnnotation from '../src/WebAnnotation';
/** */
function createSubject(args = {}) {
return new WebAnnotation({
body: {
value: 'body',
},
canvasId: 'canvasId',
fragsel: { t: '5,10', xywh: 'xywh' },
id: 'id',
svg: 'svg',
tags: ['tags'],
...args,
});
}
describe('WebAnnotation', () => {
let subject = createSubject();
describe('constructor', () => {
it('sets instance accessors', () => {
['canvasId', 'id', 'svg'].forEach((prop) => {
expect(subject[prop]).toBe(prop);
});
expect(subject.fragsel).toStrictEqual({ t: '5,10', xywh: 'xywh' });
});
it('sets instance accessors for body', () => {
['body'].forEach((prop) => {
expect(subject[prop].value).toBe(prop);
});
});
});
describe('target', () => {
it('with svg and xywh', () => {
expect(subject.target()).toEqual({
selector: [
{
type: 'SvgSelector',
value: 'svg',
},
{
type: 'FragmentSelector',
value: 't=5,10&xywh=xywh',
},
],
source: 'canvasId',
});
});
it('with svg only', () => {
subject = createSubject({ fragsel: null });
expect(subject.target()).toEqual({
selector: {
type: 'SvgSelector',
value: 'svg',
},
source: 'canvasId',
});
});
it('with time interval only', () => {
subject = createSubject({ fragsel: { t: '5,10' }, svg: null });
expect(subject.target()).toEqual({
selector: {
type: 'FragmentSelector',
value: 't=5,10',
},
source: 'canvasId',
});
});
it('with time interval only - xywh present but null', () => {
subject = createSubject({ fragsel: { t: '5,10', xywh: null }, svg: null });