Skip to content
Snippets Groups Projects
Commit 45550473 authored by Mathias Maaß's avatar Mathias Maaß Committed by Mathias Maaß
Browse files

Refactor <Workspace/> component.

parent 6b1d1af0
No related branches found
No related tags found
No related merge requests found
import React from 'react'; import React from 'react';
import { shallow } from 'enzyme'; import { shallow } from 'enzyme';
import Workspace from '../../../src/components/Workspace'; import WorkspaceMosaic from '../../../src/containers/WorkspaceMosaic';
import Window from '../../../src/containers/Window'; import Window from '../../../src/containers/Window';
import Workspace from '../../../src/components/Workspace';
describe('Workspace', () => {
const windows = { 1: { id: 1 }, 2: { id: 2 } }; const windows = { 1: { id: 1 }, 2: { id: 2 } };
let wrapper;
beforeEach(() => { describe('Workspace', () => {
wrapper = shallow( describe('if workspace type is mosaic', () => {
<Workspace it('should render <WorkspaceMosaic/> properly', () => {
windows={windows} const wrapper = shallow(
config={{ workspace: { type: 'mosaic' } }} <Workspace windows={windows} workspaceType="mosaic" />,
/>,
); );
expect(wrapper.matchesElement(
<div className="mirador-workspace">
<WorkspaceMosaic windows={windows} />
</div>,
)).toBe(true);
}); });
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);
}); });
it('anything else', () => { describe('if workspace type is unknown', () => {
wrapper = shallow( it('should render <Window/> components as list', () => {
<Workspace const wrapper = shallow(
windows={windows} <Workspace windows={windows} workspaceType="bubu" />,
config={{ workspace: { type: 'foo' } }}
/>,
); );
expect(wrapper.matchesElement( expect(wrapper.matchesElement(
<div className="mirador-workspace"> <div className="mirador-workspace">
<Window window={{ id: 1 }} /> <Window window={{ id: 1 }} />
......
...@@ -10,20 +10,12 @@ import ns from '../config/css-ns'; ...@@ -10,20 +10,12 @@ import ns from '../config/css-ns';
* @private * @private
*/ */
class Workspace extends React.Component { class Workspace extends React.Component {
/**
*/
constructor(props) {
super(props);
this.workspaceByType = this.workspaceByType.bind(this);
}
/** /**
* Determine which workspace to render by configured type * Determine which workspace to render by configured type
*/ */
workspaceByType() { workspaceByType() {
const { config, windows } = this.props; const { workspaceType, windows } = this.props;
switch (config.workspace.type) { switch (workspaceType) {
case 'mosaic': case 'mosaic':
return <WorkspaceMosaic windows={windows} />; return <WorkspaceMosaic windows={windows} />;
default: default:
...@@ -50,7 +42,7 @@ class Workspace extends React.Component { ...@@ -50,7 +42,7 @@ class Workspace extends React.Component {
Workspace.propTypes = { Workspace.propTypes = {
windows: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types 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; export default Workspace;
...@@ -9,7 +9,7 @@ import Workspace from '../components/Workspace'; ...@@ -9,7 +9,7 @@ import Workspace from '../components/Workspace';
*/ */
const mapStateToProps = state => ( const mapStateToProps = state => (
{ {
config: state.config, workspaceType: state.config.workspace.type,
windows: state.windows, windows: state.windows,
} }
); );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment