forked from muicss/mui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-radio.js
More file actions
130 lines (96 loc) · 3.05 KB
/
test-radio.js
File metadata and controls
130 lines (96 loc) · 3.05 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/**
* MUI test react radio library
* @module test/react-tests/test-radio
*/
import assert from 'assert';
import createClass from 'create-react-class';
import React from 'react';
import ReactDOM from 'react-dom';
import ReactUtils from 'react-dom/test-utils';
import Radio from '../../src/react/radio';
import { getShallowRendererOutput } from '../lib/react-helpers';
describe('react/radio', function() {
let elem;
beforeEach(function() {
elem = <Radio>My Label</Radio>;
});
it('renders wrapper properly', function() {
let result = getShallowRendererOutput(elem);
assert.equal(result.type, 'div');
assert.equal(result.props.className, 'mui-radio ');
});
it('renders content properly', function() {
let node = ReactUtils.renderIntoDocument(elem);
let wrapperEl = ReactDOM.findDOMNode(node);
assert.equal(wrapperEl.children.length, 1);
let labelEl = wrapperEl.children[0];
assert.equal(labelEl.tagName, 'LABEL');
let inputEl = labelEl.children[0];
assert.equal(inputEl.tagName, 'INPUT');
});
it('renders properly with additional classNames', function() {
let result = getShallowRendererOutput(
<Radio className="additional">
test
</Radio>
);
assert.equal(result.props.className, 'mui-radio additional');
});
it('renders properly with additional styles', function() {
let result = getShallowRendererOutput(
<Radio style={{additonal: 'style'}}>
test
</Radio>
);
assert.equal(result.props.style.additonal, 'style');
});
it('can be used as a controlled component', function() {
var TestApp = createClass({
getInitialState: function() {
return {checked: this.props.checked};
},
onChange: function(ev) {
this.setState({checked: ev.target.checked});
},
render: function() {
return (
<Radio
ref="refEl"
checked={this.state.checked}
onChange={this.onChange}
/>
);
}
});
let elem = <TestApp checked={false} />;
let instance = ReactUtils.renderIntoDocument(elem);
let inputEl = instance.refs.refEl.refs.inputEl
// check default value
assert.equal(inputEl.checked, false);
// update TestApp and check inputEl value
instance.setState({checked: true});
assert.equal(inputEl.checked, true);
// update inputEl and check state
inputEl.checked = false;
ReactUtils.Simulate.change(inputEl);
assert.equal(instance.state.checked, false);
});
it('supports onChange method', function(done) {
let counter = 0;
let onChangeFn = function() {
counter += 1;
};
let node = ReactUtils.renderIntoDocument(
<Radio onChange={onChangeFn} />
);
// change checkbox
let inputEl = ReactUtils.findRenderedDOMComponentWithTag(node, 'input');
ReactUtils.Simulate.change(inputEl);
// test conditions
setTimeout(function() {
// one onChange event (https://github.com/muicss/mui/issues/94)
assert.equal(counter, 1);
done();
}, 50);
});
});