Skip to content
This repository has been archived by the owner on Feb 15, 2022. It is now read-only.

Commit

Permalink
Tests, fixtures and a readme update
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenwf committed May 7, 2021
1 parent f3d6f02 commit ee297ab
Show file tree
Hide file tree
Showing 14 changed files with 42,897 additions and 3 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/yarn.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Yarn build

on: [push]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node: [ '12', '10' ]

name: Node ${{ matrix.node }} build
steps:
- uses: actions/checkout@v1
- name: Get yarn cache
id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v1
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-${{ matrix.node }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Setup node
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- run: yarn install --frozen-lockfile --non-interactive
- run: yarn run build
- run: yarn run test
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,32 @@ vault.loadManifest('http://example.org/..').then(manifest => {
});
```

#### Validate Presentation 3
With such a new specification it can be useful to have some validation. This goes beyond the types, which cannot be
used at runtime. The validator uses an official JSON-Schema for validating.

```js
import { Validator } from '@hyperion-framework/parser';

const validator = new Validator();

validator.validateManifest({ ... }); // boolean
validator.validateCollection({ ... }); // boolean
validator.validateAnnotationPage({ ... }); // boolean
validator.validateCustom('canvas', { ... }); // boolean

```

#### Upgrade Presentation 2 to 3

If you want to start building with IIIF Presentation 3 you will likely want to support both IIIF Presentation 2
as the community transitions. The `@hyperion-framework/parser` package contains a simple converter that can
as the community transitions. The `@hyperion-framework/presentation-2-parser` package contains a simple converter that can
be used to convert 2 to 3 in the browser and can be dropped into most applications right after fetching an
IIIF resource. This supports both Collections and Manifests. If you need more granular control and options
you can check the `@hyperion-framework/presentation-2-parser` package.

```js
import { convertPresentation2 } from '@hyperion-framework/parser';
import { convertPresentation2 } from '@hyperion-framework/presentation-2-parser';

// ...

Expand Down
3 changes: 2 additions & 1 deletion __tests__/presentation-2-parser/traverse-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import iiifManifest from '../../fixtures/presentation-2/iiif-fixture-manifest.js
import bibManifest from '../../fixtures/presentation-2/biblissima-manifest.json';
import iiifAnnoList from '../../fixtures/presentation-2/iiif-fixture-annotation-list.json';
import { Traverse } from '../../packages/presentation-2-parser/src/traverse';
import { upgraderTraverse } from '../../packages/presentation-2-parser/src/upgrader';
import { presentation2to3 } from '../../packages/presentation-2-parser/src/upgrader';

describe('Presentation 2 Traverse', () => {
// test('upgrade 2 to 3', () => {
Expand All @@ -25,6 +25,7 @@ describe('Presentation 2 Traverse', () => {
manifest: [
manifest => {
manifestIds.push(manifest['@id']);
return manifest;
},
],
});
Expand Down
94 changes: 94 additions & 0 deletions __tests__/presentation-2-parser/upgrade-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import iiifManifest from '../../fixtures/presentation-2/iiif-fixture-manifest.json';
import iiifManifest2 from '../../fixtures/presentation-2/biblissima-manifest.json';
import blManifest from '../../fixtures/presentation-2/bl-manifest.json';
import nlwManifest from '../../fixtures/presentation-2/nlw-manifest.json';
import bodleianManifest from '../../fixtures/presentation-2/bodleian-manifest.json';
import stanfordManifest from '../../fixtures/presentation-2/stanford-manifest.json';
import folgerManifest from '../../fixtures/presentation-2/folger-manifest.json';
import villanovaManifest from '../../fixtures/presentation-2/villanova-manifest.json';
import ngaManifest from '../../fixtures/presentation-2/nga-manifest.json';
import quatarManifest from '../../fixtures/presentation-2/quatar-manifest.json';
import { presentation2to3 } from '../../packages/presentation-2-parser/src/upgrader';
import { Validator } from '../../packages/validator/src/validator';

describe('Presentation 2 to 3', () => {
const validator = new Validator();

test('Simple manifest', () => {
const result = presentation2to3.traverseManifest(iiifManifest as any);
const isValid = validator.validateManifest(result);

expect(validator.validators.manifest.errors).toEqual(null);
expect(isValid).toEqual(true);
});
test('Biblissima manifest', () => {
const result = presentation2to3.traverseManifest(iiifManifest2 as any);
const isValid = validator.validateManifest(result);

expect(validator.validators.manifest.errors).toEqual(null);
expect(isValid).toEqual(true);
});

test('British Library manifest', () => {
const result = presentation2to3.traverseManifest(blManifest as any);
const isValid = validator.validateManifest(result);

expect(validator.validators.manifest.errors).toEqual(null);
expect(isValid).toEqual(true);
});

test('NLW manifest', () => {
const result = presentation2to3.traverseManifest(nlwManifest as any);
const isValid = validator.validateManifest(result);

expect(validator.validators.manifest.errors).toEqual(null);
expect(isValid).toEqual(true);
});

test('Bodleian manifest', () => {
const result = presentation2to3.traverseManifest(bodleianManifest as any);
const isValid = validator.validateManifest(result);

expect(validator.validators.manifest.errors).toEqual(null);
expect(isValid).toEqual(true);
});

test('Stanford manifest', () => {
const result = presentation2to3.traverseManifest(stanfordManifest as any);
const isValid = validator.validateManifest(result);

expect(validator.validators.manifest.errors).toEqual(null);
expect(isValid).toEqual(true);
});

test('Folger manifest', () => {
const result = presentation2to3.traverseManifest(folgerManifest as any);
const isValid = validator.validateManifest(result);

expect(validator.validators.manifest.errors).toEqual(null);
expect(isValid).toEqual(true);
});

test('Villanova manifest', () => {
const result = presentation2to3.traverseManifest(villanovaManifest as any);
const isValid = validator.validateManifest(result);

expect(validator.validators.manifest.errors).toEqual(null);
expect(isValid).toEqual(true);
});

test('NGA manifest', () => {
const result = presentation2to3.traverseManifest(ngaManifest as any);
const isValid = validator.validateManifest(result);

expect(validator.validators.manifest.errors).toEqual(null);
expect(isValid).toEqual(true);
});
test('Quatar manifest', () => {
const result = presentation2to3.traverseManifest(quatarManifest as any);
const isValid = validator.validateManifest(result);

expect(validator.validators.manifest.errors).toEqual(null);
expect(isValid).toEqual(true);
});
});
8 changes: 8 additions & 0 deletions __tests__/utility/__snapshots__/iiif-normalize-test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Object {
"logo": Array [],
"metadata": Array [],
"motivation": null,
"provider": Array [],
"rendering": Array [],
"requiredStatement": null,
"rights": null,
Expand All @@ -46,6 +47,7 @@ Object {
},
"Canvas": Object {
"https://example.org/iiif/book1/canvas/p1": Object {
"accompanyingCanvas": null,
"annotations": Array [],
"behavior": Array [],
"duration": 0,
Expand All @@ -64,7 +66,9 @@ Object {
"motivation": null,
"navDate": null,
"partOf": Array [],
"placeholderCanvas": null,
"posterCanvas": null,
"provider": Array [],
"rendering": Array [],
"requiredStatement": null,
"rights": null,
Expand Down Expand Up @@ -96,6 +100,7 @@ Object {
"http://www.w3.org/ns/anno.jsonld",
"http://iiif.io/api/presentation/{{ page.major }}/context.json",
],
"accompanyingCanvas": null,
"annotations": Array [],
"behavior": Array [],
"homepage": Object {
Expand All @@ -119,12 +124,15 @@ Object {
"motivation": null,
"navDate": null,
"partOf": Array [],
"placeholderCanvas": null,
"posterCanvas": null,
"provider": Array [],
"rendering": Array [],
"requiredStatement": null,
"rights": null,
"seeAlso": Array [],
"service": Array [],
"services": Array [],
"start": null,
"structures": Array [],
"summary": null,
Expand Down
Loading

0 comments on commit ee297ab

Please sign in to comment.