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

Refactor WorkspaceMosaic tests to use a createWrapper helper

parent 5201f5b8
Branches
Tags
No related merge requests found
...@@ -3,17 +3,23 @@ import { shallow } from 'enzyme'; ...@@ -3,17 +3,23 @@ import { shallow } from 'enzyme';
import { Mosaic } from 'react-mosaic-component'; import { Mosaic } from 'react-mosaic-component';
import WorkspaceMosaic from '../../../src/components/WorkspaceMosaic'; import WorkspaceMosaic from '../../../src/components/WorkspaceMosaic';
describe('WorkspaceMosaic', () => { /** create wrapper */
const windows = { 1: { id: 1 }, 2: { id: 2 } }; function createWrapper(props) {
let wrapper; return shallow(
beforeEach(() => {
wrapper = shallow(
<WorkspaceMosaic <WorkspaceMosaic
windows={windows} windows={{}}
workspace={{}} workspace={{}}
updateWorkspaceMosaicLayout={() => {}} updateWorkspaceMosaicLayout={() => {}}
{...props}
/>, />,
); );
}
describe('WorkspaceMosaic', () => {
const windows = { 1: { id: 1 }, 2: { id: 2 } };
let wrapper;
beforeEach(() => {
wrapper = createWrapper({ windows });
}); });
it('should render properly with an initialValue', () => { it('should render properly with an initialValue', () => {
expect(wrapper.matchesElement( expect(wrapper.matchesElement(
...@@ -22,25 +28,13 @@ describe('WorkspaceMosaic', () => { ...@@ -22,25 +28,13 @@ describe('WorkspaceMosaic', () => {
}); });
describe('determineWorkspaceLayout', () => { describe('determineWorkspaceLayout', () => {
it('when window ids do not match workspace layout', () => { it('when window ids do not match workspace layout', () => {
wrapper = shallow( wrapper = createWrapper({ windows, workspace: { layout: 'foo' } });
<WorkspaceMosaic
windows={windows}
workspace={{ layout: 'foo' }}
updateWorkspaceMosaicLayout={() => {}}
/>,
);
expect(wrapper.instance().determineWorkspaceLayout()).toMatchObject({ expect(wrapper.instance().determineWorkspaceLayout()).toMatchObject({
direction: 'row', first: '1', second: '2', direction: 'row', first: '1', second: '2',
}); });
}); });
it('when window ids match workspace layout', () => { it('when window ids match workspace layout', () => {
wrapper = shallow( wrapper = createWrapper({ windows: { foo: { id: 'foo' } }, workspace: { layout: 'foo' } });
<WorkspaceMosaic
windows={{ foo: { id: 'foo' } }}
workspace={{ layout: 'foo' }}
updateWorkspaceMosaicLayout={() => {}}
/>,
);
expect(wrapper.instance().determineWorkspaceLayout()).toBeNull(); expect(wrapper.instance().determineWorkspaceLayout()).toBeNull();
}); });
}); });
...@@ -54,16 +48,11 @@ describe('WorkspaceMosaic', () => { ...@@ -54,16 +48,11 @@ describe('WorkspaceMosaic', () => {
}); });
describe('mosaicChange', () => { describe('mosaicChange', () => {
it('calls the provided prop to update layout', () => { it('calls the provided prop to update layout', () => {
const mock = jest.fn(); const updateWorkspaceMosaicLayout = jest.fn();
wrapper = shallow( wrapper = createWrapper({ windows, updateWorkspaceMosaicLayout });
<WorkspaceMosaic
windows={{ foo: { id: 'foo' } }}
workspace={{ layout: 'foo' }}
updateWorkspaceMosaicLayout={mock}
/>,
);
wrapper.instance().mosaicChange(); wrapper.instance().mosaicChange();
expect(mock).toBeCalled(); expect(updateWorkspaceMosaicLayout).toBeCalled();
}); });
}); });
}); });
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment