Skip to content
Snippets Groups Projects
Commit df205124 authored by Chris Beer's avatar Chris Beer
Browse files

Refactor ManifestListItem test to use a createWrapper helper

parent 09f250ae
Branches
Tags
No related merge requests found
...@@ -2,60 +2,54 @@ import React from 'react'; ...@@ -2,60 +2,54 @@ import React from 'react';
import { shallow } from 'enzyme'; import { shallow } from 'enzyme';
import ManifestListItem from '../../../src/components/ManifestListItem'; import ManifestListItem from '../../../src/components/ManifestListItem';
describe('ManifestListItem', () => { /** */
it('renders without an error', () => { function createWrapper(props) {
const addWindow = jest.fn(); return shallow(
const wrapper = shallow(
<ManifestListItem <ManifestListItem
manifestId="http://example.com" manifestId="http://example.com"
title="xyz" title="xyz"
ready ready
addWindow={addWindow} addWindow={() => {}}
fetchManifest={() => {}}
t={t => t} t={t => t}
{...props}
/>, />,
).dive(); ).dive(); // to unwrapp HOC created by withStyle()
}
describe('ManifestListItem', () => {
it('renders without an error', () => {
const wrapper = createWrapper();
expect(wrapper.find('.mirador-manifest-list-item').length).toBe(1); expect(wrapper.find('.mirador-manifest-list-item').length).toBe(1);
expect(wrapper.find('WithStyles(ButtonBase)').length).toBe(1); expect(wrapper.find('WithStyles(ButtonBase)').length).toBe(1);
expect(wrapper.find('WithStyles(ButtonBase) WithStyles(Typography)').children().text()).toEqual('xyz'); expect(wrapper.find('WithStyles(ButtonBase) WithStyles(Typography)').children().text()).toEqual('xyz');
}); });
it('renders a placeholder element until real data is available', () => { it('renders a placeholder element until real data is available', () => {
const addWindow = jest.fn(); const wrapper = createWrapper({ ready: false });
const wrapper = shallow(
<ManifestListItem manifestId="http://example.com" addWindow={addWindow} />,
).dive();
expect(wrapper.find('.mirador-manifest-list-item').length).toBe(1); expect(wrapper.find('.mirador-manifest-list-item').length).toBe(1);
expect(wrapper.find('ReactPlaceholder').length).toBe(1); expect(wrapper.find('ReactPlaceholder').length).toBe(1);
}); });
it('updates and adds window when button clicked', () => { it('updates and adds window when button clicked', () => {
const addWindow = jest.fn(); const addWindow = jest.fn();
const wrapper = shallow( const wrapper = createWrapper({ addWindow });
<ManifestListItem manifestId="http://example.com" title="xyz" addWindow={addWindow} />,
).dive();
wrapper.find('WithStyles(ButtonBase)').simulate('click'); wrapper.find('WithStyles(ButtonBase)').simulate('click');
expect(addWindow).toHaveBeenCalledTimes(1); expect(addWindow).toHaveBeenCalledTimes(1);
}); });
it('uses the manifest id if the title is not available', () => { it('uses the manifest id if the title is not available', () => {
const addWindow = jest.fn(); const wrapper = createWrapper({ ready: true, title: null });
const wrapper = shallow(
<ManifestListItem manifestId="http://example.com" ready addWindow={addWindow} />,
).dive();
expect(wrapper.find('WithStyles(ButtonBase)').length).toBe(1); expect(wrapper.find('WithStyles(ButtonBase)').length).toBe(1);
expect(wrapper.find('WithStyles(ButtonBase) WithStyles(Typography)').children().text()).toEqual('http://example.com'); expect(wrapper.find('WithStyles(ButtonBase) WithStyles(Typography)').children().text()).toEqual('http://example.com');
}); });
it('displays the provider information', () => { it('displays the provider information', () => {
const addWindow = jest.fn(); const wrapper = createWrapper({ provider: 'ACME' });
const wrapper = shallow(
<ManifestListItem manifestId="http://example.com" ready provider="ACME" addWindow={addWindow} />,
).dive();
expect(wrapper.find('WithStyles(Typography).mirador-manifest-list-item-provider').children().text()).toEqual('ACME'); expect(wrapper.find('WithStyles(Typography).mirador-manifest-list-item-provider').children().text()).toEqual('ACME');
}); });
it('displays a placeholder provider if no information is given', () => { it('displays a placeholder provider if no information is given', () => {
const addWindow = jest.fn(); const wrapper = createWrapper();
const wrapper = shallow(
<ManifestListItem manifestId="http://example.com" ready addWindow={addWindow} />,
).dive();
expect(wrapper.find('WithStyles(Typography).mirador-manifest-list-item-provider').children().text()).toEqual('addedFromUrl'); expect(wrapper.find('WithStyles(Typography).mirador-manifest-list-item-provider').children().text()).toEqual('addedFromUrl');
}); });
}); });
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment