Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test] Increase test coverage #8908

Merged
merged 1 commit into from Oct 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/Checkbox/Checkbox.spec.js
Expand Up @@ -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('<Checkbox />', () => {
let shallow;
let classes;
let mount;

before(() => {
shallow = createShallow({ dive: true });
classes = getClasses(<Checkbox />);
mount = createMount();
});

after(() => {
mount.cleanUp();
});

describe('styleSheet', () => {
Expand All @@ -26,4 +33,11 @@ describe('<Checkbox />', () => {
const wrapper = shallow(<Checkbox />);
assert.strictEqual(wrapper.name(), 'withStyles(SwitchBase)');
});

describe('prop: indeterminate', () => {
it('should render an indeterminate icon', () => {
const wrapper = mount(<Checkbox indeterminate />);
assert.strictEqual(wrapper.find(IndeterminateCheckBoxIcon).length, 1);
});
});
});
31 changes: 14 additions & 17 deletions src/Chip/Chip.spec.js
Expand Up @@ -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('<Chip />', () => {
let shallow;
let classes;
let mount;

before(() => {
shallow = createShallow({ dive: true });
classes = getClasses(<Chip />);
mount = createMount();
});

after(() => {
mount.cleanUp();
});

describe('text only', () => {
Expand Down Expand Up @@ -154,19 +161,14 @@ describe('<Chip />', () => {
});

describe('prop: deleteIcon', () => {
let wrapper;

before(() => {
wrapper = shallow(
it('should fire the function given in onDeleteRequest', () => {
const wrapper = shallow(
<Chip
label="Custom delete icon Chip"
onRequestDelete={() => {}}
deleteIcon={<CheckBox />}
/>,
);
});

it('should fire the function given in onDeleteRequest', () => {
const onRequestDeleteSpy = spy();
wrapper.setProps({ onRequestDelete: onRequestDeleteSpy });

Expand All @@ -177,6 +179,11 @@ describe('<Chip />', () => {
'should have called the onRequestDelete handler',
);
});

it('should render a default icon', () => {
const wrapper = mount(<Chip label="Custom delete icon Chip" onRequestDelete={() => {}} />);
assert.strictEqual(wrapper.find(CancelIcon).length, 1);
});
});

describe('reacts to keyboard chip', () => {
Expand All @@ -202,16 +209,6 @@ describe('<Chip />', () => {
});

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(<ChipNaked classes={{}}>Text Chip</ChipNaked>);
Expand Down
16 changes: 15 additions & 1 deletion src/Radio/Radio.spec.js
Expand Up @@ -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('<Radio />', () => {
let classes;
let mount;

before(() => {
classes = getClasses(<Radio />);
mount = createMount();
});

after(() => {
mount.cleanUp();
});

describe('styleSheet', () => {
Expand All @@ -25,4 +32,11 @@ describe('<Radio />', () => {
assert.strictEqual(Radio.displayName, 'Radio');
});
});

describe('prop: checked', () => {
it('should render a checked icon', () => {
const wrapper = mount(<Radio checked />);
assert.strictEqual(wrapper.find(RadioButtonCheckedIcon).length, 1);
});
});
});
14 changes: 13 additions & 1 deletion src/Table/TableSortLabel.spec.js
Expand Up @@ -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('<TableSortLabel />', () => {
let shallow;
let mount;
let classes;

before(() => {
shallow = createShallow({ dive: true });
mount = createMount();
classes = getClasses(<TableSortLabel />);
});

after(() => {
mount.cleanUp();
});

it('should render TableSortLabel', () => {
const wrapper = shallow(<TableSortLabel />);
assert.strictEqual(wrapper.hasClass(classes.root), true, 'should have root class');
Expand Down Expand Up @@ -59,4 +65,10 @@ describe('<TableSortLabel />', () => {
assert.strictEqual(icon.hasClass(classes.desc), false);
});
});

describe('mount', () => {
it('should mount without error', () => {
mount(<TableSortLabel />);
});
});
});