Extract tests related to BaseViews.js
authorFrank Bessou <frank.bessou@logilab.fr>
Fri, 30 Jun 2017 16:17:04 +0200
changeset 244 37258411b15b
parent 243 8ed13b832c31
child 245 ad59d03502e2
Extract tests related to BaseViews.js
src/components/BaseViews.spec.js
test/index.js
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/components/BaseViews.spec.js	Fri Jun 30 16:17:04 2017 +0200
@@ -0,0 +1,118 @@
+import * as React from 'react';
+import {PropTypes} from 'prop-types';
+import createRouterContext from 'react-router-test-context';
+import {shallow, render} from 'enzyme';
+import {expect} from 'chai';
+
+import {ActionLink, ActionsDropDown, CollectionItemLink} from './BaseViews';
+import {mapToSchema} from "../jsonaryutils";
+
+describe('<CollectionItemLink />', () => {
+    const renderOptions = {
+        context: createRouterContext(),
+        childContextTypes: {router: PropTypes.object},
+    };
+
+    it('renders a link with title and proper URL', () => {
+        const item = {title: 'bob', id: '123'};
+        const itemSchema = {links: [{rel: 'item', href: '/user/{id}'}]};
+        const wrappedItem = mapToSchema(item, itemSchema);
+        const component = <CollectionItemLink item={wrappedItem}/>;
+
+        const wrapper = shallow(component);
+        const link = render(component, renderOptions);
+
+        expect(wrapper.is('Link')).to.be.true;
+        expect(wrapper.children()).to.have.length(1);
+        expect(link.text()).to.be.equal('bob');
+        expect(wrapper.prop('to')).to.be.equal('/user/123');
+    });
+
+    it.skip('renders a download link for downloadable entity', () => {
+        const entity = {
+            eid: 123,
+            cw_etype: 'user',
+            dc_title: 'bob',
+            download_url: 'https://example.com/123/download',
+        };
+        const wrapper = shallow(<CollectionItemLink entity={entity} />);
+        expect(wrapper.is('div')).to.be.equal(true);
+        expect(wrapper.children().length).to.equal(3);
+        const link = wrapper.render();
+        expect(link.text()).to.contain('bob');
+        expect(wrapper.find('a').prop('href')).to.be.equal(
+            'https://example.com/123/download');
+    });
+
+    it.skip('renders a badge with workflow state', () => {
+        const entity = {
+            eid: 123,
+            cw_etype: 'user',
+            dc_title: 'bob',
+            workflow_state: 'jumping',
+        };
+        const wrapper = shallow(<CollectionItemLink entity={entity} />);
+        expect(wrapper.is('div')).to.be.equal(true);
+        expect(wrapper.children().length).to.equal(3);
+        expect(wrapper.find('span').text()).to.be.equal('jumping');
+    });
+});
+
+describe('<ActionsDropDown />', () => {
+    const targetResource = {
+        allowedActions: ["view", "create", "edit", "delete"],
+        url: "/here/",
+        data: {},
+    };
+
+    it('renders a dropdown button with actions from target', () => {
+        const wrapper = shallow(<ActionsDropDown target={targetResource}/>);
+        expect(wrapper.find('ActionLink')).to.have.length(4);
+        expect(wrapper.find({action: "view"})).to.have.length(1);
+    });
+
+    it('renders a dropdown button with actions from target but those in "ignore" array', () => {
+        const wrapper = shallow(<ActionsDropDown target={targetResource} ignore={["view"]}/>);
+        expect(wrapper.find('ActionLink')).to.have.length(3);
+        expect(wrapper.find({action: "view"})).to.have.length(0);
+    });
+
+});
+
+describe('<ActionLink />', () => {
+    let targetUrl;
+    beforeEach(() => {
+        targetUrl = "/any/123";
+    });
+
+    it('given an "add" action, it renders a link pointing to "add" view', () => {
+        const wrapper = shallow(<ActionLink targetUrl={targetUrl} action='add'/>);
+
+        expect(wrapper.is('Link')).to.be.equal(true);
+        expect(wrapper.prop('to')).to.be.equal('/any/123@@add');
+        expect(wrapper.prop('title')).to.be.equal('add');
+    });
+
+    it('given an "edit" action, it renders a link pointing to "edit" view', () => {
+        const wrapper = shallow(<ActionLink targetUrl={targetUrl} action='edit'/>);
+
+        expect(wrapper.is('Link')).to.be.equal(true);
+        expect(wrapper.prop('to')).to.be.equal( '/any/123@@edit');
+        expect(wrapper.prop('title')).to.be.equal('edit');
+    });
+
+    it('given a "delete" action, it renders a link pointing to "delete" view', () => {
+        const wrapper = shallow(<ActionLink targetUrl={targetUrl} action='delete'/>);
+
+        expect(wrapper.is('Link')).to.be.equal(true);
+        expect(wrapper.prop('to')).to.be.equal( '/any/123@@delete');
+        expect(wrapper.prop('title')).to.be.equal('delete');
+    });
+
+    it('given an unknown action, it renders nothing', () => {
+        const wrapper = shallow(<ActionLink targetUrl={targetUrl} action='foo'/>);
+
+        expect(wrapper.html()).to.be.equal(null);
+    });
+
+});
--- a/test/index.js	Fri Jun 30 15:55:44 2017 +0200
+++ b/test/index.js	Fri Jun 30 16:17:04 2017 +0200
@@ -1,11 +1,8 @@
 import chai from 'chai';
 import chaiAsPromised from 'chai-as-promised';
