From 455504735b38fc87eb188fae87b8f259512e432a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mathias=20Maa=C3=9F?= <mathias.maass@uni-leipzig.de>
Date: Wed, 6 Feb 2019 13:05:44 +0100
Subject: [PATCH] Refactor <Workspace/> component.

---
 __tests__/src/components/Workspace.test.js | 45 ++++++++++------------
 src/components/Workspace.js                | 14 ++-----
 src/containers/Workspace.js                |  2 +-
 3 files changed, 25 insertions(+), 36 deletions(-)

diff --git a/__tests__/src/components/Workspace.test.js b/__tests__/src/components/Workspace.test.js
index 138523c2b..d8584fa81 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 35cef899b..0fc01ce0e 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 a86a81739..34274fc22 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,
   }
 );
-- 
GitLab