Change relative route to absolute route in CollectionItemLink
authorFrank Bessou <frank.bessou@logilab.fr>
Thu, 06 Apr 2017 11:59:07 +0200
changeset 88 3075a8f89265
parent 87 e788bdc3ea46
child 89 b7917282a980
Change relative route to absolute route in CollectionItemLink
src/components/BaseViews.js
test/index.js
--- a/src/components/BaseViews.js	Thu Apr 06 11:47:50 2017 +0200
+++ b/src/components/BaseViews.js	Thu Apr 06 11:59:07 2017 +0200
@@ -9,7 +9,7 @@
     // XXX Use schema link when it becomes available
     const id = entity.get('/id');
     return (
-        <Link to={`${etype}/${id}`}>
+        <Link to={`/${etype}/${id}`}>
             {entity.get('/title')}
         </Link>
     );
--- a/test/index.js	Thu Apr 06 11:47:50 2017 +0200
+++ b/test/index.js	Thu Apr 06 11:59:07 2017 +0200
@@ -121,26 +121,16 @@
 });
 
 describe('<CollectionItemLink />', () => {
-    beforeEach(() => {
-        sinon.stub(defaultApi, 'buildUrl').callsFake( x => `http://testing.com/${x}`);
-    });
-
-    afterEach(() => {
-        defaultApi.buildUrl.restore();
-    });
+    it('renders a link with title and proper URL', () => {
+        const entity = Jsonary.create({title: 'bob', id:'123'});
+        const wrapper = shallow(<CollectionItemLink entity={entity} etype={'user'}/>);
 
-    it('renders a link with dc_title and proper URL', () => {
-        const entity = {
-            eid: 123,
-            cw_etype: 'user',
-            dc_title: 'bob',
-        };
-        const wrapper = shallow(<CollectionItemLink entity={entity} />);
-        expect(wrapper.is('Link')).to.be.equal(true);
-        expect(wrapper.children().length).to.equal(1);
         const link = wrapper.render();
+
+        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('http://testing.com/user/123');
+        expect(wrapper.prop('to')).to.be.equal('/user/123');
     });
 
     it('renders a link with <etype> #<eid> when dc_title is not present', () => {