aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Select.spec.jsx
diff options
context:
space:
mode:
authorMG12 <wuzhao.mail@gmail.com>2015-12-16 12:19:56 +0800
committerMG12 <wuzhao.mail@gmail.com>2015-12-16 12:19:56 +0800
commit700c77e4f32e2ec18f3c63b176bf83bac24cdb74 (patch)
treedd7b0d090e946586dbc3bb5268a0a5b5619f81e4 /tests/Select.spec.jsx
parent182e9fccc90ae709322b7cc314c8775a9d8d46b8 (diff)
parentbec70d57f3ef17ed1ef29c660936be235804061e (diff)
downloadtime-picker-700c77e4f32e2ec18f3c63b176bf83bac24cdb74.tar.gz
time-picker-700c77e4f32e2ec18f3c63b176bf83bac24cdb74.tar.zst
time-picker-700c77e4f32e2ec18f3c63b176bf83bac24cdb74.zip
Merge pull request #10 from react-component/1.0.0-alpha7
1.0.0 alpha7
Diffstat (limited to 'tests/Select.spec.jsx')
-rw-r--r--tests/Select.spec.jsx153
1 files changed, 136 insertions, 17 deletions
diff --git a/tests/Select.spec.jsx b/tests/Select.spec.jsx
index 7e53c31..f7717c7 100644
--- a/tests/Select.spec.jsx
+++ b/tests/Select.spec.jsx
@@ -29,7 +29,7 @@ describe('Select', () => {
29 formatter={formatter} 29 formatter={formatter}
30 locale={TimePickerLocale} 30 locale={TimePickerLocale}
31 showSecond={showSecond} 31 showSecond={showSecond}
32 defaultValue={formatTime('01:02:03', formatter)} 32 defaultValue={formatTime('01:02:04', formatter)}
33 {...props} 33 {...props}
34 />, container); 34 />, container);
35 } 35 }
@@ -89,19 +89,19 @@ describe('Select', () => {
89 }, (next) => { 89 }, (next) => {
90 expect(picker.state.open).to.be(true); 90 expect(picker.state.open).to.be(true);
91 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; 91 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0];
92 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[0];
93 const option = selector.getElementsByTagName('li')[19];
94 expect(header).to.be.ok(); 92 expect(header).to.be.ok();
95 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); 93 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04');
96 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); 94 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04');
97 95
96 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[0];
97 const option = selector.getElementsByTagName('li')[19];
98 Simulate.click(option); 98 Simulate.click(option);
99 setTimeout(next, 100); 99 setTimeout(next, 100);
100 }, (next) => { 100 }, (next) => {
101 expect(change).to.be.ok(); 101 expect(change).to.be.ok();
102 expect(change.getHourOfDay()).to.be(19); 102 expect(change.getHourOfDay()).to.be(19);
103 expect(ReactDOM.findDOMNode(header).value).to.be('19:02:03'); 103 expect(ReactDOM.findDOMNode(header).value).to.be('19:02:04');
104 expect(ReactDOM.findDOMNode(input).value).to.be('19:02:03'); 104 expect(ReactDOM.findDOMNode(input).value).to.be('19:02:04');
105 expect(picker.state.open).to.be.ok(); 105 expect(picker.state.open).to.be.ok();
106 106
107 next(); 107 next();
@@ -128,19 +128,19 @@ describe('Select', () => {
128 }, (next) => { 128 }, (next) => {
129 expect(picker.state.open).to.be(true); 129 expect(picker.state.open).to.be(true);
130 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; 130 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0];
131 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[1];
132 const option = selector.getElementsByTagName('li')[19];
133 expect(header).to.be.ok(); 131 expect(header).to.be.ok();
134 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); 132 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04');
135 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); 133 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04');
136 134
135 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[1];
136 const option = selector.getElementsByTagName('li')[19];
137 Simulate.click(option); 137 Simulate.click(option);
138 setTimeout(next, 100); 138 setTimeout(next, 100);
139 }, (next) => { 139 }, (next) => {
140 expect(change).to.be.ok(); 140 expect(change).to.be.ok();
141 expect(change.getMinutes()).to.be(19); 141 expect(change.getMinutes()).to.be(19);
142 expect(ReactDOM.findDOMNode(header).value).to.be('01:19:03'); 142 expect(ReactDOM.findDOMNode(header).value).to.be('01:19:04');
143 expect(ReactDOM.findDOMNode(input).value).to.be('01:19:03'); 143 expect(ReactDOM.findDOMNode(input).value).to.be('01:19:04');
144 expect(picker.state.open).to.be.ok(); 144 expect(picker.state.open).to.be.ok();
145 145
146 next(); 146 next();
@@ -167,12 +167,12 @@ describe('Select', () => {
167 }, (next) => { 167 }, (next) => {
168 expect(picker.state.open).to.be(true); 168 expect(picker.state.open).to.be(true);
169 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; 169 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0];
170 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[2];
171 const option = selector.getElementsByTagName('li')[19];
172 expect(header).to.be.ok(); 170 expect(header).to.be.ok();
173 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); 171 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04');
174 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); 172 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04');
175 173
174 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[2];
175 const option = selector.getElementsByTagName('li')[19];
176 Simulate.click(option); 176 Simulate.click(option);
177 setTimeout(next, 100); 177 setTimeout(next, 100);
178 }, (next) => { 178 }, (next) => {
@@ -187,5 +187,124 @@ describe('Select', () => {
187 done(); 187 done();
188 }); 188 });
189 }); 189 });
190
191 it('disabled correctly', (done) => {
192 let change;
193 const picker = renderPicker({
194 onChange(v) {
195 change = v;
196 },
197 disabledMinutes(h) {
198 return [h];
199 },
200 disabledSeconds(h, m) {
201 return [h + m % 60];
202 },
203 });
204 expect(picker.state.open).not.to.be.ok();
205 const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0];
206 let header;
207 async.series([(next) => {
208 expect(picker.state.open).to.be(false);
209
210 Simulate.click(input);
211 setTimeout(next, 100);
212 }, (next) => {
213 expect(picker.state.open).to.be(true);
214 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0];
215 expect(header).to.be.ok();
216 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04');
217 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04');
218
219 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[1];
220 const option = selector.getElementsByTagName('li')[1];
221 Simulate.click(option);
222 setTimeout(next, 100);
223 }, (next) => {
224 expect(change).not.to.be.ok();
225 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04');
226 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04');
227 expect(picker.state.open).to.be.ok();
228
229 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[2];
230 const option = selector.getElementsByTagName('li')[3];
231 Simulate.click(option);
232 setTimeout(next, 100);
233 }, (next) => {
234 expect(change).not.to.be.ok();
235 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04');
236 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04');
237 expect(picker.state.open).to.be.ok();
238
239 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[1];
240 const option = selector.getElementsByTagName('li')[7];
241 Simulate.click(option);
242 setTimeout(next, 100);
243 }, (next) => {
244 expect(change).to.be.ok();
245 expect(change.getMinutes()).to.be(7);
246 expect(ReactDOM.findDOMNode(header).value).to.be('01:07:04');
247 expect(ReactDOM.findDOMNode(input).value).to.be('01:07:04');
248 expect(picker.state.open).to.be.ok();
249
250 next();
251 }], () => {
252 done();
253 });
254 });
255
256 it('hidden correctly', (done) => {
257 let change;
258 const picker = renderPicker({
259 onChange(v) {
260 change = v;
261 },
262 disabledHours() {
263 return [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23];
264 },
265 hideDisabledOptions: true,
266 });
267 expect(picker.state.open).not.to.be.ok();
268 const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0];
269 let header;
270 async.series([(next) => {
271 expect(picker.state.open).to.be(false);
272
273 Simulate.click(input);
274 setTimeout(next, 100);
275 }, (next) => {
276 expect(picker.state.open).to.be(true);
277 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0];
278 expect(header).to.be.ok();
279 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04');
280 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04');
281
282 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[0];
283 const option = selector.getElementsByTagName('li')[3];
284 Simulate.click(option);
285 setTimeout(next, 100);
286 }, (next) => {
287 expect(change).to.be.ok();
288 expect(change.getHourOfDay()).to.be(6);
289 expect(ReactDOM.findDOMNode(header).value).to.be('06:02:04');
290 expect(ReactDOM.findDOMNode(input).value).to.be('06:02:04');
291 expect(picker.state.open).to.be.ok();
292
293 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[0];
294 const option = selector.getElementsByTagName('li')[4];
295 Simulate.click(option);
296 setTimeout(next, 100);
297 }, (next) => {
298 expect(change).to.be.ok();
299 expect(change.getHourOfDay()).to.be(8);
300 expect(ReactDOM.findDOMNode(header).value).to.be('08:02:04');
301 expect(ReactDOM.findDOMNode(input).value).to.be('08:02:04');
302 expect(picker.state.open).to.be.ok();
303
304 next();
305 }], () => {
306 done();
307 });
308 });
190 }); 309 });
191}); 310});