Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:mirador_crash #3927

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
13 changes: 12 additions & 1 deletion __tests__/src/components/ManifestListItem.test.js
Original file line number Diff line number Diff line change
@@ -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';

/** */
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions __tests__/src/selectors/manifests.test.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/containers/ManifestListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
isCollection,
isFetching: manifest.isFetching,
isMultipart: isCollection
Expand Down
11 changes: 7 additions & 4 deletions src/state/selectors/manifests.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
if (!json) return undefined;
// Use JSON stringify/parse to create a deep copy and prevent Manifesto from mutating the json
const manifestoObject = Utils.parseManifest(JSON.parse(JSON.stringify(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 = () => [];
}

Check warning on line 18 in src/state/selectors/manifests.js

View check run for this annotation

Codecov / codecov/patch

src/state/selectors/manifests.js#L17-L18

Added lines #L17 - L18 were not covered by tests
return manifestoObject;
}
return manifestoObject;
return undefined;
}

/** */
Expand Down
Loading