Extract tests related to Resource.js
authorFrank Bessou <frank.bessou@logilab.fr>
Fri, 30 Jun 2017 16:19:51 +0200
changeset 245 ad59d03502e2
parent 244 37258411b15b
child 246 0bc5f2d1871a
Extract tests related to Resource.js
src/components/Resource.spec.js
test/index.js
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/components/Resource.spec.js	Fri Jun 30 16:19:51 2017 +0200
@@ -0,0 +1,97 @@
+import * as React from 'react';
+import {shallow} from 'enzyme';
+import {expect} from 'chai';
+
+import {mapToSchema} from "../jsonaryutils";
+import {
+    Resource,
+    ResourceCreationForm,
+    ResourceEditionForm,
+    ResourceView,
+    PaginatedResourceView,
+    ResourceDeletionView,
+} from './Resource';
+import {
+    ResourceCollectionView,
+    ResourceEntityView,
+} from '../views/Generics';
+
+describe('Resource', () => {
+    it('should select "ResourceCreationForm" when action is "add"', () => {
+        const params = {
+            apiUrl: '/book/',
+            action: 'add',
+        };
+        const wrapper = shallow(<Resource match={{params: params}}/>);
+        const component = wrapper.props().component;
+
+        expect(component).to.be.equal(ResourceCreationForm);
+    });
+
+    it('should select "ResourceEditionForm" when action is "edit"', () => {
+        const params = {
+            apiUrl: '/book/123',
+            action: 'edit',
+        };
+        const wrapper = shallow(<Resource match={{params: params}}/>);
+        const component = wrapper.props().component;
+
+        expect(component).to.be.equal(ResourceEditionForm);
+    });
+
+    it('should select "ResourceDeletionView" when action is "delete"', () => {
+        const params = {
+            apiUrl: '/book/123',
+            action: 'delete',
+        };
+        const wrapper = shallow(<Resource match={{params: params}}/>);
+        const component = wrapper.props().component;
+
+        expect(component).to.be.equal(ResourceDeletionView);
+    });
+
+    it('should select "PaginatedResourceView" when action is "view"', () => {
+        const params = {
+            apiUrl: '/book/123',
+            action: 'view',
+        };
+        const wrapper = shallow(<Resource match={{params: params}}/>);
+        const component = wrapper.props().component;
+
+        expect(component).to.be.equal(PaginatedResourceView);
+    });
+
+    it('should select "PaginatedResourceView" when action is not present', () => {
+        const params = {
+            apiUrl: '/book/123',
+            action: undefined,
+        };
+        const wrapper = shallow(<Resource match={{params: params}}/>);
+        const component = wrapper.props().component;
+
+        expect(component).to.be.equal(PaginatedResourceView);
+    });
+
+});
+
+describe('ResourceView', () => {
+    context('resource represents a collection', () => {
+        it('should render a ResourceCollectionView', () => {
+            const resource = {data: mapToSchema([], {type: 'array'})};
+            const wrapper = shallow(<ResourceView resource={resource}/>);
+
+            const view = <ResourceCollectionView data={resource.data} />;
+            expect(wrapper.contains(view)).to.be.true;
+        });
+    });
+
+    context('resource represents an entity', () => {
+        it('should render a ResourceCollectionView', () => {
+            const resource = {data: mapToSchema({}, {type: 'object'})};
+            const wrapper = shallow(<ResourceView resource={resource}/>);
+
+            const view = <ResourceEntityView data={resource.data} />;
+            expect(wrapper.contains(view)).to.be.true;
+        });
+    });
+});
--- a/test/index.js	Fri Jun 30 16:17:04 2017 +0200
+++ b/test/index.js	Fri Jun 30 16:19:51 2017 +0200
@@ -1,104 +1,7 @@
 import chai from 'chai';
 import chaiAsPromised from 'chai-as-promised';
-import {shallow} from 'enzyme';
-import React from 'react';
-
-import {mapToSchema} from "../src/jsonaryutils";
-import {
-    Resource,
-    ResourceCreationForm,
-    ResourceEditionForm,
-    ResourceView,
-    PaginatedResourceView,
-    ResourceDeletionView,
-} from '../src/components/Resource';
-import {
-    ResourceCollectionView,
-    ResourceEntityView,
-} from '../src/views/Generics';
-import {expect} from 'chai';
 
 chai.use(chaiAsPromised);
 
 const testsContext = require.context("../src", true, /.spec.js$/);
 testsContext.keys().forEach(testsContext);
-
-describe('Resource', () => {
-    it('should select "ResourceCreationForm" when action is "add"', () => {
-        const params = {
-            apiUrl: '/book/',
-            action: 'add',
-        };
-        const wrapper = shallow(<Resource match={{params: params}}/>);
-        const component = wrapper.props().component;
-
-        expect(component).to.be.equal(ResourceCreationForm);
-    });
-
-    it('should select "ResourceEditionForm" when action is "edit"', () => {
-        const params = {
-            apiUrl: '/book/123',
-            action: 'edit',
-        };
-        const wrapper = shallow(<Resource match={{params: params}}/>);
-        const component = wrapper.props().component;
-
-        expect(component).to.be.equal(ResourceEditionForm);
-    });
-
-    it('should select "ResourceDeletionView" when action is "delete"', () => {
-        const params = {
-            apiUrl: '/book/123',
-            action: 'delete',
-        };
-        const wrapper = shallow(<Resource match={{params: params}}/>);
-        const component = wrapper.props().component;
-
-        expect(component).to.be.equal(ResourceDeletionView);
-    });
-
-    it('should select "PaginatedResourceView" when action is "view"', () => {
-        const params = {
-            apiUrl: '/book/123',
-            action: 'view',
-        };
-        const wrapper = shallow(<Resource match={{params: params}}/>);
-        const component = wrapper.props().component;
-
-        expect(component).to.be.equal(PaginatedResourceView);
-    });
-
-    it('should select "PaginatedResourceView" when action is not present', () => {
-        const params = {
-            apiUrl: '/book/123',
-            action: undefined,
-        };
-        const wrapper = shallow(<Resource match={{params: params}}/>);
-        const component = wrapper.props().component;
-
-        expect(component).to.be.equal(PaginatedResourceView);
-    });
-
-});
-
-describe('ResourceView', () => {
-    context('resource represents a collection', () => {
-        it('should render a ResourceCollectionView', () => {
-            const resource = {data: mapToSchema([], {type: 'array'})};
-            const wrapper = shallow(<ResourceView resource={resource}/>);
-
-            const view = <ResourceCollectionView data={resource.data} />;
-            expect(wrapper.contains(view)).to.be.true;
-        });
-    });
-
-    context('resource represents an entity', () => {
-        it('should render a ResourceCollectionView', () => {
-            const resource = {data: mapToSchema({}, {type: 'object'})};
-            const wrapper = shallow(<ResourceView resource={resource}/>);
-
-            const view = <ResourceEntityView data={resource.data} />;
-            expect(wrapper.contains(view)).to.be.true;
-        });
-    });
-});