Skip to content
Snippets Groups Projects
Commit a85a952e authored by Jack Reed's avatar Jack Reed
Browse files

Backfill tests for LocalStorageAdapter

parent ceb1340e
No related branches found
No related tags found
No related merge requests found
{
"id": "localStorage://?canvasId=https://iiif.harvardartmuseums.org/manifests/object/299843/canvas/canvas-47174896",
"items": [
{
"body": {
"language": "en",
"type": "TextualBody",
"value": "eye"
},
"id": "https://example.org/iiif/book1/page/manifest/efb5757d-899b-4551-a7ab-5cb5d1d0eb02",
"motivation": "commenting",
"target": {
"id": "https://iiif.harvardartmuseums.org/manifests/object/299843/canvas/canvas-47174896",
"selector": {
"type": "SvgSelector",
"value": "<path xmlns=\"http://www.w3.org/2000/svg\" d=\"M784.24634,1028.82823v-183.35553h200.33289v183.35553z\" fill=\"none\" fill-rule=\"nonzero\" stroke=\"#00bfff\" stroke-width=\"1\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-miterlimit=\"10\" stroke-dasharray=\"\" stroke-dashoffset=\"0\" font-family=\"none\" font-weight=\"none\" font-size=\"none\" text-anchor=\"none\" style=\"mix-blend-mode: normal\"/>"
}
},
"type": "Annotation"
}
],
"type": "AnnotationPage"
}
import LocalStorageAdapter from '../src/LocalStorageAdapter';
import fixture from '../__fixtures__/web_annotation.json';
describe('LocalStorageAdapter', () => {
let subject;
beforeEach(() => {
subject = new LocalStorageAdapter('//foo');
localStorage.clear();
localStorage.setItem('//foo', JSON.stringify(fixture));
});
describe('create', () => {
it('adds an item to the AnnotationPage items', () => {
expect(subject.all().items.length).toBe(1);
const annoPage = subject.create({});
expect(annoPage.items.length).toBe(2);
});
it('if there is no AnnotationPage, create one', () => {
subject = new LocalStorageAdapter('//bar');
expect(subject.all()).toBe(null);
subject.create({});
const annoPage = subject.all();
expect(annoPage.type).toBe('AnnotationPage');
expect(annoPage.items.length).toBe(1);
});
});
describe('delete', () => {
it('removes an item from an AnnotationPage', () => {
expect(subject.all().items.length).toBe(1);
const annoPage = subject.delete('https://example.org/iiif/book1/page/manifest/efb5757d-899b-4551-a7ab-5cb5d1d0eb02');
expect(annoPage.items.length).toBe(0);
});
});
describe('update', () => {
xit('not implemented', () => {
});
});
describe('all', () => {
it('parses and returns an item based on its annotationPageId', () => {
const annoPage = subject.all();
expect(localStorage.getItem).toHaveBeenLastCalledWith('//foo');
expect(annoPage.items.length).toBe(1);
expect(annoPage.type).toBe('AnnotationPage');
});
});
});
......@@ -8,7 +8,7 @@ module.exports = {
// The directory where Jest should output its coverage files
coverageDirectory: 'coverage',
setupFiles: [
'<rootDir>/setupJest.js',
'<rootDir>/setupJest.js', 'jest-localstorage-mock',
],
// Ignore Mirador code from jest transforms
transformIgnorePatterns: [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment