diff --git a/__tests__/fixtures/version-3/with_a_provider.json b/__tests__/fixtures/version-3/with_a_provider.json new file mode 100644 index 0000000000000000000000000000000000000000..2a0fd4d90c97b2c8e83c37c066215c85550a975b --- /dev/null +++ b/__tests__/fixtures/version-3/with_a_provider.json @@ -0,0 +1,35 @@ +{ + "@context": [ + "http://www.w3.org/ns/anno.jsonld", + "http://iiif.io/api/presentation/3/context.json" + ], + "id": "https://example.com/with_a_provider.json", + "type": "Manifest", + "provider": [ + { + "id": "https://example.org/about", + "type": "Agent", + "label": {"en": ["Example Organization"]}, + "homepage": { + "id": "https://example.org/", + "type": "Text", + "label": {"en": ["Example Organization Homepage"]}, + "format": "text/html" + }, + "logo": { + "id": "https://example.org/images/logo.png", + "type": "Image", + "height": 100, + "width": 120 + }, + "seeAlso": [ + { + "id": "https://data.example.org/about/us.jsonld", + "type": "Dataset", + "format": "application/ld+json", + "profile": "https://schema.org/" + } + ] + } + ] +} diff --git a/__tests__/src/components/ManifestListItem.test.js b/__tests__/src/components/ManifestListItem.test.js index 26df8eb7346e99e83233aa9e658af31c52d92f18..16c46918d7aafe79b6d60d2453520b3f2295679e 100644 --- a/__tests__/src/components/ManifestListItem.test.js +++ b/__tests__/src/components/ManifestListItem.test.js @@ -42,4 +42,20 @@ describe('ManifestListItem', () => { expect(wrapper.find('WithStyles(ButtonBase)').length).toBe(1); expect(wrapper.find('WithStyles(ButtonBase) WithStyles(Typography)').children().text()).toEqual('http://example.com'); }); + + it('displays the provider information', () => { + const addWindow = jest.fn(); + const wrapper = shallow( + <ManifestListItem manifestId="http://example.com" ready provider="ACME" addWindow={addWindow} />, + ).dive(); + expect(wrapper.find('WithStyles(Typography).mirador-manifest-list-item-provider').children().text()).toEqual('ACME'); + }); + + it('displays a placeholder provider if no information is given', () => { + const addWindow = jest.fn(); + const wrapper = shallow( + <ManifestListItem manifestId="http://example.com" ready addWindow={addWindow} />, + ).dive(); + expect(wrapper.find('WithStyles(Typography).mirador-manifest-list-item-provider').children().text()).toEqual('addedFromUrl'); + }); }); diff --git a/__tests__/src/selectors/index.test.js b/__tests__/src/selectors/index.test.js index 485aca099187473508bbdd76dbee0e5c6e124b67..216d0efbd8d0a902722895314c7e082cb2ea3aba 100644 --- a/__tests__/src/selectors/index.test.js +++ b/__tests__/src/selectors/index.test.js @@ -2,6 +2,7 @@ import manifesto from 'manifesto.js'; import manifestFixture001 from '../../fixtures/version-2/001.json'; import manifestFixture002 from '../../fixtures/version-2/002.json'; import manifestFixture019 from '../../fixtures/version-2/019.json'; +import manifestFixtureWithAProvider from '../../fixtures/version-3/with_a_provider.json'; import { getCanvasLabel, getCompanionWindowForPosition, @@ -12,6 +13,7 @@ import { getManifestCanvases, getManifestDescription, getThumbnailNavigationPosition, + getManifestProvider, getManifestTitle, getManifestThumbnail, getWindowViewType, @@ -182,6 +184,24 @@ describe('getManifestDescription', () => { }); }); +describe('getManifestProvider', () => { + it('should return manifest provider label', () => { + const manifest = { manifestation: manifesto.create(manifestFixtureWithAProvider) }; + const received = getManifestProvider(manifest); + expect(received).toBe('Example Organization'); + }); + + it('should return undefined if manifest undefined', () => { + const received = getManifestProvider(undefined); + expect(received).toBeUndefined(); + }); + + it('should return undefined if no manifestation', () => { + const manifest = {}; + const received = getManifestProvider(manifest); + expect(received).toBeUndefined(); + }); +}); describe('getSelectedCanvas', () => { const state = { windows: { diff --git a/src/components/ManifestListItem.js b/src/components/ManifestListItem.js index 8132c2e59a9ded424d29b48cf667915fd4d6e3a0..ffdbce53f880079801cd7ff7e2af2835665177b8 100644 --- a/src/components/ManifestListItem.js +++ b/src/components/ManifestListItem.js @@ -87,7 +87,7 @@ class ManifestListItem extends React.Component { </ButtonBase> </Grid> <Grid item xs={8} sm={4}> - <Typography>{provider || t('addedFromUrl')}</Typography> + <Typography className={ns('manifest-list-item-provider')}>{provider || t('addedFromUrl')}</Typography> <Typography>{`${size} items`}</Typography> </Grid> diff --git a/src/containers/ManifestListItem.js b/src/containers/ManifestListItem.js index 59b60e44e046166a2e5e3185b5bc83c0849842fb..562f1e3c64bae771f1f56b95e5b95e6d298dbc0e 100644 --- a/src/containers/ManifestListItem.js +++ b/src/containers/ManifestListItem.js @@ -2,7 +2,7 @@ import { compose } from 'redux'; import { connect } from 'react-redux'; import { withNamespaces } from 'react-i18next'; import { - getManifestTitle, getManifestLogo, getManifestThumbnail, getManifestCanvases, + getManifestTitle, getManifestLogo, getManifestThumbnail, getManifestCanvases, getManifestProvider, } from '../state/selectors'; import * as actions from '../state/actions'; import ManifestListItem from '../components/ManifestListItem'; @@ -16,6 +16,7 @@ const mapStateToProps = (state, { manifestId }) => { title: getManifestTitle(manifest), logo: getManifestLogo(manifest), thumbnail: getManifestThumbnail(manifest), + provider: getManifestProvider(manifest), size: getManifestCanvases(manifest).length, }; }; diff --git a/src/state/selectors/index.js b/src/state/selectors/index.js index 1ff29544a7e0c7263ebd72f362ae889a7a5d0a6d..69a9c36462fc40e1fd04dcc09df0b1b822d00801 100644 --- a/src/state/selectors/index.js +++ b/src/state/selectors/index.js @@ -1,3 +1,4 @@ +import { LanguageMap } from 'manifesto.js'; /** * Return the manifest that belongs to a certain window. @@ -21,6 +22,23 @@ export function getManifestLogo(manifest) { && manifest.manifestation.getLogo(); } +/** +* Return the IIIF v3 provider of a manifest or null +* @param {object} manifest +* @return {String|null} +*/ +export function getManifestProvider(manifest) { + if (manifest && manifest.provider) { + return manifest.provider; + } + + return manifest + && manifest.manifestation + && manifest.manifestation.getProperty('provider') + && manifest.manifestation.getProperty('provider')[0].label + && LanguageMap.parse(manifest.manifestation.getProperty('provider')[0].label, manifest.manifestation.options.locale).map(label => label.value)[0]; +} + /** * Return the logo of a manifest or null * @param {object} manifest