From 829ec4f9f983b5ee2140cfac39eb50f9e7d500f1 Mon Sep 17 00:00:00 2001 From: Jessie Keck <jessie.keck@gmail.com> Date: Tue, 19 Feb 2019 15:05:52 -0800 Subject: [PATCH] Render ManifestListItemError when the manifest error is sent in as a prop. --- __tests__/fixtures/version-2/broken.json | 6 +++++ .../mirador/invalid-api-response.test.js | 23 ++++++++++++++++++- .../src/components/ManifestListItem.test.js | 3 ++- src/components/ManifestListItem.js | 3 ++- 4 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 __tests__/fixtures/version-2/broken.json diff --git a/__tests__/fixtures/version-2/broken.json b/__tests__/fixtures/version-2/broken.json new file mode 100644 index 000000000..2b84515e2 --- /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 8bc544ad8..4cec57481 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 b6084286d..f3c85f267 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 ade9413cd..6f91563f5 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> ); } -- GitLab