-import {shallow, render} from 'enzyme';
+import {shallow} from 'enzyme';
 import React from 'react';
-import {PropTypes} from 'prop-types';
-import createRouterContext from 'react-router-test-context';
 
-import {ActionLink, ActionsDropDown, CollectionItemLink} from '../src/components/BaseViews';
 import {mapToSchema} from "../src/jsonaryutils";
 import {
     Resource,
@@ -26,116 +23,6 @@
 const testsContext = require.context("../src", true, /.spec.js$/);
 testsContext.keys().forEach(testsContext);
 
-describe('<CollectionItemLink />', () => {
-    const renderOptions = {
-        context: createRouterContext(),
-        childContextTypes: {router: PropTypes.object},
-    };
-
-    it('renders a link with title and proper URL', () => {
-        const item = {title: 'bob', id: '123'};
-        const itemSchema = {links: [{rel: 'item', href: '/user/{id}'}]};
-        const wrappedItem = mapToSchema(item, itemSchema);
-        const component = <CollectionItemLink item={wrappedItem}/>;
-
-        const wrapper = shallow(component);
-        const link = render(component, renderOptions);
-
-        expect(wrapper.is('Link')).to.be.true;
-        expect(wrapper.children()).to.have.length(1);
-        expect(link.text()).to.be.equal('bob');
-        expect(wrapper.prop('to')).to.be.equal('/user/123');
-    });
-
-    it.skip('renders a download link for downloadable entity', () => {
-        const entity = {
-            eid: 123,
-            cw_etype: 'user',
-            dc_title: 'bob',
-            download_url: 'https://example.com/123/download',
-        };
-        const wrapper = shallow(<CollectionItemLink entity={entity} />);
-        expect(wrapper.is('div')).to.be.equal(true);
-        expect(wrapper.children().length).to.equal(3);
-        const link = wrapper.render();
-        expect(link.text()).to.contain('bob');
-        expect(wrapper.find('a').prop('href')).to.be.equal(
-            'https://example.com/123/download');
-    });
-
-    it.skip('renders a badge with workflow state', () => {
-        const entity = {
-            eid: 123,
-            cw_etype: 'user',
-            dc_title: 'bob',
-            workflow_state: 'jumping',
-        };
-        const wrapper = shallow(<CollectionItemLink entity={entity} />);
-        expect(wrapper.is('div')).to.be.equal(true);
-        expect(wrapper.children().length).to.equal(3);
-        expect(wrapper.find('span').text()).to.be.equal('jumping');
-    });
-});
-
-describe('<ActionsDropDown />', () => {
-    const targetResource = {
-        allowedActions: ["view", "create", "edit", "delete"],
-        url: "/here/",
-        data: {},
-    };
-
-    it('renders a dropdown button with actions from target', () => {
-        const wrapper = shallow(<ActionsDropDown target={targetResource}/>);
-        expect(wrapper.find('ActionLink')).to.have.length(4);
-        expect(wrapper.find({action: "view"})).to.have.length(1);
-    });
-
-    it('renders a dropdown button with actions from target but those in "ignore" array', () => {
-        const wrapper = shallow(<ActionsDropDown target={targetResource} ignore={["view"]}/>);
-        expect(wrapper.find('ActionLink')).to.have.length(3);
-        expect(wrapper.find({action: "view"})).to.have.length(0);
-    });
-
-});
-
-describe('<ActionLink />', () => {
-    let targetUrl;
-    beforeEach(() => {
-        targetUrl = "/any/123";
-    });
-
-    it('given an "add" action, it renders a link pointing to "add" view', () => {
-        const wrapper = shallow(<ActionLink targetUrl={targetUrl} action='add'/>);
-
-        expect(wrapper.is('Link')).to.be.equal(true);
-        expect(wrapper.prop('to')).to.be.equal('/any/123@@add');
-        expect(wrapper.prop('title')).to.be.equal('add');
-    });
-
-    it('given an "edit" action, it renders a link pointing to "edit" view', () => {
-        const wrapper = shallow(<ActionLink targetUrl={targetUrl} action='edit'/>);
-
-        expect(wrapper.is('Link')).to.be.equal(true);
-        expect(wrapper.prop('to')).to.be.equal( '/any/123@@edit');
-        expect(wrapper.prop('title')).to.be.equal('edit');
-    });
-
-    it('given a "delete" action, it renders a link pointing to "delete" view', () => {
-        const wrapper = shallow(<ActionLink targetUrl={targetUrl} action='delete'/>);
-
-        expect(wrapper.is('Link')).to.be.equal(true);
-        expect(wrapper.prop('to')).to.be.equal( '/any/123@@delete');
-        expect(wrapper.prop('title')).to.be.equal('delete');
-    });
-
-    it('given an unknown action, it renders nothing', () => {
-        const wrapper = shallow(<ActionLink targetUrl={targetUrl} action='foo'/>);
-
-        expect(wrapper.html()).to.be.equal(null);
-    });
-
-});
-
 describe('Resource', () => {
     it('should select "ResourceCreationForm" when action is "add"', () => {
         const params = {