Skip to content
Merged
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
npm-debug.log*
package-lock.json
.cache
dist
dist
.DS_Store
.claude/
104 changes: 86 additions & 18 deletions __tests__/CanvasDownloadLinks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ function createWrapper(props) {
canvasId="abc123"
canvasLabel="My Canvas Label"
classes={{}}
infoResponse={{}}
restrictDownloadOnSizeDefinition={false}
viewType="single"
windowId="wid123"
Expand Down Expand Up @@ -40,6 +39,18 @@ describe('CanvasDownloadLinks', () => {
],
};

const infoResponse = {
json: {
'@context': 'http://iiif.io/api/image/2/context.json',
'@id': 'http://example.com/iiif/abc123/',
width: 4000,
height: 1000,
profile: [
'http://iiif.io/api/image/2/level1.json',
],
},
};

let currentBoundsSpy;

beforeEach(() => {
Expand All @@ -51,7 +62,7 @@ describe('CanvasDownloadLinks', () => {
});

it('renders the canvas label as an h3 heading', () => {
createWrapper({ canvas });
createWrapper({ canvas, infoResponse });

const headingElement = screen.getByText('My Canvas Label');
expect(headingElement).toBeInTheDocument();
Expand All @@ -60,18 +71,14 @@ describe('CanvasDownloadLinks', () => {

describe('Canvas Renderings', () => {
it('includes a canvas-level rendering as a download link', () => {
createWrapper({ canvas });
createWrapper({ canvas, infoResponse });

const downloadLink = screen.getByRole('link', { name: /mirador-dl-plugin\.whole_image {"width":4000,"height":1000}/i });
expect(downloadLink).toBeInTheDocument();
});
});

describe('Zoomed Region Links', () => {
const infoResponse = {
json: { width: 4000, height: 1000 },
};

it('does not render a zoom link when viewer is zoomed out to full image', () => {
currentBoundsSpy.mockImplementation(() => ({
x: 0, y: 0, width: 6000, height: 1000,
Expand Down Expand Up @@ -129,8 +136,7 @@ describe('CanvasDownloadLinks', () => {
canvas,
infoResponse: {
json: {
width: 4000,
height: 1000,
...infoResponse.json,
sizes: [{ width: 400, height: 100 }],
},
},
Expand All @@ -146,11 +152,16 @@ describe('CanvasDownloadLinks', () => {
});

describe('When Defined Sizes Are Present in infoResponse', () => {
const sizes = [
{ width: 4000, height: 1000 },
{ width: 2000, height: 500 },
{ width: 1000, height: 250 },
];
const infoResponseWithSizes = {
json: {
...infoResponse.json,
sizes: [
{ width: 4000, height: 1000 },
{ width: 2000, height: 500 },
{ width: 1000, height: 250 },
],
},
};

const viewport = {
getBounds: () => ({
Expand All @@ -161,7 +172,7 @@ describe('CanvasDownloadLinks', () => {
current: { viewport },
});
it('renders download links for all specified sizes in the dialog', () => {
createWrapper({ canvas, infoResponse: { json: { sizes } } });
createWrapper({ canvas, infoResponse: infoResponseWithSizes });

const link1 = screen.getByRole('link', { name: /mirador-dl-plugin\.whole_image {"width":4000,"height":1000}/i });
const link2 = screen.getByRole('link', { name: /mirador-dl-plugin\.whole_image {"width":2000,"height":500}/i });
Expand All @@ -173,9 +184,60 @@ describe('CanvasDownloadLinks', () => {
});
});

describe('When The Image Server Is Level 0', () => {
const level0InfoResponse = {
json: {
...infoResponse.json,
profile: ['http://iiif.io/api/image/2/level0.json'],
},
};

it('renders the full-size link but not the unsupported 1000px wide link', () => {
createWrapper({ canvas, infoResponse: level0InfoResponse });

const fullLink = screen.getByRole('link', { name: /mirador-dl-plugin\.whole_image {"width":4000,"height":1000}/i });
expect(fullLink).toHaveAttribute('href', 'http://example.com/iiif/abc123/full/full/0/default.jpg?download=true');

expect(screen.queryByRole('link', { name: /mirador-dl-plugin\.whole_image {"width":1000,"height":250}/i })).not.toBeInTheDocument();
});

it('never renders a link with an undefined href', () => {
createWrapper({ canvas, infoResponse: level0InfoResponse });

screen.getAllByRole('link').forEach((link) => {
expect(link.getAttribute('href')).not.toMatch(/^undefined/);
});
});
});

describe('When The Request Exceeds The Server Maximum', () => {
const cappedInfoResponse = {
json: {
...infoResponse.json,
profile: [
'http://iiif.io/api/image/2/level1.json',
{ maxWidth: 2000 },
],
},
};

it('omits the full-size link rather than rendering an undefined href', () => {
createWrapper({ canvas, infoResponse: cappedInfoResponse });

expect(screen.queryByRole('link', { name: /mirador-dl-plugin\.whole_image {"width":4000,"height":1000}/i })).not.toBeInTheDocument();

const smallLink = screen.getByRole('link', { name: /mirador-dl-plugin\.whole_image {"width":1000,"height":250}/i });
expect(smallLink).toHaveAttribute('href', 'http://example.com/iiif/abc123/full/1000,/0/default.jpg?download=true');

screen.getAllByRole('link').forEach((link) => {
expect(link.getAttribute('href')).not.toMatch(/^undefined/);
});
});
});

describe('When No Sizes Are Defined in infoResponse', () => {
it('renders a single link to the full-size image', () => {
createWrapper({ canvas });
createWrapper({ canvas, infoResponse });

const link = screen.getByRole('link', { name: /mirador-dl-plugin\.whole_image {"width":4000,"height":1000}/i });
expect(link).toBeInTheDocument();
Expand All @@ -184,7 +246,7 @@ describe('CanvasDownloadLinks', () => {

describe('For Images Wider Than 1000px', () => {
it('renders links for both full-size and 1000px wide versions', () => {
createWrapper({ canvas });
createWrapper({ canvas, infoResponse });

const link1 = screen.getByRole('link', { name: /mirador-dl-plugin\.whole_image {"width":4000,"height":1000}/i });
expect(link1).toHaveAttribute('href', 'http://example.com/iiif/abc123/full/full/0/default.jpg?download=true');
Expand All @@ -197,7 +259,13 @@ describe('CanvasDownloadLinks', () => {
describe('For Images Less Than 1000px Wide', () => {
it('does not render a smaller version link if image is under 1000px wide', () => {
const smallCanvas = { ...canvas, getWidth: () => 999 };
createWrapper({ canvas: smallCanvas });
const smallInfoResponse = {
json: {
...infoResponse.json,
width: 999,
},
};
createWrapper({ canvas: smallCanvas, infoResponse: smallInfoResponse });

const links = screen.getAllByRole('link');
expect(links).toHaveLength(2); // Should only show full-size version and link to PDF.
Expand Down
29 changes: 23 additions & 6 deletions __tests__/MiradorDownloadDialog.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function createWrapper(props) {
closeDialog={() => {}}
containerId="container-123"
infoResponse={() => ({})}
manifest={{ getSequences: () => [] }}
manifest={{ getRenderings: () => undefined, getSequences: () => [] }}
open
t={(k) => k}
viewType="single"
Expand Down Expand Up @@ -58,22 +58,39 @@ describe('Dialog', () => {
describe('ManifestDownloadLinks', () => {
it('does not render when there are no manifest renderings', () => {
createWrapper();
const manifestLinks = screen.queryByText('ManifestDownloadLinks');
expect(manifestLinks).not.toBeInTheDocument();
const manifestLinksHeading = screen.queryByText('Other download options');
expect(manifestLinksHeading).not.toBeInTheDocument();
});

it('renders when the manifest contains renderings', () => {
const rendering = { id: '', getLabel: () => ({ getValue: () => 'ManifestDownloadLinks' }), getFormat: () => {} };
it('renders when the default sequence contains renderings', () => {
const rendering = { id: '', getLabel: () => ({ getValue: () => 'Rendering from sequence' }), getFormat: () => {} };
createWrapper({
manifest: {
getRenderings: () => undefined,
getSequences: () => [
{
getRenderings: () => [rendering],
},
],
},
});
const manifestLinks = screen.queryByText('ManifestDownloadLinks');
const manifestLinksHeading = screen.queryByText('mirador-dl-plugin.other_download');
expect(manifestLinksHeading).toBeInTheDocument();
const manifestLinks = screen.queryByText('Rendering from sequence');
expect(manifestLinks).toBeInTheDocument();
});

it('renders when the manifest contains renderings', () => {
const rendering = { id: '', getLabel: () => ({ getValue: () => 'Rendering from manifest' }), getFormat: () => {} };
createWrapper({
manifest: {
getRenderings: () => [rendering],
getSequences: () => undefined,
},
});
const manifestLinksHeading = screen.queryByText('mirador-dl-plugin.other_download');
expect(manifestLinksHeading).toBeInTheDocument();
const manifestLinks = screen.queryByText('Rendering from manifest');
expect(manifestLinks).toBeInTheDocument();
});
});
Expand Down
24 changes: 24 additions & 0 deletions __tests__/fixtures/imageInfoV2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"@context": "http://iiif.io/api/image/2/context.json",
"@id": "https://stacks.stanford.edu/image/iiif/fv114zn4386/LD3047_Q4_v090_1985_0001",
"protocol": "http://iiif.io/api/image",
"width": 4056,
"height": 5182,
"sizes": [
{ "width": 127, "height": 162 },
{ "width": 254, "height": 324 },
{ "width": 507, "height": 648 },
{ "width": 1014, "height": 1296 },
{ "width": 2028, "height": 2591 },
{ "width": 4056, "height": 5182 },
{ "width": 4056, "height": 5182 }
],
"tiles": [
{
"width": 1024,
"height": 1024,
"scaleFactors": [1, 2, 4, 8, 16, 32]
}
],
"profile": ["http://iiif.io/api/image/2/level2.json"]
}
45 changes: 45 additions & 0 deletions __tests__/fixtures/imageInfoV3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"@context": "http://iiif.io/api/image/3/context.json",
"id": "https://ndhadeliver.natlib.govt.nz/iiif/3/IE18987210:FL91807985.jp2",
"type": "ImageService3",
"protocol": "http://iiif.io/api/image",
"profile": "level2",
"width": 4145,
"height": 5389,
"sizes": [
{ "width": 65, "height": 84 },
{ "width": 130, "height": 168 },
{ "width": 259, "height": 337 },
{ "width": 518, "height": 674 },
{ "width": 1036, "height": 1347 },
{ "width": 2073, "height": 2695 },
{ "width": 4145, "height": 5389 }
],
"tiles": [
{
"width": 1024,
"height": 1024,
"scaleFactors": [1, 2, 4, 8, 16, 32, 64]
}
],
"extraQualities": ["bitonal", "color", "gray"],
"extraFormats": ["tif", "gif"],
"extraFeatures": [
"baseUriRedirect",
"canonicalLinkHeader",
"cors",
"jsonldMediaType",
"mirroring",
"profileLinkHeader",
"regionByPct",
"regionByPx",
"regionSquare",
"rotationArbitrary",
"rotationBy90s",
"sizeByConfinedWh",
"sizeByH",
"sizeByPct",
"sizeByW",
"sizeByWh"
]
}
Loading
Loading