forked from muicss/mui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-textarea.js
More file actions
103 lines (77 loc) · 2.55 KB
/
test-textarea.js
File metadata and controls
103 lines (77 loc) · 2.55 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
/**
* MUI test react textinput library
* @module test/react-tests/test-textinput
*/
import assert from 'assert';
import React from 'react';
import ReactDOM from 'react-dom';
import ReactUtils from 'react-addons-test-utils';
import Textarea from '../../src/react/textarea';
import { getShallowRendererOutput } from '../lib/react-helpers';
describe('react/textarea', function() {
// capture console error messages
let errFn, elem;
before(function() {
errFn = console.error;
console.error = function(msg) {throw Error(msg);};
});
after(function() {
console.error = errFn;
});
beforeEach(function() {
elem = <Textarea defaultValue="my input"></Textarea>;
});
it('renders wrapper properly', function() {
let instance = ReactUtils.renderIntoDocument(elem);
let wrapperEl = ReactDOM.findDOMNode(instance);
assert.equal(wrapperEl.tagName, 'DIV');
assert.equal(wrapperEl.className.trim(), 'mui-textfield');
});
it('renders native textarea element', function() {
let instance = ReactUtils.renderIntoDocument(elem);
let fn = ReactUtils.findRenderedDOMComponentWithTag;
let textareaEl = fn(instance, 'textarea');
assert.equal(textareaEl.textContent, 'my input');
});
it('does controlled component validation', function() {
// raises error when `value` defined and `onChange missing
assert.throws(
function() {
let elem = <Textarea value="my value"></Textarea>;
let instance = ReactUtils.renderIntoDocument(elem);
},
/MUI Warning/
);
});
it('can be used as controlled component', function() {
var TestApp = React.createClass({
getInitialState: function() {
return {value: this.props.value};
},
onChange: function(ev) {
this.setState({value: ev.target.value});
},
render: function() {
return (
<Textarea
value={this.state.value}
onChange={this.onChange}
/>
);
}
});
let elem = <TestApp value="test" />;
let instance = ReactUtils.renderIntoDocument(elem);
let findComponent = ReactUtils.findRenderedDOMComponentWithTag;
let inputEl = findComponent(instance, 'textarea');
// check default value
assert.equal(inputEl.value, 'test');
// update TestApp and check inputEl value
instance.setState({value: 'test2'});
assert.equal(inputEl.value, 'test2');
// update inputEl and check state
inputEl.value = 'test3';
ReactUtils.Simulate.change(inputEl);
assert.equal(instance.state.value, 'test3');
});
});