forked from react-bootstrap/react-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormGroupSpec.js
121 lines (101 loc) · 3.65 KB
/
FormGroupSpec.js
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
import React from 'react';
import ReactTestUtils from 'react/lib/ReactTestUtils';
import FormGroup from '../src/FormGroup';
import {shouldWarn} from './helpers';
describe('FormGroup', () => {
it('renders children', () => {
let instance = ReactTestUtils.renderIntoDocument(
<FormGroup>
<span className='child1' />
<span className='child2' />
</FormGroup>
);
assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'child1'));
assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'child2'));
});
it('renders with form-group class', () => {
let instance = ReactTestUtils.renderIntoDocument(
<FormGroup>
<span />
</FormGroup>
);
assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'form-group'));
});
it('renders form-group with sm or lg class when bsSize is small or large', () => {
let instance = ReactTestUtils.renderIntoDocument(
<FormGroup bsSize="small">
<span />
</FormGroup>
);
assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'form-group'));
assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'form-group-sm'));
instance = ReactTestUtils.renderIntoDocument(
<FormGroup bsSize="large">
<span />
</FormGroup>
);
assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'form-group'));
assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'form-group-lg'));
});
// This test case must come first, since the error only gets logged once.
it('throws no warning without bsSize when standalone', () => {
ReactTestUtils.renderIntoDocument(
<FormGroup standalone />
);
// Warning thrown above would lead to failure from index.
});
it('throws warning about bsSize when standalone', () => {
ReactTestUtils.renderIntoDocument(
<FormGroup standalone bsSize="large" />
);
shouldWarn('Failed propType: bsSize');
});
it('renders no form-group class when standalone', () => {
let instance = ReactTestUtils.renderIntoDocument(
<FormGroup standalone>
<span />
</FormGroup>
);
assert.equal(ReactTestUtils.scryRenderedDOMComponentsWithClass(instance, 'form-group').length, 0);
});
it('renders no form-group-* class when standalone', () => {
let instance = ReactTestUtils.renderIntoDocument(
<FormGroup standalone bsSize="large" />
);
assert.equal(ReactTestUtils.scryRenderedDOMComponentsWithClass(instance, 'form-group').length, 0);
assert.equal(ReactTestUtils.scryRenderedDOMComponentsWithClass(instance, 'form-group-lg').length, 0);
});
[{
className: 'has-feedback',
props: { hasFeedback: true }
}, {
className: 'has-success',
props: { bsStyle: 'success' }
}, {
className: 'has-warning',
props: { bsStyle: 'warning' }
}, {
className: 'has-error',
props: { bsStyle: 'error' }
}, {
className: 'custom-group',
props: { groupClassName: 'custom-group' }
}].forEach( testCase => {
it(`does not render ${testCase.className} class`, () => {
let instance = ReactTestUtils.renderIntoDocument(
<FormGroup>
<span />
</FormGroup>
);
assert.equal(ReactTestUtils.scryRenderedDOMComponentsWithClass(instance, testCase.className).length, 0);
});
it(`renders with ${testCase.className} class`, () => {
let instance = ReactTestUtils.renderIntoDocument(
<FormGroup {...testCase.props}>
<span />
</FormGroup>
);
assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, testCase.className));
});
});
});