|
| 1 | +import { describe, expect, test } from "vitest"; |
| 2 | +import { normalize } from "../../src/presentation-4"; |
| 3 | + |
| 4 | +describe("presentation-4 specific resource parity", () => { |
| 5 | + test("coerces start, range items, and annotation target for v3 input and keeps selectors", () => { |
| 6 | + const manifest = { |
| 7 | + "@context": "http://iiif.io/api/presentation/3/context.json", |
| 8 | + id: "https://example.org/manifest/p3-upgrade", |
| 9 | + type: "Manifest", |
| 10 | + label: { en: ["p3 specific resource parity"] }, |
| 11 | + start: "https://example.org/canvas/1#t=5,15", |
| 12 | + items: [ |
| 13 | + { |
| 14 | + id: "https://example.org/canvas/1", |
| 15 | + type: "Canvas", |
| 16 | + width: 1000, |
| 17 | + height: 1000, |
| 18 | + items: [ |
| 19 | + { |
| 20 | + id: "https://example.org/canvas/1/page/1", |
| 21 | + type: "AnnotationPage", |
| 22 | + items: [ |
| 23 | + { |
| 24 | + id: "https://example.org/canvas/1/annotation/1", |
| 25 | + type: "Annotation", |
| 26 | + motivation: "painting", |
| 27 | + body: { |
| 28 | + id: "https://example.org/image/1.jpg", |
| 29 | + type: "Image", |
| 30 | + format: "image/jpeg", |
| 31 | + }, |
| 32 | + target: "https://example.org/canvas/1#xywh=10,20,30,40", |
| 33 | + }, |
| 34 | + ], |
| 35 | + }, |
| 36 | + ], |
| 37 | + }, |
| 38 | + ], |
| 39 | + structures: [ |
| 40 | + { |
| 41 | + id: "https://example.org/range/1", |
| 42 | + type: "Range", |
| 43 | + items: ["https://example.org/canvas/1#t=0,10"], |
| 44 | + }, |
| 45 | + ], |
| 46 | + }; |
| 47 | + |
| 48 | + const result = normalize(manifest as any); |
| 49 | + const normalizedManifest = result.entities.Manifest["https://example.org/manifest/p3-upgrade"] as any; |
| 50 | + const normalizedRange = result.entities.Range["https://example.org/range/1"] as any; |
| 51 | + const normalizedAnnotation = result.entities.Annotation["https://example.org/canvas/1/annotation/1"] as any; |
| 52 | + const startSelector = Array.isArray(normalizedManifest.start.selector) |
| 53 | + ? normalizedManifest.start.selector[0] |
| 54 | + : normalizedManifest.start.selector; |
| 55 | + const rangeSelector = Array.isArray(normalizedRange.items[0].selector) |
| 56 | + ? normalizedRange.items[0].selector[0] |
| 57 | + : normalizedRange.items[0].selector; |
| 58 | + const targetSelector = Array.isArray(normalizedAnnotation.target[0].selector) |
| 59 | + ? normalizedAnnotation.target[0].selector[0] |
| 60 | + : normalizedAnnotation.target[0].selector; |
| 61 | + |
| 62 | + expect(normalizedManifest.start.type).toBe("SpecificResource"); |
| 63 | + expect(normalizedManifest.start.source.id).toBe("https://example.org/canvas/1"); |
| 64 | + expect(startSelector.type).toBe("FragmentSelector"); |
| 65 | + expect(startSelector.value).toBe("t=5,15"); |
| 66 | + |
| 67 | + expect(normalizedRange.items[0].type).toBe("SpecificResource"); |
| 68 | + expect(normalizedRange.items[0].source.id).toBe("https://example.org/canvas/1"); |
| 69 | + expect(rangeSelector.type).toBe("FragmentSelector"); |
| 70 | + expect(rangeSelector.value).toBe("t=0,10"); |
| 71 | + |
| 72 | + expect(normalizedAnnotation.target[0].type).toBe("SpecificResource"); |
| 73 | + expect(normalizedAnnotation.target[0].source.id).toBe("https://example.org/canvas/1"); |
| 74 | + expect(targetSelector.type).toBe("FragmentSelector"); |
| 75 | + expect(targetSelector.value).toBe("xywh=10,20,30,40"); |
| 76 | + |
| 77 | + const selectorId = targetSelector.id; |
| 78 | + expect(selectorId).toBeTruthy(); |
| 79 | + expect(result.entities.Selector[selectorId]).toBeTruthy(); |
| 80 | + expect(result.mapping[selectorId]).toBe("Selector"); |
| 81 | + }); |
| 82 | +}); |
0 commit comments