diff options
Diffstat (limited to 'test/react/Radio.spec.js')
-rw-r--r-- | test/react/Radio.spec.js | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/test/react/Radio.spec.js b/test/react/Radio.spec.js new file mode 100644 index 0000000..39e33f7 --- /dev/null +++ b/test/react/Radio.spec.js @@ -0,0 +1,60 @@ +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 ( + <form > + <Radio ref={(radio)=>{this.radio = radio;}} name='grp1' checked={this.state.checked} label='This is the radio label' value='1' onChange={this.handleChange} /> + </form> + ); + } +} + +describe('Radio', () => { + test('Radio - unchecked', () => { + const radio = renderer.create(<Radio name='grp4' label='This is the radio label' value='1' />).toJSON(); + expect(radio).toMatchSnapshot(); + }); + + test('Radio - disabled', () => { + const radio = renderer.create(<Radio name='grp2' disabled={true} label='This is the radio label' value='1' />).toJSON(); + expect(radio).toMatchSnapshot(); + }); + + test('Radio - checked state changes', () => { + const radio = mount(<RadioForm />); + 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(<Radio label='This is the radio label' value='myVal' />); + expect(radio.instance().getValue()).toEqual('myVal'); + }); + +}); |