forked from react-bootstrap/react-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgressBarSpec.js
215 lines (168 loc) · 6.98 KB
/
ProgressBarSpec.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import React from 'react';
import ReactTestUtils from 'react/lib/ReactTestUtils';
import ReactDOM from 'react-dom';
import ProgressBar from '../src/ProgressBar';
import {getOne, shouldWarn} from './helpers';
function getProgressBarNode(wrapper) {
return ReactTestUtils.findRenderedDOMComponentWithClass(wrapper, 'progress-bar');
}
describe('ProgressBar', () => {
it('Should output a progress bar with wrapper', () => {
let instance = ReactTestUtils.renderIntoDocument(
<ProgressBar min={0} max={10} now={0} />
);
assert.equal(ReactDOM.findDOMNode(instance).nodeName, 'DIV');
assert.ok(ReactDOM.findDOMNode(instance).className.match(/\bprogress\b/));
assert.ok(getProgressBarNode(instance).className.match(/\bprogress-bar\b/));
assert.equal(getProgressBarNode(instance).getAttribute('role'), 'progressbar');
});
it('Should have the default class', () => {
let instance = ReactTestUtils.renderIntoDocument(
<ProgressBar min={0} max={10} now={0} />
);
assert.ok(getProgressBarNode(instance).className.match(/\bprogress-bar\b/));
});
it('Should have the success class', () => {
let instance = ReactTestUtils.renderIntoDocument(
<ProgressBar min={0} max={10} now={0} bsStyle="success" />
);
assert.ok(getProgressBarNode(instance).className.match(/\bprogress-bar-success\b/));
});
it('Should have the warning class', () => {
let instance = ReactTestUtils.renderIntoDocument(
<ProgressBar min={0} max={10} now={0} bsStyle="warning" />
);
assert.ok(getProgressBarNode(instance).className.match(/\bprogress-bar-warning\b/));
});
it('Should default to min:0, max:100', () => {
let instance = ReactTestUtils.renderIntoDocument(
<ProgressBar now={5} />
);
let bar = getProgressBarNode(instance);
assert.equal(bar.getAttribute('aria-valuemin'), '0');
assert.equal(bar.getAttribute('aria-valuemax'), '100');
});
it('Should have 0% computed width', () => {
let instance = ReactTestUtils.renderIntoDocument(
<ProgressBar min={0} max={10} now={0} />
);
assert.equal(getProgressBarNode(instance).style.width, '0%');
});
it('Should have 10% computed width', () => {
let instance = ReactTestUtils.renderIntoDocument(
<ProgressBar min={0} max={10} now={1} />
);
assert.equal(getProgressBarNode(instance).style.width, '10%');
});
it('Should have 100% computed width', () => {
let instance = ReactTestUtils.renderIntoDocument(
<ProgressBar min={0} max={10} now={10} />
);
assert.equal(getProgressBarNode(instance).style.width, '100%');
});
it('Should have 50% computed width with non-zero min', () => {
let instance = ReactTestUtils.renderIntoDocument(
<ProgressBar min={1} max={11} now={6} />
);
assert.equal(getProgressBarNode(instance).style.width, '50%');
});
it('Should not have label', () => {
let instance = ReactTestUtils.renderIntoDocument(
<ProgressBar min={0} max={10} now={5} />
);
assert.equal(ReactDOM.findDOMNode(instance).innerText, '');
});
it('Should have label', () => {
let instance = ReactTestUtils.renderIntoDocument(
<ProgressBar min={0} max={10} now={5} bsStyle="success"
label="min:%(min)s, max:%(max)s, now:%(now)s, percent:%(percent)s, bsStyle:%(bsStyle)s" />
);
assert.equal(ReactDOM.findDOMNode(instance).innerText, 'min:0, max:10, now:5, percent:50, bsStyle:success');
});
it('Should have screen reader only label', () => {
let instance = ReactTestUtils.renderIntoDocument(
<ProgressBar min={0} max={10} now={5} srOnly bsStyle="success"
label="min:%(min)s, max:%(max)s, now:%(now)s, percent:%(percent)s, bsStyle:%(bsStyle)s" />
);
let srLabel = ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'sr-only');
assert.equal(srLabel.innerText, 'min:0, max:10, now:5, percent:50, bsStyle:success');
});
it('Should have a label that is a React component', () => {
let customLabel = (
<strong className="special-label">My label</strong>
);
let instance = ReactTestUtils.renderIntoDocument(
<ProgressBar min={0} max={10} now={5} label={customLabel} />
);
assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'special-label'));
});
it('Should have screen reader only label that wraps a React component', () => {
let customLabel = (
<strong className="special-label">My label</strong>
);
let instance = ReactTestUtils.renderIntoDocument(
<ProgressBar min={0} max={10} now={5} label={customLabel} srOnly />
);
let srLabel = ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'sr-only');
let component = getOne(srLabel.getElementsByClassName('special-label'));
assert.ok(component);
});
it('Should show striped bar', () => {
let instance = ReactTestUtils.renderIntoDocument(
<ProgressBar min={1} max={11} now={6} striped />
);
assert.ok(ReactDOM.findDOMNode(instance).firstChild.className.match(/\bprogress-bar-striped\b/));
});
it('Should show animated striped bar', () => {
let instance = ReactTestUtils.renderIntoDocument(
<ProgressBar min={1} max={11} now={6} active />
);
const barClassName = ReactDOM.findDOMNode(instance).firstChild.className;
assert.ok(barClassName.match(/\bprogress-bar-striped\b/));
assert.ok(barClassName.match(/\bactive\b/));
});
it('Should show stacked bars', () => {
let instance = ReactTestUtils.renderIntoDocument(
<ProgressBar>
<ProgressBar key={1} now={50} />
<ProgressBar key={2} now={30} />
</ProgressBar>
);
let wrapper = ReactDOM.findDOMNode(instance);
let bar1 = wrapper.firstChild;
let bar2 = wrapper.lastChild;
assert.ok(wrapper.className.match(/\bprogress\b/));
assert.ok(bar1.className.match(/\bprogress-bar\b/));
assert.equal(bar1.style.width, '50%');
assert.ok(bar2.className.match(/\bprogress-bar\b/));
assert.equal(bar2.style.width, '30%');
});
it('Should render active and striped children in stacked bar too', () => {
let instance = ReactTestUtils.renderIntoDocument(
<ProgressBar>
<ProgressBar active key={1} now={50} />
<ProgressBar striped key={2} now={30} />
</ProgressBar>
);
let wrapper = ReactDOM.findDOMNode(instance);
let bar1 = wrapper.firstChild;
let bar2 = wrapper.lastChild;
assert.ok(wrapper.className.match(/\bprogress\b/));
assert.ok(bar1.className.match(/\bprogress-bar\b/));
assert.ok(bar1.className.match(/\bactive\b/));
assert.ok(bar1.className.match(/\bprogress-bar-striped\b/));
assert.ok(bar2.className.match(/\bprogress-bar\b/));
assert.ok(bar2.className.match(/\bprogress-bar-striped\b/));
assert.notOk(bar2.className.match(/\bactive\b/));
});
it('allows only ProgressBar in children', () => {
ReactTestUtils.renderIntoDocument(
<ProgressBar>
<ProgressBar key={1} />
<div />
<ProgressBar key={2} />
</ProgressBar>
);
shouldWarn('Failed propType');
});
});