Extract tests related to Entity.js
authorFrank Bessou <frank.bessou@logilab.fr>
Fri, 30 Jun 2017 15:55:44 +0200
changeset 243 8ed13b832c31
parent 242 db082354de16
child 244 37258411b15b
Extract tests related to Entity.js
src/components/Entity.spec.js
test/index.js
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/components/Entity.spec.js	Fri Jun 30 15:55:44 2017 +0200
@@ -0,0 +1,131 @@
+import * as React from 'react';
+import {expect} from 'chai';
+import {shallow, render} from 'enzyme';
+
+import {EntityAttributes, EntityMeta} from './Entity';
+import {mapToSchema} from '../jsonaryutils';
+
+describe('<EntityAttributes />', () => {
+
+    it('Use the schema title of an attribute when it exists', () => {
+        const instance = {
+            name: 'A_NAME',
+        };
+        const schema = {
+            properties: {
+                name: {type: 'string', title: 'Title'},
+                description: {type: 'string', title: 'Description'},
+            },
+            type: 'object',
+        };
+        const entity = mapToSchema(instance, schema);
+        const wrapper = render(<EntityAttributes data={entity} />);
+        expect(wrapper.find('th').eq(0).text()).to.be.equal('Title');
+        expect(wrapper.find('th').eq(1).text()).to.be.equal('Description');
+    });
+});
+
+describe('<EntityMeta />', () => {
+
+    const schemaWithoutDates = {
+        properties: {
+            id: {
+                type: 'string',
+            },
+        },
+    };
+
+    const dataWithoutDates = {
+        id: 'ABCD',
+    };
+
+    const dataWithDates = {
+        created_at: '2017-10-21T00:00:00.000Z',
+        updated_at: '2015-07-15T00:00:00.000Z',
+    };
+
+    const schemaWithDatesWithoutTitles = {
+        properties: {
+            created_at: {
+                type: 'string',
+            },
+            updated_at: {
+                type: 'string',
+            },
+        },
+    };
+
+    const createdAtTitle = 'posted';
+    const updatedAtTitle = 'last update';
+    const schemaWithDatesWithTitles = {
+        properties: {
+            created_at: {
+                type: 'string',
+                title: createdAtTitle,
+            },
+            updated_at: {
+                type: 'string',
+                title: updatedAtTitle,
+            },
+        },
+    };
+
+    describe('with data containing "created_at" and "updated_at" properties', () => {
+
+        it('renders something', () => {
+            const entity = mapToSchema(dataWithDates, schemaWithoutDates);
+
+            const wrapper = shallow(<EntityMeta data={entity}/>);
+            expect(wrapper.html()).to.not.be.equal(null);
+
+        });
+
+        it('renders the dates', () => {
+
+            const entity = mapToSchema(dataWithDates, schemaWithoutDates);
+
+            const wrapper = shallow(<EntityMeta data={entity}/>);
+            expect(wrapper.html()).to.contain('2017');
+            expect(wrapper.html()).to.contain('2015');
+
+        });
+
+        it('renders "created at" when the "created_at" property has no title', () => {
+            const entity = mapToSchema(dataWithDates, schemaWithDatesWithoutTitles);
+
+            const wrapper = shallow(<EntityMeta data={entity}/>);
+            expect(wrapper.html()).to.contain('created at');
+        });
+
+        it('renders "updated at" when the "updated_at" property has no title', () => {
+            const entity = mapToSchema(dataWithDates, schemaWithDatesWithoutTitles);
+
+            const wrapper = shallow(<EntityMeta data={entity}/>);
+            expect(wrapper.html()).to.contain('updated at');
+        });
+
+        it('renders the "created_at" property\'s title when it exists', () => {
+            const entity = mapToSchema(dataWithDates, schemaWithDatesWithTitles);
+
+            const wrapper = shallow(<EntityMeta data={entity}/>);
+            expect(wrapper.html()).to.contain(createdAtTitle);
+        });
+
+        it('renders the "updated_at" property\'s title when it exists', () => {
+            const entity = mapToSchema(dataWithDates, schemaWithDatesWithTitles);
+
+            const wrapper = shallow(<EntityMeta data={entity}/>);
+            expect(wrapper.html()).to.contain(updatedAtTitle);
+        });
+
+    });
+
+    it('renders nothing when data contains neither "created_at" nor "updated_at" property', () => {
+        const entity = mapToSchema(dataWithoutDates, schemaWithoutDates);
+
+        const wrapper = shallow(<EntityMeta data={entity}/>);
+        expect(wrapper.html()).to.be.equal(null);
+
+    });
+
+});
--- a/test/index.js	Fri Jun 30 15:43:49 2017 +0200
+++ b/test/index.js	Fri Jun 30 15:55:44 2017 +0200
@@ -6,7 +6,6 @@
 import createRouterContext from 'react-router-test-context';
 
 import {ActionLink, ActionsDropDown, CollectionItemLink} from '../src/components/BaseViews';
