diff --git a/__tests__/fixtures/version-2/broken.json b/__tests__/fixtures/version-2/broken.json new file mode 100644 index 0000000000000000000000000000000000000000..2b84515e2736c7d43339eee33678bb8c9d53e650 --- /dev/null +++ b/__tests__/fixtures/version-2/broken.json @@ -0,0 +1,6 @@ +<html> + <title>Error</title> + <body> + <p>Something went wrong</p> + </body> +</html> diff --git a/__tests__/integration/mirador/invalid-api-response.test.js b/__tests__/integration/mirador/invalid-api-response.test.js index 8bc544ad8f837b71bc26b8c2a889fcfb1776b998..4cec574815a8ae86f09e7b1fa10c88c012c8b812 100644 --- a/__tests__/integration/mirador/invalid-api-response.test.js +++ b/__tests__/integration/mirador/invalid-api-response.test.js @@ -1,5 +1,5 @@ describe('Mirador Invalid API Response Handler Test', () => { - beforeAll(async () => { + beforeEach(async () => { await page.goto('http://127.0.0.1:4488/__tests__/integration/mirador/'); }); it('breaks Mirador', async () => { @@ -14,4 +14,25 @@ describe('Mirador Invalid API Response Handler Test', () => { expect(e.name).toMatch('TimeoutError'); } }); + + it('renders an error message when a manifest cannot be loaded (and allows it to be dismissed)', async () => { + await expect(page).toClick('#addBtn'); + await expect(page).toFill('#manifestURL', 'http://localhost:5000/api/broken'); + await expect(page).toClick('#fetchBtn'); + + await page.waitFor(1000); + + await expect(page).toMatchElement( + 'p', { text: 'The resource cannot be added:' }, + ); + await expect(page).toMatchElement( + 'p', { text: 'http://localhost:5000/api/broken' }, + ); + + await expect(page).toClick('button', { text: 'Dismiss' }); + await expect(page).not.toMatchElement( + 'p', + { text: 'The resource http://localhost:5000/api/broken cannot be added.' }, + ); + }); }); diff --git a/__tests__/src/components/ManifestListItem.test.js b/__tests__/src/components/ManifestListItem.test.js index b6084286d9edeef8100f8609366faa124823f58b..f3c85f267e08c931a273e443c99c6b0e819cb188 100644 --- a/__tests__/src/components/ManifestListItem.test.js +++ b/__tests__/src/components/ManifestListItem.test.js @@ -1,6 +1,7 @@ import React from 'react'; import { shallow } from 'enzyme'; import ManifestListItem from '../../../src/components/ManifestListItem'; +import ManifestListItemError from '../../../src/containers/ManifestListItemError'; /** */ function createWrapper(props) { @@ -34,7 +35,7 @@ describe('ManifestListItem', () => { const wrapper = createWrapper({ error: 'This is an error message' }); expect(wrapper.find('WithStyles(Paper)').length).toBe(1); - expect(wrapper.find('WithStyles(Paper)').children().text()).toEqual('This is an error message'); + expect(wrapper.find(ManifestListItemError).length).toBe(1); }); it('updates and adds window when button clicked', () => { const addWindow = jest.fn(); diff --git a/src/components/ManifestListItem.js b/src/components/ManifestListItem.js index ade9413cd04a8f91e1062293673c9c11d96b07f7..6f91563f5ec041781a797855c4c7339edc3b77c2 100644 --- a/src/components/ManifestListItem.js +++ b/src/components/ManifestListItem.js @@ -7,6 +7,7 @@ import Grid from '@material-ui/core/Grid'; import Typography from '@material-ui/core/Typography'; import ReactPlaceholder from 'react-placeholder'; import { TextBlock, TextRow, RectShape } from 'react-placeholder/lib/placeholders'; +import ManifestListItemError from '../containers/ManifestListItemError'; import WindowIcon from './WindowIcon'; import ns from '../config/css-ns'; import 'react-placeholder/lib/reactPlaceholder.css'; @@ -71,7 +72,7 @@ class ManifestListItem extends React.Component { if (error) { return ( <Paper elevation={1} className={classes.root} data-manifestid={manifestId}> - {error} + <ManifestListItemError manifestId={manifestId} /> </Paper> ); }