From 51ba521f5758b8d11cfac0f03a5f47318daaea74 Mon Sep 17 00:00:00 2001 From: tomoversluizen Date: Fri, 9 Jun 2017 11:08:32 +0200 Subject: [PATCH 1/3] created component test for avater --- test/avatar/index.test.js | 50 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 test/avatar/index.test.js diff --git a/test/avatar/index.test.js b/test/avatar/index.test.js new file mode 100644 index 00000000..d46ddbf1 --- /dev/null +++ b/test/avatar/index.test.js @@ -0,0 +1,50 @@ +/* eslint-env mocha */ +/* eslint react/jsx-filename-extension: [0] */ +import React from 'react'; +import chai, { expect } from 'chai'; +import { shallow } from 'enzyme'; +import sinon from 'sinon'; +import sinonChai from 'sinon-chai'; +import Avatar from '../../src/avatar'; +import getStyles from '../../src/alert/get-styles'; + +chai.use(sinonChai); +global.navigator = { userAgent: 'all' }; + +describe('Avatar.index', () => { + const props = { + style: {}, + status: '', + statusStyle: {}, + image: '' + }; + + it('should always render a section element', () => { + const wrapper = shallow().dive(); + + expect(wrapper.find('section')).to.have.length(1); + }); + + it('should render a div element when the status prop is passed', () => { + props.status = 'online'; + const wrapper = shallow().dive(); + + expect(wrapper.find('div')).to.have.length(1); + props.status = ''; + }); + + it('should get root styles', () => { + getStyles.root.restore(); + const spy = sinon.spy(getStyles, 'root'); + + shallow().dive(); + expect(spy).to.have.been.calledWith(props.image, props.style); + }); + + it('should get status styles', () => { + const spy = sinon.spy(getStyles, 'status'); + + shallow().dive(); + expect(spy).to.have.been.calledWith(props.status, props.statusStyle); + }); +}); From 4a2a7a4001f1cc49684849b7261a486ba3112e9d Mon Sep 17 00:00:00 2001 From: Ralphvandodewaard Date: Mon, 12 Jun 2017 14:57:46 +0200 Subject: [PATCH 2/3] Fixed tests --- test/avatar/index.test.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/test/avatar/index.test.js b/test/avatar/index.test.js index d46ddbf1..6012eb45 100644 --- a/test/avatar/index.test.js +++ b/test/avatar/index.test.js @@ -6,7 +6,7 @@ import { shallow } from 'enzyme'; import sinon from 'sinon'; import sinonChai from 'sinon-chai'; import Avatar from '../../src/avatar'; -import getStyles from '../../src/alert/get-styles'; +import getStyles from '../../src/avatar/get-styles'; chai.use(sinonChai); global.navigator = { userAgent: 'all' }; @@ -16,7 +16,7 @@ describe('Avatar.index', () => { style: {}, status: '', statusStyle: {}, - image: '' + image: 'imageurl' }; it('should always render a section element', () => { @@ -25,7 +25,13 @@ describe('Avatar.index', () => { expect(wrapper.find('section')).to.have.length(1); }); - it('should render a div element when the status prop is passed', () => { + it('should not render a div element if the status prop is not passed', () => { + const wrapper = shallow().dive(); + + expect(wrapper.find('div')).to.have.length(0); + }); + + it('should render a div element if the status prop is passed', () => { props.status = 'online'; const wrapper = shallow().dive(); @@ -34,7 +40,6 @@ describe('Avatar.index', () => { }); it('should get root styles', () => { - getStyles.root.restore(); const spy = sinon.spy(getStyles, 'root'); shallow().dive(); @@ -42,9 +47,11 @@ describe('Avatar.index', () => { }); it('should get status styles', () => { + props.status = 'online'; const spy = sinon.spy(getStyles, 'status'); shallow().dive(); expect(spy).to.have.been.calledWith(props.status, props.statusStyle); + props.status = ''; }); }); From 250735483c7bf7f2162025e7a43d010c241833f4 Mon Sep 17 00:00:00 2001 From: Ralphvandodewaard Date: Mon, 12 Jun 2017 15:00:50 +0200 Subject: [PATCH 3/3] Fixed userAgent --- test/avatar/index.test.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/avatar/index.test.js b/test/avatar/index.test.js index 6012eb45..cbf45d88 100644 --- a/test/avatar/index.test.js +++ b/test/avatar/index.test.js @@ -9,7 +9,6 @@ import Avatar from '../../src/avatar'; import getStyles from '../../src/avatar/get-styles'; chai.use(sinonChai); -global.navigator = { userAgent: 'all' }; describe('Avatar.index', () => { const props = { @@ -19,6 +18,14 @@ describe('Avatar.index', () => { image: 'imageurl' }; + beforeEach(() => { + global.navigator = { userAgent: 'all' }; + }); + + afterEach(() => { + global.navigator = undefined; + }); + it('should always render a section element', () => { const wrapper = shallow().dive();