diff --git a/__tests__/src/components/Workspace.test.js b/__tests__/src/components/Workspace.test.js index 138523c2b169aa9f09efe8d0b523a58622f37368..d8584fa81af5774a3603e53e31fe8aee5af23343 100644 --- a/__tests__/src/components/Workspace.test.js +++ b/__tests__/src/components/Workspace.test.js @@ -1,34 +1,31 @@ import React from 'react'; import { shallow } from 'enzyme'; -import Workspace from '../../../src/components/Workspace'; +import WorkspaceMosaic from '../../../src/containers/WorkspaceMosaic'; import Window from '../../../src/containers/Window'; +import Workspace from '../../../src/components/Workspace'; + +const windows = { 1: { id: 1 }, 2: { id: 2 } }; describe('Workspace', () => { - const windows = { 1: { id: 1 }, 2: { id: 2 } }; - let wrapper; - beforeEach(() => { - wrapper = shallow( - <Workspace - windows={windows} - config={{ workspace: { type: 'mosaic' } }} - />, - ); - }); - it('should render properly', () => { - expect(wrapper.find('.mirador-workspace').length).toBe(1); - expect(wrapper.find('Connect(WorkspaceMosaic)').length).toBe(1); - }); - describe('workspaceByType', () => { - it('when mosaic', () => { - expect(wrapper.find('Connect(WorkspaceMosaic)').length).toBe(1); + describe('if workspace type is mosaic', () => { + it('should render <WorkspaceMosaic/> properly', () => { + const wrapper = shallow( + <Workspace windows={windows} workspaceType="mosaic" />, + ); + + expect(wrapper.matchesElement( + <div className="mirador-workspace"> + <WorkspaceMosaic windows={windows} /> + </div>, + )).toBe(true); }); - it('anything else', () => { - wrapper = shallow( - <Workspace - windows={windows} - config={{ workspace: { type: 'foo' } }} - />, + }); + describe('if workspace type is unknown', () => { + it('should render <Window/> components as list', () => { + const wrapper = shallow( + <Workspace windows={windows} workspaceType="bubu" />, ); + expect(wrapper.matchesElement( <div className="mirador-workspace"> <Window window={{ id: 1 }} /> diff --git a/src/components/Workspace.js b/src/components/Workspace.js index 35cef899bf2e6092c1b19064a4a243cc30fa9f72..0fc01ce0e2c8b74d13aeadbb82b188b0693a2e82 100644 --- a/src/components/Workspace.js +++ b/src/components/Workspace.js @@ -10,20 +10,12 @@ import ns from '../config/css-ns'; * @private */ class Workspace extends React.Component { - /** - */ - constructor(props) { - super(props); - - this.workspaceByType = this.workspaceByType.bind(this); - } - /** * Determine which workspace to render by configured type */ workspaceByType() { - const { config, windows } = this.props; - switch (config.workspace.type) { + const { workspaceType, windows } = this.props; + switch (workspaceType) { case 'mosaic': return <WorkspaceMosaic windows={windows} />; default: @@ -50,7 +42,7 @@ class Workspace extends React.Component { Workspace.propTypes = { windows: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types - config: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types + workspaceType: PropTypes.string.isRequired, // eslint-disable-line react/forbid-prop-types }; export default Workspace; diff --git a/src/containers/Workspace.js b/src/containers/Workspace.js index a86a81739d1cb8099d0ce6e70ced1b4df2e9e302..34274fc228850c9b468057ca7fd832945f88ec61 100644 --- a/src/containers/Workspace.js +++ b/src/containers/Workspace.js @@ -9,7 +9,7 @@ import Workspace from '../components/Workspace'; */ const mapStateToProps = state => ( { - config: state.config, + workspaceType: state.config.workspace.type, windows: state.windows, } );