Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joshwooding committed Mar 10, 2019
1 parent 8c82693 commit 6166150
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 52 deletions.
46 changes: 0 additions & 46 deletions packages/material-ui/src/Radio/Radio.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import RadioButtonUncheckedIcon from '../internal/svg-icons/RadioButtonUnchecked
import { getClasses, createMount } from '@material-ui/core/test-utils';
import SwitchBase from '../internal/SwitchBase';
import Radio from './Radio';
import RadioGroup from '../RadioGroup';

describe('<Radio />', () => {
let classes;
Expand All @@ -20,10 +19,6 @@ describe('<Radio />', () => {
mount.cleanUp();
});

function findRadio(wrapper, value) {
return wrapper.find(`SwitchBase[value="${value}"]`).first();
}

describe('styleSheet', () => {
it('should have the classes required for SwitchBase', () => {
assert.strictEqual(typeof classes.root, 'string');
Expand All @@ -50,45 +45,4 @@ describe('<Radio />', () => {
assert.strictEqual(wrapper.find(RadioButtonCheckedIcon).length, 1);
});
});

describe('RadioButtonGroup', () => {
it('should support uncontrolled mode', () => {
const wrapper = mount(
<RadioGroup name="group">
<Radio value="one" />
</RadioGroup>,
);

findRadio(wrapper, 'one').simulate('change');
assert.strictEqual(
findRadio(wrapper, 'one')
.childAt(0)
.hasClass(classes.checked),
true,
);
});

it('should support default value in uncontrolled mode', () => {
const wrapper = mount(
<RadioGroup name="group" defaultValue="zero">
<Radio value="zero" />
<Radio value="one" />
</RadioGroup>,
);

assert.strictEqual(
findRadio(wrapper, 'zero')
.childAt(0)
.hasClass(classes.checked),
true,
);
findRadio(wrapper, 'one').simulate('change');
assert.strictEqual(
findRadio(wrapper, 'one')
.childAt(0)
.hasClass(classes.checked),
true,
);
});
});
});
46 changes: 40 additions & 6 deletions packages/material-ui/src/RadioGroup/RadioGroup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ describe('<RadioGroup />', () => {
mount.cleanUp();
});

function findRadio(wrapper, value) {
return wrapper.find(`SwitchBase[value="${value}"]`).first();
}

it('should render a FormGroup with the radiogroup role', () => {
const wrapper = mount(<RadioGroup value="" />);
const formGroupWrapper = wrapper.find(FormGroup);
Expand Down Expand Up @@ -51,6 +55,37 @@ describe('<RadioGroup />', () => {
);
});

it('should support uncontrolled mode', () => {
const wrapper = mount(
<RadioGroup name="group">
<Radio value="one" />
</RadioGroup>,
);

findRadio(wrapper, 'one')
.find('input')
.simulate('change', { target: { checked: true } });

assert.strictEqual(findRadio(wrapper, 'one').props().checked, true);
});

it('should support default value in uncontrolled mode', () => {
const wrapper = mount(
<RadioGroup name="group" defaultValue="zero">
<Radio value="zero" />
<Radio value="one" />
</RadioGroup>,
);

assert.strictEqual(findRadio(wrapper, 'zero').props().checked, true);

findRadio(wrapper, 'one')
.find('input')
.simulate('change');

assert.strictEqual(findRadio(wrapper, 'one').props().checked, true);
});

describe('prop: onChange', () => {
it('should fire onChange', () => {
const handleChange = spy();
Expand All @@ -61,11 +96,11 @@ describe('<RadioGroup />', () => {
</RadioGroup>,
);

const firstRadio = findOutermostIntrinsic(wrapper.find(Radio).at(0));
const event = { test: true };
firstRadio.simulate('change', event);
findRadio(wrapper, 'woofRadioGroup')
.find('input')
.simulate('change');

assert.strictEqual(handleChange.callCount, 1);
assert.strictEqual(handleChange.args[0][0].test, true);
});

it('should chain the onChange property', () => {
Expand All @@ -79,8 +114,7 @@ describe('<RadioGroup />', () => {
);

const firstRadio = findOutermostIntrinsic(wrapper.find(Radio).at(0));
const event = { test: true };
firstRadio.simulate('change', event);
firstRadio.find('input').simulate('change');
assert.strictEqual(handleChange1.callCount, 1);
assert.strictEqual(handleChange2.callCount, 1);
});
Expand Down

0 comments on commit 6166150

Please sign in to comment.