1 import ReactDOM from 'react-dom';
2 import React from 'react';
3 import TimePicker from '../src/TimePicker';
4 import TestUtils from 'react-addons-test-utils';
5 const Simulate = TestUtils.Simulate;
6 import expect from 'expect.js';
7 import async from 'async';
8 import moment from 'moment';
10 describe('Select', () => {
13 function renderPicker(props) {
14 const showSecond = true;
15 const format = 'HH:mm:ss';
17 return ReactDOM.render(
20 showSecond={showSecond}
21 defaultValue={moment('01:02:04', format)}
27 container = document.createElement('div');
28 document.body.appendChild(container);
32 ReactDOM.unmountComponentAtNode(container);
33 document.body.removeChild(container);
36 describe('select number', () => {
37 it('select number correctly', (done) => {
38 const picker = renderPicker();
39 expect(picker.state.open).not.to.be.ok();
40 const input = TestUtils.scryRenderedDOMComponentsWithClass(picker,
41 'rc-time-picker-input')[0];
43 async.series([(next) => {
44 expect(picker.state.open).to.be(false);
46 Simulate.click(input);
47 setTimeout(next, 100);
49 expect(picker.state.open).to.be(true);
50 selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance,
51 'rc-time-picker-panel-select');
53 setTimeout(next, 100);
55 expect(selector.length).to.be(3);
64 describe('select to change value', () => {
65 it('hour correctly', (done) => {
67 const picker = renderPicker({
72 expect(picker.state.open).not.to.be.ok();
73 const input = TestUtils.scryRenderedDOMComponentsWithClass(picker,
74 'rc-time-picker-input')[0];
76 async.series([(next) => {
77 expect(picker.state.open).to.be(false);
79 Simulate.click(input);
80 setTimeout(next, 100);
82 expect(picker.state.open).to.be(true);
83 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance,
84 'rc-time-picker-panel-input')[0];
85 expect(header).to.be.ok();
86 expect((header).value).to.be('01:02:04');
87 expect((input).value).to.be('01:02:04');
89 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance,
90 'rc-time-picker-panel-select')[0];
91 const option = selector.getElementsByTagName('li')[19];
92 Simulate.click(option);
93 setTimeout(next, 100);
95 expect(change).to.be.ok();
96 expect(change.hour()).to.be(19);
97 expect((header).value).to.be('19:02:04');
98 expect((input).value).to.be('19:02:04');
99 expect(picker.state.open).to.be.ok();
107 it('minute correctly', (done) => {
109 const picker = renderPicker({
114 expect(picker.state.open).not.to.be.ok();
115 const input = TestUtils.scryRenderedDOMComponentsWithClass(picker,
116 'rc-time-picker-input')[0];
118 async.series([(next) => {
119 expect(picker.state.open).to.be(false);
121 Simulate.click(input);
122 setTimeout(next, 100);
124 expect(picker.state.open).to.be(true);
125 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance,
126 'rc-time-picker-panel-input')[0];
127 expect(header).to.be.ok();
128 expect((header).value).to.be('01:02:04');
129 expect((input).value).to.be('01:02:04');
131 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance,
132 'rc-time-picker-panel-select')[1];
133 const option = selector.getElementsByTagName('li')[19];
134 Simulate.click(option);
135 setTimeout(next, 100);
137 expect(change).to.be.ok();
138 expect(change.minute()).to.be(19);
139 expect((header).value).to.be('01:19:04');
140 expect((input).value).to.be('01:19:04');
141 expect(picker.state.open).to.be.ok();
149 it('second correctly', (done) => {
151 const picker = renderPicker({
156 expect(picker.state.open).not.to.be.ok();
157 const input = TestUtils.scryRenderedDOMComponentsWithClass(picker,
158 'rc-time-picker-input')[0];
160 async.series([(next) => {
161 expect(picker.state.open).to.be(false);
163 Simulate.click(input);
164 setTimeout(next, 100);
166 expect(picker.state.open).to.be(true);
167 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance,
168 'rc-time-picker-panel-input')[0];
169 expect(header).to.be.ok();
170 expect((header).value).to.be('01:02:04');
171 expect((input).value).to.be('01:02:04');
173 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance,
174 'rc-time-picker-panel-select')[2];
175 const option = selector.getElementsByTagName('li')[19];
176 Simulate.click(option);
177 setTimeout(next, 100);
179 expect(change).to.be.ok();
180 expect(change.second()).to.be(19);
181 expect((header).value).to.be('01:02:19');
182 expect((input).value).to.be('01:02:19');
183 expect(picker.state.open).to.be.ok();
191 it('disabled correctly', (done) => {
193 const picker = renderPicker({
200 disabledSeconds(h, m) {
204 expect(picker.state.open).not.to.be.ok();
205 const input = TestUtils.scryRenderedDOMComponentsWithClass(picker,
206 'rc-time-picker-input')[0];
208 async.series([(next) => {
209 expect(picker.state.open).to.be(false);
211 Simulate.click(input);
212 setTimeout(next, 100);
214 expect(picker.state.open).to.be(true);
215 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance,
216 'rc-time-picker-panel-input')[0];
217 expect(header).to.be.ok();
218 expect((header).value).to.be('01:02:04');
219 expect((input).value).to.be('01:02:04');
221 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance,
222 'rc-time-picker-panel-select')[1];
223 const option = selector.getElementsByTagName('li')[1];
224 Simulate.click(option);
225 setTimeout(next, 100);
227 expect(change).not.to.be.ok();
228 expect((header).value).to.be('01:02:04');
229 expect((input).value).to.be('01:02:04');
230 expect(picker.state.open).to.be.ok();
232 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance,
233 'rc-time-picker-panel-select')[2];
234 const option = selector.getElementsByTagName('li')[3];
235 Simulate.click(option);
236 setTimeout(next, 100);
238 expect(change).not.to.be.ok();
239 expect((header).value).to.be('01:02:04');
240 expect((input).value).to.be('01:02:04');
241 expect(picker.state.open).to.be.ok();
243 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance,
244 'rc-time-picker-panel-select')[1];
245 const option = selector.getElementsByTagName('li')[7];
246 Simulate.click(option);
247 setTimeout(next, 100);
249 expect(change).to.be.ok();
250 expect(change.minute()).to.be(7);
251 expect((header).value).to.be('01:07:04');
252 expect((input).value).to.be('01:07:04');
253 expect(picker.state.open).to.be.ok();
261 it('hidden correctly', (done) => {
263 const picker = renderPicker({
268 return [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23];
270 hideDisabledOptions: true,
272 expect(picker.state.open).not.to.be.ok();
273 const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0];
275 async.series([(next) => {
276 expect(picker.state.open).to.be(false);
278 Simulate.click(input);
279 setTimeout(next, 100);
281 expect(picker.state.open).to.be(true);
282 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance,
283 'rc-time-picker-panel-input')[0];
284 expect(header).to.be.ok();
285 expect((header).value).to.be('01:02:04');
286 expect((input).value).to.be('01:02:04');
288 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance,
289 'rc-time-picker-panel-select')[0];
290 const option = selector.getElementsByTagName('li')[3];
291 Simulate.click(option);
292 setTimeout(next, 100);
294 expect(change).to.be.ok();
295 expect(change.hour()).to.be(6);
296 expect((header).value).to.be('06:02:04');
297 expect((input).value).to.be('06:02:04');
298 expect(picker.state.open).to.be.ok();
300 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance,
301 'rc-time-picker-panel-select')[0];
302 const option = selector.getElementsByTagName('li')[4];
303 Simulate.click(option);
304 setTimeout(next, 100);
306 expect(change).to.be.ok();
307 expect(change.hour()).to.be(8);
308 expect((header).value).to.be('08:02:04');
309 expect((input).value).to.be('08:02:04');
310 expect(picker.state.open).to.be.ok();