import React from 'react';
import Radio from '../../src/react/Radio.js';
import renderer from 'react-test-renderer';
import {mount} from 'enzyme';
class RadioForm extends React.Component {
constructor(props) {
super(props);
this.state = {checked: false};
this.handleChange = this.handleChange.bind(this);
}
handleChange(val) {
this.setState({checked: val});
}
getChecked() {
return this.radio.getChecked();
}
render() {
return (
);
}
}
describe('Radio', () => {
test('Radio - unchecked', () => {
const radio = renderer.create().toJSON();
expect(radio).toMatchSnapshot();
});
test('Radio - disabled', () => {
const radio = renderer.create().toJSON();
expect(radio).toMatchSnapshot();
});
test('Radio - checked state changes', () => {
const radio = mount();
expect(radio.instance().getChecked()).toEqual(false);
expect(radio.instance().getChecked()).toEqual(radio.find('input').props().checked);
radio.find('input').simulate('change', { target : { checked: true }});
expect(radio.instance().getChecked()).toEqual(true);
expect(radio.instance().getChecked()).toEqual(radio.find('input').props().checked);
radio.find('input').simulate('change', { target : { checked: false }});
expect(radio.instance().getChecked()).toEqual(false);
expect(radio.instance().getChecked()).toEqual(radio.find('input').props().checked);
});
test('Radio - returns its value', () => {
const radio = mount();
expect(radio.instance().getValue()).toEqual('myVal');
});
});