-import {EntityMeta, EntityAttributes} from '../src/components/Entity';
 import {mapToSchema} from "../src/jsonaryutils";
 import {
     Resource,
@@ -137,131 +136,6 @@
 
 });
 
-describe('<EntityAttributes />', () => {
-
-    it('Use the schema title of an attribute when it exists', () => {
-        const instance = {
-            name: 'A_NAME',
-        };
-        const schema = {
-            properties: {
-                name: {type: 'string', title: 'Title'},
-                description: {type: 'string', title: 'Description'},
-            },
-            type: 'object',
-        };
-        const entity = mapToSchema(instance, schema);
-        const wrapper = render(<EntityAttributes data={entity} />);
-        expect(wrapper.find('th').eq(0).text()).to.be.equal('Title');
-        expect(wrapper.find('th').eq(1).text()).to.be.equal('Description');
-    });
-});
-
-describe('<EntityMeta />', () => {
-
-    const schemaWithoutDates = {
-        properties: {
-            id: {
-                type: 'string',
-            },
-        },
-    };
-
-    const dataWithoutDates = {
-        id: 'ABCD',
-    };
-
-    const dataWithDates = {
-        created_at: '2017-10-21T00:00:00.000Z',
-        updated_at: '2015-07-15T00:00:00.000Z',
-    };
-
-    const schemaWithDatesWithoutTitles = {
-        properties: {
-            created_at: {
-                type: 'string',
-            },
-            updated_at: {
-                type: 'string',
-            },
-        },
-    };
-
-    const createdAtTitle = 'posted';
-    const updatedAtTitle = 'last update';
-    const schemaWithDatesWithTitles = {
-        properties: {
-            created_at: {
-                type: 'string',
-                title: createdAtTitle,
-            },
-            updated_at: {
-                type: 'string',
-                title: updatedAtTitle,
-            },
-        },
-    };
-
-    describe('with data containing "created_at" and "updated_at" properties', () => {
-
-        it('renders something', () => {
-            const entity = mapToSchema(dataWithDates, schemaWithoutDates);
-
-            const wrapper = shallow(<EntityMeta data={entity}/>);
-            expect(wrapper.html()).to.not.be.equal(null);
-
-        });
-
-        it('renders the dates', () => {
-
-            const entity = mapToSchema(dataWithDates, schemaWithoutDates);
-
-            const wrapper = shallow(<EntityMeta data={entity}/>);
-            expect(wrapper.html()).to.contain('2017');
-            expect(wrapper.html()).to.contain('2015');
-
-        });
-
-        it('renders "created at" when the "created_at" property has no title', () => {
-            const entity = mapToSchema(dataWithDates, schemaWithDatesWithoutTitles);
-
-            const wrapper = shallow(<EntityMeta data={entity}/>);
-            expect(wrapper.html()).to.contain('created at');
-        });
-
-        it('renders "updated at" when the "updated_at" property has no title', () => {
-            const entity = mapToSchema(dataWithDates, schemaWithDatesWithoutTitles);
-
-            const wrapper = shallow(<EntityMeta data={entity}/>);
-            expect(wrapper.html()).to.contain('updated at');
-        });
-
-        it('renders the "created_at" property\'s title when it exists', () => {
-            const entity = mapToSchema(dataWithDates, schemaWithDatesWithTitles);
-
-            const wrapper = shallow(<EntityMeta data={entity}/>);
-            expect(wrapper.html()).to.contain(createdAtTitle);
-        });
-
-        it('renders the "updated_at" property\'s title when it exists', () => {
-            const entity = mapToSchema(dataWithDates, schemaWithDatesWithTitles);
-
-            const wrapper = shallow(<EntityMeta data={entity}/>);
-            expect(wrapper.html()).to.contain(updatedAtTitle);
-        });
-
-    });
-
-    it('renders nothing when data contains neither "created_at" nor "updated_at" property', () => {
-        const entity = mapToSchema(dataWithoutDates, schemaWithoutDates);
-
-        const wrapper = shallow(<EntityMeta data={entity}/>);
-        expect(wrapper.html()).to.be.equal(null);
-
-    });
-
-});
-
 describe('Resource', () => {
     it('should select "ResourceCreationForm" when action is "add"', () => {
         const params = {