From b3071f8dddfa24532e252ba5ffe36c714b2dcec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pradel=20Le=CC=81o?= Date: Mon, 22 Feb 2016 13:19:12 +0100 Subject: [PATCH 1/2] Add badge unit tests --- test/unit/Badge.spec.js | 82 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 test/unit/Badge.spec.js diff --git a/test/unit/Badge.spec.js b/test/unit/Badge.spec.js new file mode 100644 index 00000000000000..545e7ded07d192 --- /dev/null +++ b/test/unit/Badge.spec.js @@ -0,0 +1,82 @@ +import React from 'react'; +import {shallow} from 'enzyme'; +import {assert} from 'chai'; +import getMuiTheme from 'src/styles/getMuiTheme'; +import Badge from 'src/badge'; + +describe('', () => { + + const badgeTheme = getMuiTheme().badge; + const testChildren =
Hello World
; + + it('renders children and badgeContent', () => { + const wrapper = shallow( + {testChildren} + ); + + assert.ok(wrapper.contains(testChildren), 'should contain the children'); + assert.ok(wrapper.find('span').length, 'should contain the badgeContent'); + }); + + it('renders children and overwrite badge styles', () => { + const badgeStyle = { + backgroundColor: 'red' + }; + const wrapper = shallow( + {testChildren} + ); + + assert.ok(wrapper.contains(testChildren), 'should contain the children'); + assert.equal(wrapper.find('span').node.props.style.backgroundColor, badgeStyle.backgroundColor, 'should overwrite badge backgroundColor'); + }); + + it('renders children by default', () => { + const wrapper = shallow( + {testChildren} + ); + + assert.ok(wrapper.contains(testChildren), 'should contain the children'); + }); + + it('renders children and className', () => { + const wrapper = shallow( + {testChildren} + ); + + assert.ok(wrapper.contains(testChildren), 'should contain the children'); + assert.ok(wrapper.is('.testClassName'), 'should contain the className'); + }); + + it('renders children and have primary styles', () => { + const wrapper = shallow( + {testChildren} + ); + + assert.ok(wrapper.contains(testChildren), 'should contain the children'); + assert.equal(wrapper.find('span').node.props.style.backgroundColor, badgeTheme.primaryColor, 'should have primary badge backgroundColor'); + assert.equal(wrapper.find('span').node.props.style.color, badgeTheme.primaryTextColor, 'should have primary badge text color'); + }); + + it('renders children and have secondary styles', () => { + const wrapper = shallow( + {testChildren} + ); + + assert.ok(wrapper.contains(testChildren), 'should contain the children'); + assert.equal(wrapper.find('span').node.props.style.backgroundColor, badgeTheme.secondaryColor, 'should have secondary badge backgroundColor'); + assert.equal(wrapper.find('span').node.props.style.color, badgeTheme.secondaryTextColor, 'should have secondary badge text color'); + }); + + it('renders children and overwrite root styles', () => { + const style = { + backgroundColor: 'red' + }; + const wrapper = shallow( + {testChildren} + ); + + assert.ok(wrapper.contains(testChildren), 'should contain the children'); + assert.equal(wrapper.node.props.style.backgroundColor, style.backgroundColor, 'should overwrite badge backgroundColor'); + }); + +}); From 4edec72aa1f51208b1c1bb242839cedd2ae2687b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pradel=20Le=CC=81o?= Date: Mon, 22 Feb 2016 20:50:47 +0100 Subject: [PATCH 2/2] fix eslint --- test/unit/Badge.spec.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/test/unit/Badge.spec.js b/test/unit/Badge.spec.js index 545e7ded07d192..9973f699c75df4 100644 --- a/test/unit/Badge.spec.js +++ b/test/unit/Badge.spec.js @@ -20,14 +20,15 @@ describe('', () => { it('renders children and overwrite badge styles', () => { const badgeStyle = { - backgroundColor: 'red' + backgroundColor: 'red', }; const wrapper = shallow( {testChildren} ); assert.ok(wrapper.contains(testChildren), 'should contain the children'); - assert.equal(wrapper.find('span').node.props.style.backgroundColor, badgeStyle.backgroundColor, 'should overwrite badge backgroundColor'); + assert.equal(wrapper.find('span').node.props.style.backgroundColor, + badgeStyle.backgroundColor, 'should overwrite badge backgroundColor'); }); it('renders children by default', () => { @@ -53,8 +54,10 @@ describe('', () => { ); assert.ok(wrapper.contains(testChildren), 'should contain the children'); - assert.equal(wrapper.find('span').node.props.style.backgroundColor, badgeTheme.primaryColor, 'should have primary badge backgroundColor'); - assert.equal(wrapper.find('span').node.props.style.color, badgeTheme.primaryTextColor, 'should have primary badge text color'); + assert.equal(wrapper.find('span').node.props.style.backgroundColor, + badgeTheme.primaryColor, 'should have primary badge backgroundColor'); + assert.equal(wrapper.find('span').node.props.style.color, + badgeTheme.primaryTextColor, 'should have primary badge text color'); }); it('renders children and have secondary styles', () => { @@ -63,20 +66,23 @@ describe('', () => { ); assert.ok(wrapper.contains(testChildren), 'should contain the children'); - assert.equal(wrapper.find('span').node.props.style.backgroundColor, badgeTheme.secondaryColor, 'should have secondary badge backgroundColor'); - assert.equal(wrapper.find('span').node.props.style.color, badgeTheme.secondaryTextColor, 'should have secondary badge text color'); + assert.equal(wrapper.find('span').node.props.style.backgroundColor, + badgeTheme.secondaryColor, 'should have secondary badge backgroundColor'); + assert.equal(wrapper.find('span').node.props.style.color, + badgeTheme.secondaryTextColor, 'should have secondary badge text color'); }); it('renders children and overwrite root styles', () => { const style = { - backgroundColor: 'red' + backgroundColor: 'red', }; const wrapper = shallow( {testChildren} ); assert.ok(wrapper.contains(testChildren), 'should contain the children'); - assert.equal(wrapper.node.props.style.backgroundColor, style.backgroundColor, 'should overwrite badge backgroundColor'); + assert.equal(wrapper.node.props.style.backgroundColor, style.backgroundColor, + 'should overwrite badge backgroundColor'); }); });