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
No related branches found
No related tags found
No related merge requests found
......@@ -2,60 +2,54 @@ import React from 'react';
import { shallow } from 'enzyme';
import ManifestListItem from '../../../src/components/ManifestListItem';
describe('ManifestListItem', () => {
it('renders without an error', () => {
const addWindow = jest.fn();
const wrapper = shallow(
/** */
function createWrapper(props) {
return shallow(
<ManifestListItem
manifestId="http://example.com"
title="xyz"
ready
addWindow={addWindow}
addWindow={() => {}}
fetchManifest={() => {}}
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('WithStyles(ButtonBase)').length).toBe(1);
expect(wrapper.find('WithStyles(ButtonBase) WithStyles(Typography)').children().text()).toEqual('xyz');
});
it('renders a placeholder element until real data is available', () => {
const addWindow = jest.fn();
const wrapper = shallow(
<ManifestListItem manifestId="http://example.com" addWindow={addWindow} />,
).dive();
const wrapper = createWrapper({ ready: false });
expect(wrapper.find('.mirador-manifest-list-item').length).toBe(1);
expect(wrapper.find('ReactPlaceholder').length).toBe(1);
});
it('updates and adds window when button clicked', () => {
const addWindow = jest.fn();
const wrapper = shallow(
<ManifestListItem manifestId="http://example.com" title="xyz" addWindow={addWindow} />,
).dive();
const wrapper = createWrapper({ addWindow });
wrapper.find('WithStyles(ButtonBase)').simulate('click');
expect(addWindow).toHaveBeenCalledTimes(1);
});
it('uses the manifest id if the title is not available', () => {
const addWindow = jest.fn();
const wrapper = shallow(
<ManifestListItem manifestId="http://example.com" ready addWindow={addWindow} />,
).dive();
const wrapper = createWrapper({ ready: true, title: null });
expect(wrapper.find('WithStyles(ButtonBase)').length).toBe(1);
expect(wrapper.find('WithStyles(ButtonBase) WithStyles(Typography)').children().text()).toEqual('http://example.com');
});
it('displays the provider information', () => {
const addWindow = jest.fn();
const wrapper = shallow(
<ManifestListItem manifestId="http://example.com" ready provider="ACME" addWindow={addWindow} />,
).dive();
const wrapper = createWrapper({ provider: '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', () => {
const addWindow = jest.fn();
const wrapper = shallow(
<ManifestListItem manifestId="http://example.com" ready addWindow={addWindow} />,
).dive();
const wrapper = createWrapper();
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