Skip to content

Commit fba3b5d

Browse files
authored
Merge pull request #3927 from fstoe/bug_viewer_crash
fix:mirador_crash
2 parents 6d39c99 + 963a934 commit fba3b5d

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

__tests__/src/components/ManifestListItem.test.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { render, screen } from '@tests/utils/test-utils';
22
import userEvent from '@testing-library/user-event';
3-
3+
import { getManifestoInstance } from '../../../src/state/selectors';
44
import { ManifestListItem } from '../../../src/components/ManifestListItem';
55

66
/** */
@@ -46,6 +46,17 @@ describe('ManifestListItem', () => {
4646
expect(screen.getByText('The resource cannot be added:')).toBeInTheDocument();
4747
expect(screen.getByText('http://example.com')).toBeInTheDocument();
4848
});
49+
50+
it('renders an error message when fetched manifest is empty', () => {
51+
const state = { manifests: { x: { json: {} } } };
52+
const manifesto = getManifestoInstance(state, { manifestId: 'x' });
53+
54+
createWrapper({ error: !manifesto });
55+
56+
expect(screen.getByText('The resource cannot be added:')).toBeInTheDocument();
57+
expect(screen.getByText('http://example.com')).toBeInTheDocument();
58+
});
59+
4960
it('updates and adds window when button clicked', async () => {
5061
const user = userEvent.setup();
5162
const addWindow = vi.fn();

__tests__/src/selectors/manifests.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { Utils } from 'manifesto.js';
2+
3+
import collection from '../../fixtures/version-2/collection.json';
24
import manifestFixture001 from '../../fixtures/version-2/001.json';
35
import manifestFixture002 from '../../fixtures/version-2/002.json';
46
import manifestFixture019 from '../../fixtures/version-2/019.json';
@@ -7,6 +9,7 @@ import manifestFixturev3001 from '../../fixtures/version-3/001.json';
79
import manifestFixtureWithAProvider from '../../fixtures/version-3/with_a_provider.json';
810
import manifestFixtureFg165hz3589 from '../../fixtures/version-2/fg165hz3589.json';
911
import manifestFixtureRelated from '../../fixtures/version-2/related.json';
12+
1013
import {
1114
getManifestoInstance,
1215
getManifestLocale,

src/containers/ManifestListItem.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const mapStateToProps = (state, { manifestId, provider }) => {
2323
: getCanvases(state, { manifestId }).length;
2424
return {
2525
active: getWindowManifests(state).includes(manifestId),
26-
error: manifest.error,
26+
error: manifest.error || (!manifesto && !!manifest.json),
2727
isCollection,
2828
isFetching: manifest.isFetching,
2929
isMultipart: isCollection

src/state/selectors/manifests.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ function createManifestoInstance(json, locale) {
1111
if (!json) return undefined;
1212
// Use structuredClone to create a deep copy and prevent Manifesto from mutating the json
1313
const manifestoObject = Utils.parseManifest(structuredClone(json), locale ? { locale } : undefined);
14-
// Local patching of Manifesto so that when its a Collection, it behaves similarly
15-
if (typeof manifestoObject.getSequences != 'function') {
16-
manifestoObject.getSequences = () => [];
14+
if (manifestoObject) {
15+
// Local patching of Manifesto so that when its a Collection, it behaves similarly
16+
if (typeof manifestoObject.getSequences != 'function') {
17+
manifestoObject.getSequences = () => [];
18+
}
19+
return manifestoObject;
1720
}
18-
return manifestoObject;
21+
return undefined;
1922
}
2023

2124
/** */

0 commit comments

Comments
 (0)