From f26d8a2922cad94bf33737574d8b23bceff561b1 Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Mon, 30 Oct 2017 13:16:45 +0100 Subject: [PATCH] [test] Increase test coverage (#8908) --- src/Checkbox/Checkbox.spec.js | 16 +++++++++++++++- src/Chip/Chip.spec.js | 31 ++++++++++++++----------------- src/Radio/Radio.spec.js | 16 +++++++++++++++- src/Table/TableSortLabel.spec.js | 14 +++++++++++++- 4 files changed, 57 insertions(+), 20 deletions(-) diff --git a/src/Checkbox/Checkbox.spec.js b/src/Checkbox/Checkbox.spec.js index 710b4238124c87..60a2bc2bc47df8 100644 --- a/src/Checkbox/Checkbox.spec.js +++ b/src/Checkbox/Checkbox.spec.js @@ -2,16 +2,23 @@ import React from 'react'; import { assert } from 'chai'; -import { createShallow, getClasses } from '../test-utils'; +import { createShallow, getClasses, createMount } from '../test-utils'; import Checkbox from './Checkbox'; +import IndeterminateCheckBoxIcon from '../svg-icons/IndeterminateCheckBox'; describe('', () => { let shallow; let classes; + let mount; before(() => { shallow = createShallow({ dive: true }); classes = getClasses(); + mount = createMount(); + }); + + after(() => { + mount.cleanUp(); }); describe('styleSheet', () => { @@ -26,4 +33,11 @@ describe('', () => { const wrapper = shallow(); assert.strictEqual(wrapper.name(), 'withStyles(SwitchBase)'); }); + + describe('prop: indeterminate', () => { + it('should render an indeterminate icon', () => { + const wrapper = mount(); + assert.strictEqual(wrapper.find(IndeterminateCheckBoxIcon).length, 1); + }); + }); }); diff --git a/src/Chip/Chip.spec.js b/src/Chip/Chip.spec.js index 8c2778b185ceba..393c3387d3c177 100644 --- a/src/Chip/Chip.spec.js +++ b/src/Chip/Chip.spec.js @@ -8,14 +8,21 @@ import CheckBox from '../svg-icons/CheckBox'; import { createShallow, createMount, getClasses, unwrap } from '../test-utils'; import Avatar from '../Avatar'; import Chip from './Chip'; +import CancelIcon from '../svg-icons/Cancel'; describe('', () => { let shallow; let classes; + let mount; before(() => { shallow = createShallow({ dive: true }); classes = getClasses(); + mount = createMount(); + }); + + after(() => { + mount.cleanUp(); }); describe('text only', () => { @@ -154,19 +161,14 @@ describe('', () => { }); describe('prop: deleteIcon', () => { - let wrapper; - - before(() => { - wrapper = shallow( + it('should fire the function given in onDeleteRequest', () => { + const wrapper = shallow( {}} deleteIcon={} />, ); - }); - - it('should fire the function given in onDeleteRequest', () => { const onRequestDeleteSpy = spy(); wrapper.setProps({ onRequestDelete: onRequestDeleteSpy }); @@ -177,6 +179,11 @@ describe('', () => { 'should have called the onRequestDelete handler', ); }); + + it('should render a default icon', () => { + const wrapper = mount( {}} />); + assert.strictEqual(wrapper.find(CancelIcon).length, 1); + }); }); describe('reacts to keyboard chip', () => { @@ -202,16 +209,6 @@ describe('', () => { }); describe('escape', () => { - let mount; - - before(() => { - mount = createMount(); - }); - - after(() => { - mount.cleanUp(); - }); - it('should unfocus when a esc key is pressed', () => { const ChipNaked = unwrap(Chip); const wrapper2 = mount(Text Chip); diff --git a/src/Radio/Radio.spec.js b/src/Radio/Radio.spec.js index 0b8657680e3f20..576c0b04cb94da 100644 --- a/src/Radio/Radio.spec.js +++ b/src/Radio/Radio.spec.js @@ -2,14 +2,21 @@ import React from 'react'; import { assert } from 'chai'; -import { getClasses } from '../test-utils'; +import { getClasses, createMount } from '../test-utils'; import Radio from './Radio'; +import RadioButtonCheckedIcon from '../svg-icons/RadioButtonChecked'; describe('', () => { let classes; + let mount; before(() => { classes = getClasses(); + mount = createMount(); + }); + + after(() => { + mount.cleanUp(); }); describe('styleSheet', () => { @@ -25,4 +32,11 @@ describe('', () => { assert.strictEqual(Radio.displayName, 'Radio'); }); }); + + describe('prop: checked', () => { + it('should render a checked icon', () => { + const wrapper = mount(); + assert.strictEqual(wrapper.find(RadioButtonCheckedIcon).length, 1); + }); + }); }); diff --git a/src/Table/TableSortLabel.spec.js b/src/Table/TableSortLabel.spec.js index 88c8b207e57ecd..ad84aa8a5c5de7 100644 --- a/src/Table/TableSortLabel.spec.js +++ b/src/Table/TableSortLabel.spec.js @@ -2,18 +2,24 @@ import React from 'react'; import { assert } from 'chai'; -import { createShallow, getClasses } from '../test-utils'; +import { createShallow, createMount, getClasses } from '../test-utils'; import TableSortLabel from './TableSortLabel'; describe('', () => { let shallow; + let mount; let classes; before(() => { shallow = createShallow({ dive: true }); + mount = createMount(); classes = getClasses(); }); + after(() => { + mount.cleanUp(); + }); + it('should render TableSortLabel', () => { const wrapper = shallow(); assert.strictEqual(wrapper.hasClass(classes.root), true, 'should have root class'); @@ -59,4 +65,10 @@ describe('', () => { assert.strictEqual(icon.hasClass(classes.desc), false); }); }); + + describe('mount', () => { + it('should mount without error', () => { + mount(); + }); + }); });