From e851620df4ae25c8f37b41de57f65cf557ef6567 Mon Sep 17 00:00:00 2001 From: Lutz Helm Date: Wed, 18 Dec 2019 17:52:00 +0100 Subject: [PATCH] Add some unit tests for the handling of different IIIF versions --- test/modules/iiif.js | 101 +++++++++++++++++++++++++++++++++++++++++++ test/test.html | 1 + 2 files changed, 102 insertions(+) create mode 100644 test/modules/iiif.js diff --git a/test/modules/iiif.js b/test/modules/iiif.js new file mode 100644 index 00000000..ab9ece03 --- /dev/null +++ b/test/modules/iiif.js @@ -0,0 +1,101 @@ +(function() { + + var id = "http://example.com/identifier"; + + var configure = function(data) { + return OpenSeadragon.IIIFTileSource.prototype.configure.apply( + new OpenSeadragon.TileSource(), [ data, 'http://example.com/identifier' ] + ); + }; + + var infoXml10level0 = new DOMParser().parseFromString('' + + '' + + 'http://example.com/identifier' + + '6000' + + '4000' + + '' + + '1' + + '2' + + '4' + + '' + + 'http://library.stanford.edu/iiif/image-api/compliance.html#level0' + + '', + 'text/xml' + ), + infoXml10level0sizeByW, + infoXml10level1, + infoJson10level0 = { + "identifier": id, + "width": 200, + "height": 100, + "profile" : "http://library.stanford.edu/iiif/image-api/compliance.html#level0" + }, + infoJson10level0sizeByW, + infoJson10level1, + infoJson11level0 = { + "@context": "http://library.stanford.edu/iiif/image-api/1.1/context.json", + "@id": id, + "width": 200, + "height": 100, + "profile": "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0" + }, + infoJson11level0sizeByW, + infoJson11level1, + infoJson2level0 = { + "@context": "http://iiif.io/api/image/2/context.json", + "@id": id, + "width": 200, + "height": 100, + "profile": ["http://iiif.io/api/image/2/level0.json"] + }, + infoJson2level0sizeByW, + infoJson2level1, + infoJson3level0 = { + "@context": "http://iiif.io/api/image/3/context.json", + "id": id, + "width": 200, + "height": 100, + "profile": "level0" + }, + infoJson3level0ContextExtension = { + "@context": [ + "http://iiif.io/api/image/3/context.json", + { + "example": "http://example.com/vocab" + } + ], + "id": id, + "width": 200, + "height": 100, + "profile": "level0" + }, + infoJson3level0sizeByW, + infoJson3level1; + + QUnit.test('IIIFTileSource.configure determins correct version', function(assert) { + var options1_0xml = configure(infoXml10level0); + assert.ok(options1_0xml.version); + assert.equal(options1_0xml.version, 1, 'Version is 1 for version 1.0 info.xml'); + + var options1_0 = configure(infoJson10level0); + assert.ok(options1_0.version); + assert.equal(options1_0.version, 1, 'Version is 1 for version 1.0 info.json'); + + var options1_1 = configure(infoJson11level0); + assert.ok(options1_1.version); + assert.equal(options1_1.version, 1, 'Version is 1 for version 1.1 info.json'); + + var options2 = configure(infoJson2level0); + assert.ok(options2.version); + assert.equal(options2.version, 2, 'Version is 2 for version 2 info.json'); + + var options3 = configure(infoJson3level0); + assert.ok(options3.version); + assert.equal(options3.version, 3, 'Version is 3 for version 3 info.json'); + + var options3withContextExtension = configure(infoJson3level0ContextExtension); + assert.ok(options3withContextExtension.version); + assert.equal(options3withContextExtension.version, 3, 'Version is 3 for version 3 info.json'); + }); + +})(); diff --git a/test/test.html b/test/test.html index 786af542..c740b01c 100644 --- a/test/test.html +++ b/test/test.html @@ -44,6 +44,7 @@ +