Skip to content
Snippets Groups Projects
Commit 487c3622 authored by Mathias Maaß's avatar Mathias Maaß
Browse files

add selector for canvas label and id

parent c7115932
Branches
Tags
No related merge requests found
......@@ -13,6 +13,7 @@ import {
getThumbnailNavigationPosition,
getManifestTitle,
getWindowViewType,
getIdAndLabelOfCanvases,
} from '../../../src/state/selectors';
......@@ -254,3 +255,29 @@ describe('getDestructuredMetadata', () => {
expect(received).toEqual([]);
});
});
describe('getIdAndLabelOfCanvases', () => {
it('should return id and label of each canvas in manifest', () => {
const canvases = manifesto
.create(manifestFixture019)
.getSequences()[0]
.getCanvases();
const received = getIdAndLabelOfCanvases(canvases);
const expected = [
{
id: 'http://iiif.io/api/presentation/2.0/example/fixtures/canvas/24/c1.json',
label: 'Test 19 Canvas: 1',
},
{
id: 'https://purl.stanford.edu/fr426cg9537/iiif/canvas/fr426cg9537_1',
label: 'Image 1',
},
];
expect(received).toEqual(expected);
});
it('should return empty array if canvas if empty', () => {
const received = getIdAndLabelOfCanvases([]);
expect(received).toEqual([]);
});
});
......@@ -34,6 +34,18 @@ export function getManifestCanvases(manifest) {
return manifest.manifestation.getSequences()[0].getCanvases();
}
/**
* Return ids and labels of canvases
* @ param {Array} canvases
* @return {Array} - [ {id: 'id', label: 'label' }, ... ]
*/
export function getIdAndLabelOfCanvases(canvases) {
return canvases.map(canvas => ({
id: canvas.__jsonld['@id'], // eslint-disable-line no-underscore-dangle
label: canvas.__jsonld.label, // eslint-disable-line no-underscore-dangle
}));
}
/**
* Return the current canvas selected in a window
* @param {object} state
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment