Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions __tests__/fixtures/choice.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"@context": "http://iiif.io/api/presentation/3/context.json",
"id": "https://iiif.io/api/cookbook/recipe/0033-choice/manifest.json",
"type": "Manifest",
"label": {
"en": ["John Dee performing an experiment before Queen Elizabeth I."]
},
"items": [
{
"id": "https://iiif.io/api/cookbook/recipe/0033-choice/canvas/p1",
"type": "Canvas",
"height": 1271,
"width": 2000,
"items": [
{
"id": "https://iiif.io/api/cookbook/recipe/0033-choice/page/p1/1",
"type": "AnnotationPage",
"items": [
{
"id": "https://iiif.io/api/cookbook/recipe/0033-choice/annotation/p0001-image",
"type": "Annotation",
"motivation": "painting",
"body": {
"type": "Choice",
"items": [
{
"id": "https://iiif.io/api/image/3.0/example/reference/421e65be2ce95439b3ad6ef1f2ab87a9-dee-natural/full/max/0/default.jpg",
"type": "Image",
"format": "image/jpeg",
"width": 2000,
"height": 1271,
"label": {
"en": ["Natural Light"]
},
"service": [
{
"id": "https://iiif.io/api/image/3.0/example/reference/421e65be2ce95439b3ad6ef1f2ab87a9-dee-natural",
"type": "ImageService3",
"profile": "level1"
}
]
},
{
"id": "https://iiif.io/api/image/3.0/example/reference/421e65be2ce95439b3ad6ef1f2ab87a9-dee-xray/full/max/0/default.jpg",
"type": "Image",
"format": "image/jpeg",
"width": 2000,
"height": 1271,
"label": {
"en": ["X-Ray"]
},
"service": [
{
"id": "https://iiif.io/api/image/3.0/example/reference/421e65be2ce95439b3ad6ef1f2ab87a9-dee-xray",
"type": "ImageService3",
"profile": "level1"
}
]
}
]
},
"target": "https://iiif.io/api/cookbook/recipe/0033-choice/canvas/p1"
}
]
}
]
}
]
}
65 changes: 65 additions & 0 deletions __tests__/helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const cookbookAnnotationsEmbedded = require("./fixtures/cookbook-annotations-emb
const wunder = require("./fixtures/wunder-pres2.json");
const brideMatch = require("./fixtures/bride-match.json");
const brideDiff = require("./fixtures/bride-diff.json");
const choice = require("./fixtures/choice.json");

function mockFetch(status: number, data?: any) {
const xhrMockObj = {
Expand Down Expand Up @@ -284,4 +285,68 @@ describe("Helper", () => {
expect(externalResource.isProbed).toBe(true);
expect(externalResource.isResponseHandled).toBe(false);
});

test("hasChoices returns true for choice manifest", async () => {
const helper = await loadManifestJson(choice, {
manifestUri: choice.id,
});

expect(helper).toBeDefined();
expect(helper.hasChoices()).toBe(true);
});

test("getChoices returns correct number of choices", async () => {
const helper = await loadManifestJson(choice, {
manifestUri: choice.id,
});

const choices = helper.getChoices();
expect(choices).toBeDefined();
expect(choices.length).toBe(2);
});

test("getChoices returns items with correct labels", async () => {
const helper = await loadManifestJson(choice, {
manifestUri: choice.id,
});

const choices = helper.getChoices();
expect(choices[0].getLabel().getValue()).toBe("Natural Light");
expect(choices[1].getLabel().getValue()).toBe("X-Ray");
});

test("getActiveChoice returns first choice by default", async () => {
const helper = await loadManifestJson(choice, {
manifestUri: choice.id,
});

const activeChoice = helper.getActiveChoice();
expect(activeChoice).toBeDefined();
expect(activeChoice?.getLabel().getValue()).toBe("Natural Light");
});

test("getActiveChoice returns correct choice after choiceIndex update", async () => {
const helper = await loadManifestJson(choice, {
manifestUri: choice.id,
});

helper.choiceIndex = 1;
expect(helper.getActiveChoice()?.getLabel().getValue()).toBe("X-Ray");
});

test("hasChoices returns false for non-choice manifest", async () => {
const helper = await loadManifestJson(utexasRightsLogoReqStatement, {
manifestUri: utexasRightsLogoReqStatement.id,
});

expect(helper.hasChoices()).toBe(false);
});

test("getActiveChoice returns null when no choices present", async () => {
const helper = await loadManifestJson(utexasRightsLogoReqStatement, {
manifestUri: utexasRightsLogoReqStatement.id,
});

expect(helper.getActiveChoice()).toBeNull();
});
});
Loading
Loading