Skip to content
Snippets Groups Projects
Unverified Commit 4b4f4032 authored by Chris Beer's avatar Chris Beer Committed by GitHub
Browse files

Merge pull request #1821 from ProjectMirador/refactor-workspace-component

Refactor <Workspace/> component.
parents 6b1d1af0 45550473
No related branches found
No related tags found
No related merge requests found
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';
describe('Workspace', () => {
const windows = { 1: { id: 1 }, 2: { id: 2 } };
let wrapper;
beforeEach(() => {
wrapper = shallow(
<Workspace
windows={windows}
config={{ workspace: { type: 'mosaic' } }}
/>,
describe('Workspace', () => {
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('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', () => {
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 }} />
......
......@@ -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;
......@@ -9,7 +9,7 @@ import Workspace from '../components/Workspace';
*/
const mapStateToProps = state => (
{
config: state.config,
workspaceType: state.config.workspace.type,
windows: state.windows,
}
);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment