blob: 39e33f71ba4f9bfb052bbdc7f0b4c8539307a270 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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');
});
});
|