diff --git a/__tests__/src/components/ManifestListItem.test.js b/__tests__/src/components/ManifestListItem.test.js index ee8d39e9c..ec90f93e7 100644 --- a/__tests__/src/components/ManifestListItem.test.js +++ b/__tests__/src/components/ManifestListItem.test.js @@ -1,6 +1,6 @@ import { render, screen } from '@tests/utils/test-utils'; import userEvent from '@testing-library/user-event'; - +import { getManifestoInstance } from '../../../src/state/selectors'; import { ManifestListItem } from '../../../src/components/ManifestListItem'; /** */ @@ -46,6 +46,17 @@ describe('ManifestListItem', () => { expect(screen.getByText('The resource cannot be added:')).toBeInTheDocument(); expect(screen.getByText('http://example.com')).toBeInTheDocument(); }); + + it('renders an error message when fetched manifest is empty', () => { + const state = { manifests: { x: { json: {} } } }; + const manifesto = getManifestoInstance(state, { manifestId: 'x' }); + + createWrapper({ error: !manifesto }); + + expect(screen.getByText('The resource cannot be added:')).toBeInTheDocument(); + expect(screen.getByText('http://example.com')).toBeInTheDocument(); + }); + it('updates and adds window when button clicked', async () => { const user = userEvent.setup(); const addWindow = vi.fn(); diff --git a/__tests__/src/selectors/manifests.test.js b/__tests__/src/selectors/manifests.test.js index 68122efb9..bf14e2d0a 100644 --- a/__tests__/src/selectors/manifests.test.js +++ b/__tests__/src/selectors/manifests.test.js @@ -1,4 +1,6 @@ import { Utils } from 'manifesto.js'; + +import collection from '../../fixtures/version-2/collection.json'; import manifestFixture001 from '../../fixtures/version-2/001.json'; import manifestFixture002 from '../../fixtures/version-2/002.json'; import manifestFixture019 from '../../fixtures/version-2/019.json'; @@ -7,6 +9,7 @@ import manifestFixturev3001 from '../../fixtures/version-3/001.json'; import manifestFixtureWithAProvider from '../../fixtures/version-3/with_a_provider.json'; import manifestFixtureFg165hz3589 from '../../fixtures/version-2/fg165hz3589.json'; import manifestFixtureRelated from '../../fixtures/version-2/related.json'; + import { getManifestoInstance, getManifestLocale, diff --git a/src/containers/ManifestListItem.js b/src/containers/ManifestListItem.js index 2c030ab7b..0e8d92e30 100644 --- a/src/containers/ManifestListItem.js +++ b/src/containers/ManifestListItem.js @@ -23,7 +23,7 @@ const mapStateToProps = (state, { manifestId, provider }) => { : getCanvases(state, { manifestId }).length; return { active: getWindowManifests(state).includes(manifestId), - error: manifest.error, + error: manifest.error || (!manifesto && !!manifest.json), isCollection, isFetching: manifest.isFetching, isMultipart: isCollection diff --git a/src/state/selectors/manifests.js b/src/state/selectors/manifests.js index ec7e93ae0..8defeb901 100644 --- a/src/state/selectors/manifests.js +++ b/src/state/selectors/manifests.js @@ -11,11 +11,14 @@ function createManifestoInstance(json, locale) { if (!json) return undefined; // Use structuredClone to create a deep copy and prevent Manifesto from mutating the json const manifestoObject = Utils.parseManifest(structuredClone(json), locale ? { locale } : undefined); - // Local patching of Manifesto so that when its a Collection, it behaves similarly - if (typeof manifestoObject.getSequences != 'function') { - manifestoObject.getSequences = () => []; + if (manifestoObject) { + // Local patching of Manifesto so that when its a Collection, it behaves similarly + if (typeof manifestoObject.getSequences != 'function') { + manifestoObject.getSequences = () => []; + } + return manifestoObject; } - return manifestoObject; + return undefined; } /** */