commit | author | age
|
0d9dc7
|
1 |
// Create the dom before requiring react |
M |
2 |
var DOM = require( './testdom'); |
|
3 |
DOM(); |
|
4 |
|
516b36
|
5 |
|
M |
6 |
// Needs to be global to work in Travis CI |
92a2c6
|
7 |
React = require('react'); |
2d8253
|
8 |
ReactDOM = require('react-dom'); |
15436d
|
9 |
|
92a2c6
|
10 |
var Datetime = require('../DateTime'), |
0d9dc7
|
11 |
assert = require('assert'), |
92a2c6
|
12 |
moment = require('moment'), |
M |
13 |
TestUtils = require('react-addons-test-utils') |
0d9dc7
|
14 |
; |
M |
15 |
|
516b36
|
16 |
var createDatetime = function( props ){ |
2d8253
|
17 |
document.body.innerHTML = '<div id="root"></div>'; |
0d9dc7
|
18 |
|
2d8253
|
19 |
ReactDOM.render( |
516b36
|
20 |
React.createElement( Datetime, props ), |
2d8253
|
21 |
document.getElementById('root') |
0d9dc7
|
22 |
); |
M |
23 |
|
2d8253
|
24 |
return document.getElementById('root').children[0]; |
0d9dc7
|
25 |
}; |
M |
26 |
|
59314a
|
27 |
var trigger = function( name, element ){ |
M |
28 |
var ev = document.createEvent("MouseEvents"); |
|
29 |
ev.initEvent(name, true, true); |
|
30 |
element.dispatchEvent( ev ); |
|
31 |
}; |
|
32 |
|
92a2c6
|
33 |
var ev = TestUtils.Simulate; |
59314a
|
34 |
var dt = { |
M |
35 |
dt: function(){ |
2d8253
|
36 |
return document.getElementById('root').children[0]; |
59314a
|
37 |
}, |
M |
38 |
view: function(){ |
|
39 |
return this.dt().children[1].children[0]; |
|
40 |
}, |
|
41 |
input: function(){ |
|
42 |
return this.dt().children[0]; |
|
43 |
}, |
|
44 |
switcher: function(){ |
2d8253
|
45 |
return document.querySelector('.rdtSwitch'); |
59314a
|
46 |
}, |
M |
47 |
timeSwitcher: function(){ |
2d8253
|
48 |
return document.querySelector('.rdtTimeToggle'); |
59314a
|
49 |
}, |
M |
50 |
year: function( n ){ |
2d8253
|
51 |
var years = document.querySelectorAll('.rdtYear'); |
59314a
|
52 |
return years[ n || 0 ]; |
M |
53 |
}, |
|
54 |
month: function( n ){ |
2d8253
|
55 |
var months = document.querySelectorAll('.rdtMonth'); |
59314a
|
56 |
return months[ n || 0 ]; |
M |
57 |
}, |
|
58 |
day: function( n ){ |
2d8253
|
59 |
return document.querySelector('.rdtDay[data-value="' + n + '"]'); |
59314a
|
60 |
}, |
M |
61 |
next: function(){ |
a8a17a
|
62 |
return document.querySelector('.rdtNext span'); |
59314a
|
63 |
}, |
M |
64 |
prev: function(){ |
a8a17a
|
65 |
return document.querySelector('.rdtPrev span'); |
59314a
|
66 |
}, |
M |
67 |
timeUp: function( n ){ |
|
68 |
return document.querySelectorAll('.rdtCounter')[ n ].children[0]; |
|
69 |
}, |
|
70 |
timeDown: function( n ){ |
|
71 |
return document.querySelectorAll('.rdtCounter')[ n ].children[2]; |
|
72 |
}, |
|
73 |
hour: function(){ |
|
74 |
return document.querySelectorAll('.rdtCount')[0]; |
|
75 |
}, |
|
76 |
minute: function(){ |
|
77 |
return document.querySelectorAll('.rdtCount')[1]; |
|
78 |
}, |
|
79 |
second: function(){ |
|
80 |
return document.querySelectorAll('.rdtCount')[2]; |
|
81 |
}, |
|
82 |
milli: function(){ |
|
83 |
return document.querySelector('.rdtMilli input'); |
|
84 |
} |
|
85 |
}; |
|
86 |
|
|
87 |
var date = new Date( 2000, 0, 15, 2, 2, 2, 2 ), |
0d9dc7
|
88 |
mDate = moment( date ), |
049c33
|
89 |
strDate = mDate.format('L') + ' ' + mDate.format('LT'), |
TS |
90 |
mDateUTC = moment.utc(date), |
|
91 |
strDateUTC = mDateUTC.format('L') + ' ' + mDateUTC.format('LT') |
0d9dc7
|
92 |
; |
M |
93 |
|
|
94 |
describe( 'Datetime', function(){ |
|
95 |
it( 'Create Datetime', function(){ |
516b36
|
96 |
var component = createDatetime({}); |
0d9dc7
|
97 |
assert( component ); |
M |
98 |
assert.equal( component.children.length, 2 ); |
|
99 |
assert.equal( component.children[0].tagName , 'INPUT' ); |
|
100 |
assert.equal( component.children[1].tagName , 'DIV' ); |
|
101 |
}); |
|
102 |
|
|
103 |
it( 'input=false', function(){ |
516b36
|
104 |
var component = createDatetime({ input: false }); |
0d9dc7
|
105 |
assert( component ); |
M |
106 |
assert.equal( component.children.length, 1 ); |
|
107 |
assert.equal( component.children[0].tagName , 'DIV' ); |
|
108 |
}); |
|
109 |
|
92a2c6
|
110 |
|
0d9dc7
|
111 |
it( 'Date value', function(){ |
516b36
|
112 |
var component = createDatetime({ value: date }), |
0d9dc7
|
113 |
input = component.children[0] |
M |
114 |
; |
|
115 |
assert.equal( input.value, strDate ); |
|
116 |
}); |
|
117 |
|
|
118 |
it( 'Moment value', function(){ |
516b36
|
119 |
var component = createDatetime({ value: mDate }), |
0d9dc7
|
120 |
input = component.children[0] |
M |
121 |
; |
|
122 |
assert.equal( input.value, strDate ); |
|
123 |
}); |
|
124 |
|
|
125 |
it( 'String value', function(){ |
516b36
|
126 |
var component = createDatetime({ value: strDate }), |
0d9dc7
|
127 |
input = component.children[0] |
M |
128 |
; |
|
129 |
assert.equal( input.value, strDate ); |
|
130 |
}); |
|
131 |
|
98310d
|
132 |
it( 'UTC Value from local moment', function(){ |
049c33
|
133 |
var component = createDatetime({ |
TS |
134 |
value: mDate, |
|
135 |
utc: true |
|
136 |
}); |
|
137 |
var input = component.children[0]; |
|
138 |
assert.equal( input.value, strDateUTC ); |
|
139 |
}); |
|
140 |
|
98310d
|
141 |
it( 'UTC Value from UTC moment', function(){ |
049c33
|
142 |
var component = createDatetime({ |
TS |
143 |
value: mDateUTC, |
|
144 |
utc: true |
|
145 |
}); |
|
146 |
var input = component.children[0]; |
|
147 |
assert.equal( input.value, strDateUTC ); |
|
148 |
}); |
|
149 |
|
98310d
|
150 |
it( 'UTC Value from utc string', function(){ |
049c33
|
151 |
var component = createDatetime({ |
TS |
152 |
value: strDateUTC, |
|
153 |
utc: true |
|
154 |
}); |
|
155 |
var input = component.children[0]; |
|
156 |
assert.equal( input.value, strDateUTC ); |
|
157 |
}); |
|
158 |
|
0d9dc7
|
159 |
it( 'Date defaultValue', function(){ |
516b36
|
160 |
var component = createDatetime({ defaultValue: date }), |
0d9dc7
|
161 |
input = component.children[0] |
M |
162 |
; |
|
163 |
assert.equal( input.value, strDate ); |
|
164 |
}); |
|
165 |
|
|
166 |
it( 'Moment defaultValue', function(){ |
516b36
|
167 |
var component = createDatetime({ defaultValue: mDate }), |
0d9dc7
|
168 |
input = component.children[0] |
M |
169 |
; |
|
170 |
assert.equal( input.value, strDate ); |
|
171 |
}); |
|
172 |
|
|
173 |
it( 'String defaultValue', function(){ |
516b36
|
174 |
var component = createDatetime({ defaultValue: strDate }), |
0d9dc7
|
175 |
input = component.children[0] |
M |
176 |
; |
|
177 |
assert.equal( input.value, strDate ); |
|
178 |
}); |
|
179 |
|
|
180 |
it( 'dateFormat', function(){ |
516b36
|
181 |
var component = createDatetime({ value: date, dateFormat: 'M&D' }), |
0d9dc7
|
182 |
input = component.children[0] |
M |
183 |
; |
|
184 |
assert.equal( input.value, mDate.format('M&D LT') ); |
|
185 |
}); |
|
186 |
|
|
187 |
it( 'dateFormat=false', function(){ |
516b36
|
188 |
var component = createDatetime({ value: date, dateFormat: false }), |
0d9dc7
|
189 |
input = component.children[0], |
59314a
|
190 |
view = dt.view() |
0d9dc7
|
191 |
; |
M |
192 |
assert.equal( input.value, mDate.format('LT') ); |
|
193 |
// The view must be the timepicker |
|
194 |
assert.equal( view.className, 'rdtTime' ); |
|
195 |
// There must not be a date toggle |
|
196 |
assert.equal( view.querySelectorAll('thead').length, 0); |
|
197 |
}); |
98310d
|
198 |
|
0d9dc7
|
199 |
it( 'timeFormat', function(){ |
M |
200 |
var format = 'HH:mm:ss:SSS', |
516b36
|
201 |
component = createDatetime({ value: date, timeFormat: format }), |
0d9dc7
|
202 |
input = component.children[0] |
M |
203 |
; |
|
204 |
assert.equal( input.value, mDate.format('L ' + format) ); |
|
205 |
}); |
|
206 |
|
|
207 |
it( 'timeFormat=false', function(){ |
516b36
|
208 |
var component = createDatetime({ value: date, timeFormat: false }), |
0d9dc7
|
209 |
input = component.children[0], |
59314a
|
210 |
view = dt.view() |
0d9dc7
|
211 |
; |
M |
212 |
assert.equal( input.value, mDate.format('L') ); |
|
213 |
// The view must be the daypicker |
|
214 |
assert.equal( view.className, 'rdtDays' ); |
|
215 |
// There must not be a time toggle |
|
216 |
assert.equal( view.querySelectorAll('.timeToggle').length, 0); |
|
217 |
}); |
|
218 |
|
|
219 |
it( 'viewMode=years', function(){ |
516b36
|
220 |
var component = createDatetime({ viewMode: 'years' }), |
59314a
|
221 |
view = dt.view() |
0d9dc7
|
222 |
; |
M |
223 |
|
|
224 |
assert.equal( view.className, 'rdtYears' ); |
|
225 |
}); |
|
226 |
|
|
227 |
it( 'viewMode=months', function(){ |
516b36
|
228 |
var component = createDatetime({ viewMode: 'months' }), |
59314a
|
229 |
view = dt.view() |
0d9dc7
|
230 |
; |
M |
231 |
|
|
232 |
assert.equal( view.className, 'rdtMonths' ); |
|
233 |
}); |
|
234 |
|
|
235 |
it( 'viewMode=time', function(){ |
516b36
|
236 |
var component = createDatetime({ viewMode: 'time' }), |
59314a
|
237 |
view = dt.view() |
0d9dc7
|
238 |
; |
M |
239 |
|
|
240 |
assert.equal( view.className, 'rdtTime' ); |
|
241 |
}); |
|
242 |
|
386942
|
243 |
it( 'className of type string', function(){ |
516b36
|
244 |
var component = createDatetime({ className: 'custom' }); |
0d9dc7
|
245 |
assert.notEqual( component.className.indexOf('custom'), -1 ); |
M |
246 |
}); |
|
247 |
|
386942
|
248 |
it( 'className of type string array', function(){ |
SE |
249 |
var component = createDatetime({ className: ['custom1', 'custom2'] }); |
|
250 |
assert.notEqual( component.className.indexOf('custom1'), -1 ); |
|
251 |
assert.notEqual( component.className.indexOf('custom2'), -1 ); |
|
252 |
}); |
|
253 |
|
0d9dc7
|
254 |
it( 'inputProps', function(){ |
516b36
|
255 |
var component = createDatetime({ inputProps: { className: 'myInput', type: 'email' } }), |
0d9dc7
|
256 |
input = component.children[0] |
M |
257 |
; |
|
258 |
|
|
259 |
assert.equal( input.className, 'myInput' ); |
|
260 |
assert.equal( input.type, 'email' ); |
|
261 |
}); |
|
262 |
|
|
263 |
it( 'renderDay', function(){ |
|
264 |
var props, currentDate, selectedDate, |
516b36
|
265 |
component = createDatetime({ value: mDate, renderDay: function( p, current, selected ){ |
0d9dc7
|
266 |
props = p; |
M |
267 |
currentDate = current; |
|
268 |
selectedDate = selected; |
|
269 |
|
|
270 |
return React.DOM.td( props, 'day' ); |
|
271 |
}}), |
59314a
|
272 |
view = dt.view() |
0d9dc7
|
273 |
; |
M |
274 |
|
|
275 |
// Last day should be 6th of february |
|
276 |
assert.equal( currentDate.day(), 6 ); |
|
277 |
assert.equal( currentDate.month(), 1 ); |
|
278 |
|
|
279 |
// The date must be the same |
|
280 |
assert.equal( selectedDate.isSame( mDate ), true ); |
|
281 |
|
|
282 |
// There should be a onClick function in the props |
|
283 |
assert.equal( typeof props.onClick, 'function' ); |
|
284 |
|
|
285 |
// The cell text should be 'day' |
2d8253
|
286 |
assert.equal( view.querySelector('.rdtDay').innerHTML, 'day' ); |
0d9dc7
|
287 |
}); |
M |
288 |
|
|
289 |
it( 'renderMonth', function(){ |
|
290 |
var props, month, year, selectedDate, |
516b36
|
291 |
component = createDatetime({ value: mDate, viewMode: 'months', renderMonth: function( p, m, y, selected ){ |
0d9dc7
|
292 |
props = p; |
M |
293 |
month = m; |
|
294 |
year = y; |
|
295 |
selectedDate = selected; |
|
296 |
|
|
297 |
return React.DOM.td( props, 'month' ); |
|
298 |
}}), |
59314a
|
299 |
view = dt.view() |
0d9dc7
|
300 |
; |
M |
301 |
|
|
302 |
// The date must be the same |
|
303 |
assert.equal( selectedDate.isSame( mDate ), true ); |
|
304 |
|
|
305 |
assert.equal( month, 11 ); |
|
306 |
assert.equal( year, 2000 ); |
|
307 |
|
|
308 |
// There should be a onClick function in the props |
|
309 |
assert.equal( typeof props.onClick, 'function' ); |
|
310 |
|
|
311 |
// The cell text should be 'day' |
2d8253
|
312 |
assert.equal( view.querySelector('.rdtMonth').innerHTML, 'month' ); |
0d9dc7
|
313 |
}); |
M |
314 |
|
|
315 |
it( 'renderYear', function(){ |
|
316 |
var props, year, selectedDate, |
516b36
|
317 |
component = createDatetime({ value: mDate, viewMode: 'years', renderYear: function( p, y, selected ){ |
0d9dc7
|
318 |
props = p; |
M |
319 |
year = y; |
|
320 |
selectedDate = selected; |
|
321 |
|
|
322 |
return React.DOM.td( props, 'year' ); |
|
323 |
}}), |
59314a
|
324 |
view = dt.view() |
0d9dc7
|
325 |
; |
M |
326 |
|
|
327 |
// The date must be the same |
|
328 |
assert.equal( selectedDate.isSame( mDate ), true ); |
|
329 |
|
|
330 |
assert.equal( year, 2010 ); |
|
331 |
|
|
332 |
// There should be a onClick function in the props |
|
333 |
assert.equal( typeof props.onClick, 'function' ); |
|
334 |
|
|
335 |
// The cell text should be 'day' |
2d8253
|
336 |
assert.equal( view.querySelector('.rdtYear').innerHTML, 'year' ); |
0d9dc7
|
337 |
}); |
59314a
|
338 |
|
M |
339 |
it( 'Time pickers depends on the time format', function() { |
|
340 |
createDatetime({ viewMode: 'time', timeFormat: "HH:mm:ss:SSS"}); |
|
341 |
assert.equal( document.querySelectorAll('.rdtCounter').length, 4 ); |
|
342 |
|
|
343 |
createDatetime({ viewMode: 'time', timeFormat: "HH:mm:ss"}); |
|
344 |
assert.equal( document.querySelectorAll('.rdtCounter').length, 3 ); |
|
345 |
|
|
346 |
createDatetime({ viewMode: 'time', timeFormat: "HH:mm"}); |
|
347 |
assert.equal( document.querySelectorAll('.rdtCounter').length, 2 ); |
|
348 |
|
|
349 |
createDatetime({ viewMode: 'time', timeFormat: "HH"}); |
|
350 |
assert.equal( document.querySelectorAll('.rdtCounter').length, 1 ); |
|
351 |
}); |
|
352 |
|
|
353 |
it( 'viewChange', function() { |
|
354 |
createDatetime({viewMode: 'time' }); |
|
355 |
|
|
356 |
assert.equal( dt.view().className, 'rdtTime' ); |
|
357 |
ev.click( dt.switcher() ); |
|
358 |
assert.equal( dt.view().className, 'rdtDays' ); |
|
359 |
ev.click( dt.switcher() ); |
|
360 |
assert.equal( dt.view().className, 'rdtMonths' ); |
|
361 |
ev.click( dt.switcher() ); |
|
362 |
assert.equal( dt.view().className, 'rdtYears' ); |
|
363 |
}); |
|
364 |
|
|
365 |
it( 'switch to time', function(){ |
|
366 |
createDatetime({}); |
|
367 |
assert.equal( dt.view().className, 'rdtDays' ); |
|
368 |
ev.click( dt.timeSwitcher() ); |
|
369 |
assert.equal( dt.view().className, 'rdtTime' ); |
98310d
|
370 |
}); |
59314a
|
371 |
|
M |
372 |
it( 'selectYear', function(){ |
|
373 |
createDatetime({ viewMode: 'years', defaultValue: date }); |
|
374 |
assert.equal( dt.view().className, 'rdtYears' ); |
|
375 |
assert.equal( dt.switcher().innerHTML, '2000-2009' ); |
|
376 |
|
|
377 |
// First year is 1999 |
|
378 |
ev.click( dt.year() ); |
|
379 |
assert.equal( dt.view().className, 'rdtMonths' ); |
|
380 |
assert.equal( dt.switcher().innerHTML, '1999' ); |
|
381 |
}); |
|
382 |
|
|
383 |
it( 'increase decade', function(){ |
|
384 |
createDatetime({ viewMode: 'years', defaultValue: date }); |
|
385 |
|
|
386 |
assert.equal( dt.switcher().innerHTML, '2000-2009' ); |
|
387 |
ev.click( dt.next() ); |
|
388 |
assert.equal( dt.switcher().innerHTML, '2010-2019' ); |
|
389 |
ev.click( dt.next() ); |
|
390 |
assert.equal( dt.switcher().innerHTML, '2020-2029' ); |
|
391 |
}); |
|
392 |
|
|
393 |
it( 'decrease decade', function(){ |
|
394 |
createDatetime({ viewMode: 'years', defaultValue: date }); |
|
395 |
|
|
396 |
assert.equal( dt.switcher().innerHTML, '2000-2009' ); |
|
397 |
ev.click( dt.prev() ); |
|
398 |
assert.equal( dt.switcher().innerHTML, '1990-1999' ); |
|
399 |
ev.click( dt.prev() ); |
|
400 |
assert.equal( dt.switcher().innerHTML, '1980-1989' ); |
|
401 |
}); |
|
402 |
|
|
403 |
it( 'selectMonth', function(){ |
|
404 |
createDatetime({ viewMode: 'months', defaultValue: date }); |
|
405 |
assert.equal( dt.view().className, 'rdtMonths' ); |
|
406 |
assert.equal( dt.switcher().innerHTML, '2000' ); |
|
407 |
|
|
408 |
ev.click( dt.month(1) ); |
|
409 |
assert.equal( dt.view().className, 'rdtDays' ); |
|
410 |
assert.equal( dt.switcher().getAttribute('data-value'), "1" ); |
|
411 |
}); |
|
412 |
|
|
413 |
it( 'increase year', function(){ |
|
414 |
createDatetime({ viewMode: 'months', defaultValue: date }); |
|
415 |
|
|
416 |
assert.equal( dt.switcher().getAttribute('data-value'), '2000' ); |
|
417 |
ev.click( dt.next() ); |
|
418 |
assert.equal( dt.switcher().getAttribute('data-value'), '2001' ); |
|
419 |
ev.click( dt.next() ); |
|
420 |
assert.equal( dt.switcher().getAttribute('data-value'), '2002' ); |
|
421 |
}); |
|
422 |
|
|
423 |
it( 'decrease year', function(){ |
|
424 |
createDatetime({ viewMode: 'months', defaultValue: date }); |
|
425 |
|
|
426 |
assert.equal( dt.switcher().getAttribute('data-value'), '2000' ); |
|
427 |
ev.click( dt.prev() ); |
|
428 |
assert.equal( dt.switcher().getAttribute('data-value'), '1999' ); |
|
429 |
ev.click( dt.prev() ); |
|
430 |
assert.equal( dt.switcher().getAttribute('data-value'), '1998' ); |
|
431 |
}); |
|
432 |
|
|
433 |
it( 'increase month', function(){ |
|
434 |
createDatetime({ defaultValue: date }); |
|
435 |
|
|
436 |
assert.equal( dt.switcher().getAttribute('data-value'), '0' ); |
|
437 |
ev.click( dt.next() ); |
|
438 |
assert.equal( dt.switcher().getAttribute('data-value'), '1' ); |
|
439 |
ev.click( dt.next() ); |
|
440 |
assert.equal( dt.switcher().getAttribute('data-value'), '2' ); |
|
441 |
}); |
|
442 |
|
|
443 |
it( 'decrease month', function(){ |
|
444 |
createDatetime({ defaultValue: date }); |
|
445 |
|
|
446 |
assert.equal( dt.switcher().getAttribute('data-value'), '0' ); |
|
447 |
ev.click( dt.prev() ); |
|
448 |
assert.equal( dt.switcher().getAttribute('data-value'), '11' ); |
|
449 |
ev.click( dt.prev() ); |
|
450 |
assert.equal( dt.switcher().getAttribute('data-value'), '10' ); |
|
451 |
}); |
|
452 |
|
|
453 |
it( 'open picker', function(){ |
|
454 |
createDatetime({}); |
|
455 |
assert.equal(dt.dt().className.indexOf('rdtOpen'), -1); |
|
456 |
ev.focus( dt.input() ); |
|
457 |
assert.notEqual(dt.dt().className.indexOf('rdtOpen'), -1); |
|
458 |
}); |
|
459 |
|
|
460 |
it( 'onSelect', function( done ){ |
|
461 |
createDatetime({ defaultValue: date, onChange: function( selected ){ |
|
462 |
assert.equal( selected.date(), 2 ); |
|
463 |
assert.equal( selected.month(), mDate.month() ); |
|
464 |
assert.equal( selected.year(), mDate.year() ); |
|
465 |
done(); |
|
466 |
}}); |
|
467 |
|
|
468 |
ev.click( dt.day( 2 ) ); |
|
469 |
}); |
|
470 |
|
|
471 |
it( 'multiple onSelect', function( done ){ |
|
472 |
var i = 0; |
|
473 |
createDatetime({ defaultValue: date, onChange: function( selected ){ |
|
474 |
i++; |
|
475 |
if( i > 2 ){ |
|
476 |
assert.equal( selected.date(), 4 ); |
|
477 |
assert.equal( selected.month(), mDate.month() ); |
|
478 |
assert.equal( selected.year(), mDate.year() ); |
|
479 |
done(); |
|
480 |
} |
|
481 |
}}); |
|
482 |
|
|
483 |
ev.click( dt.day( 2 ) ); |
|
484 |
ev.click( dt.day( 3 ) ); |
|
485 |
ev.click( dt.day( 4 ) ); |
|
486 |
}); |
|
487 |
|
aca9e6
|
488 |
it( 'onFocus', function(){ |
R |
489 |
var focus = false; |
|
490 |
createDatetime({ value: date, onFocus: function( selected ){ |
|
491 |
focus = true; |
|
492 |
}}); |
|
493 |
|
|
494 |
ev.focus( dt.input() ); |
|
495 |
assert.equal( focus, true ); |
|
496 |
}); |
|
497 |
|
59314a
|
498 |
it( 'onBlur', function(){ |
M |
499 |
createDatetime({ value: date, onBlur: function( selected ){ |
|
500 |
assert.equal( dt.dt().className.indexOf( 'rdtOpen' ), -1 ); |
|
501 |
assert.equal( selected.date(), mDate.date() ); |
|
502 |
assert.equal( selected.month(), mDate.month() ); |
|
503 |
assert.equal( selected.year(), mDate.year() ); |
|
504 |
done(); |
|
505 |
}}); |
|
506 |
|
|
507 |
assert.equal( dt.dt().className.indexOf( 'rdtOpen' ), -1 ); |
|
508 |
ev.focus( dt.input() ); |
|
509 |
assert.notEqual( dt.dt().className.indexOf( 'rdtOpen' ), -1 ); |
|
510 |
trigger( 'click', document.body ); |
|
511 |
}); |
|
512 |
|
9012e8
|
513 |
it( 'closeOnTab:true', function(){ |
M |
514 |
createDatetime({ value: date }); |
|
515 |
|
|
516 |
assert.equal( dt.dt().className.indexOf( 'rdtOpen' ), -1 ); |
|
517 |
ev.focus( dt.input() ); |
|
518 |
assert.notEqual( dt.dt().className.indexOf( 'rdtOpen' ), -1 ); |
|
519 |
TestUtils.Simulate.keyDown(dt.input(), {key: "Tab", keyCode: 9, which: 9}); |
|
520 |
assert.equal( dt.dt().className.indexOf( 'rdtOpen' ), -1 ); |
|
521 |
trigger( 'click', document.body ); |
|
522 |
}); |
|
523 |
|
|
524 |
it( 'closeOnTab:false', function(){ |
|
525 |
createDatetime({ value: date, closeOnTab: false }); |
|
526 |
|
|
527 |
assert.equal( dt.dt().className.indexOf( 'rdtOpen' ), -1 ); |
|
528 |
ev.focus( dt.input() ); |
|
529 |
assert.notEqual( dt.dt().className.indexOf( 'rdtOpen' ), -1 ); |
|
530 |
TestUtils.Simulate.keyDown(dt.input(), {key: "Tab", keyCode: 9, which: 9}); |
|
531 |
assert.notEqual( dt.dt().className.indexOf( 'rdtOpen' ), -1 ); |
|
532 |
trigger( 'click', document.body ); |
|
533 |
}); |
|
534 |
|
59314a
|
535 |
it( 'increase time', function( done ){ |
M |
536 |
var i = 0; |
|
537 |
createDatetime({ timeFormat: "HH:mm:ss:SSS", viewMode: 'time', defaultValue: date, onChange: function( selected ){ |
|
538 |
i++; |
|
539 |
if( i > 2 ){ |
|
540 |
assert.equal( selected.hour(), 3 ); |
|
541 |
assert.equal( selected.minute(), 3 ); |
|
542 |
assert.equal( selected.second(), 3 ); |
|
543 |
done(); |
|
544 |
} |
|
545 |
}}); |
|
546 |
|
|
547 |
trigger( 'mousedown', dt.timeUp( 0 ) ); |
|
548 |
trigger('mouseup', document.body ); |
|
549 |
assert.equal( dt.hour().innerHTML, 3 ); |
|
550 |
trigger( 'mousedown', dt.timeUp( 1 ) ); |
|
551 |
trigger( 'mouseup', dt.timeUp( 1 ) ); |
|
552 |
assert.equal( dt.minute().innerHTML, 3 ); |
|
553 |
trigger( 'mousedown', dt.timeUp( 2 ) ); |
|
554 |
trigger( 'mouseup', dt.timeUp( 2 ) ); |
|
555 |
assert.equal( dt.second().innerHTML, 3 ); |
|
556 |
}); |
|
557 |
|
|
558 |
it( 'decrease time', function( done ){ |
|
559 |
var i = 0; |
|
560 |
createDatetime({ timeFormat: "HH:mm:ss:SSS", viewMode: 'time', defaultValue: date, onChange: function( selected ){ |
|
561 |
i++; |
|
562 |
if( i > 2 ){ |
|
563 |
assert.equal( selected.hour(), 1 ); |
|
564 |
assert.equal( selected.minute(), 1 ); |
|
565 |
assert.equal( selected.second(), 1 ); |
|
566 |
done(); |
|
567 |
} |
|
568 |
}}); |
|
569 |
|
|
570 |
trigger('mousedown', dt.timeDown( 0 ) ); |
|
571 |
trigger('mouseup', dt.timeDown( 0 ) ); |
|
572 |
assert.equal( dt.hour().innerHTML, 1 ); |
|
573 |
trigger('mousedown', dt.timeDown( 1 ) ); |
|
574 |
trigger('mouseup', dt.timeDown( 1 ) ); |
|
575 |
assert.equal( dt.minute().innerHTML, 1 ); |
|
576 |
trigger('mousedown', dt.timeDown( 2 ) ); |
|
577 |
trigger('mouseup', dt.timeDown( 2 ) ); |
|
578 |
assert.equal( dt.second().innerHTML, 1 ); |
|
579 |
}); |
|
580 |
|
|
581 |
it( 'long increase time', function( done ){ |
|
582 |
createDatetime({ timeFormat: "HH:mm:ss:SSS", viewMode: 'time', defaultValue: date}); |
|
583 |
|
|
584 |
trigger( 'mousedown', dt.timeUp( 0 ) ); |
|
585 |
setTimeout( function(){ |
|
586 |
trigger('mouseup', document.body ); |
|
587 |
assert.notEqual( dt.hour().innerHTML, 2 ); |
|
588 |
assert.notEqual( dt.hour().innerHTML, 3 ); |
|
589 |
done(); |
a79e6b
|
590 |
}, 920 ); |
59314a
|
591 |
}); |
M |
592 |
|
|
593 |
it( 'long decrease time', function( done ){ |
|
594 |
createDatetime({ timeFormat: "HH:mm:ss:SSS", viewMode: 'time', defaultValue: date}); |
|
595 |
|
|
596 |
trigger( 'mousedown', dt.timeDown( 0 ) ); |
|
597 |
setTimeout( function(){ |
|
598 |
trigger('mouseup', document.body ); |
|
599 |
assert.notEqual( dt.hour().innerHTML, 1 ); |
|
600 |
assert.notEqual( dt.hour().innerHTML, 0 ); |
|
601 |
done(); |
a79e6b
|
602 |
}, 920 ); |
59314a
|
603 |
}); |
62fd2f
|
604 |
|
9bb4f7
|
605 |
it( 'increase time with timeConstraints', function( done ){ |
LG |
606 |
var i = 0; |
|
607 |
createDatetime({ timeFormat: "HH:mm:ss:SSS", viewMode: 'time', defaultValue: date, onChange: function( selected ){ |
|
608 |
i++; |
|
609 |
if( i > 2 ){ |
|
610 |
assert.equal( selected.minute(), 17 ); |
|
611 |
assert.equal( selected.second(), 3 ); |
|
612 |
done(); |
|
613 |
} |
4ed404
|
614 |
}, timeConstraints: { hours: { max: 6, step: 8 }, minutes: { step: 15 }}}); |
9bb4f7
|
615 |
|
LG |
616 |
trigger( 'mousedown', dt.timeUp( 0 ) ); |
|
617 |
trigger('mouseup', document.body ); |
ef2929
|
618 |
assert.equal( dt.hour().innerHTML, 3 ); |
9bb4f7
|
619 |
trigger( 'mousedown', dt.timeUp( 1 ) ); |
LG |
620 |
trigger( 'mouseup', dt.timeUp( 1 ) ); |
|
621 |
assert.equal( dt.minute().innerHTML, 17 ); |
|
622 |
trigger( 'mousedown', dt.timeUp( 2 ) ); |
|
623 |
trigger( 'mouseup', dt.timeUp( 2 ) ); |
|
624 |
assert.equal( dt.second().innerHTML, 3 ); |
|
625 |
}); |
|
626 |
|
4ed404
|
627 |
it( 'decrease time with timeConstraints', function( done ){ |
LG |
628 |
createDatetime({ timeFormat: "HH:mm:ss:SSS", viewMode: 'time', defaultValue: date, onChange: function( selected ){ |
|
629 |
assert.equal( selected.minute(), 47 ); |
|
630 |
done(); |
|
631 |
}, timeConstraints: { minutes: { step: 15 }}}); |
|
632 |
|
|
633 |
trigger( 'mousedown', dt.timeDown( 1 ) ); |
|
634 |
trigger( 'mouseup', dt.timeDown( 1 ) ); |
|
635 |
assert.equal( dt.minute().innerHTML, 47 ); |
|
636 |
}); |
|
637 |
|
62fd2f
|
638 |
it( 'invalid input value', function( done ){ |
M |
639 |
createDatetime({ defaultValue: 'luis', onChange: function( updated ){ |
|
640 |
assert.equal( mDate.format('L LT'), updated.format('L LT') ); |
|
641 |
done(); |
|
642 |
}}); |
|
643 |
|
|
644 |
assert.equal( dt.input().value, 'luis' ); |
|
645 |
dt.input().value = strDate; |
92a2c6
|
646 |
ev.change( dt.input() ); |
62fd2f
|
647 |
}); |
M |
648 |
|
0eb496
|
649 |
it( 'invalid moment object as input value', function( done ){ |
SE |
650 |
var value = moment(null); |
|
651 |
createDatetime({ value: value, onChange: function( updated ){ |
|
652 |
assert.equal( mDate.format('L LT'), updated.format('L LT') ); |
|
653 |
done(); |
|
654 |
}}); |
|
655 |
|
|
656 |
assert.equal( dt.input().value, '' ); |
|
657 |
dt.input().value = strDate; |
|
658 |
ev.change( dt.input() ); |
|
659 |
}); |
|
660 |
|
62fd2f
|
661 |
it( 'delete input value', function( done ){ |
M |
662 |
createDatetime({ defaultValue: date, onChange: function( date ){ |
|
663 |
assert.equal( date, '' ); |
|
664 |
done(); |
|
665 |
}}); |
|
666 |
dt.input().value = ''; |
92a2c6
|
667 |
ev.change( dt.input() ); |
62fd2f
|
668 |
}); |
0eb226
|
669 |
|
NB |
670 |
it( 'strictParsing=true', function( done ){ |
|
671 |
var invalidStrDate = strDate + 'x'; |
|
672 |
createDatetime({ defaultValue: '', strictParsing: true, onChange: function( updated ){ |
|
673 |
assert.equal( updated, invalidStrDate); |
|
674 |
done(); |
|
675 |
}}); |
|
676 |
|
|
677 |
dt.input().value = invalidStrDate; |
92a2c6
|
678 |
ev.change( dt.input() ); |
0eb226
|
679 |
}); |
NB |
680 |
|
|
681 |
it( 'strictParsing=false', function( done ){ |
|
682 |
var invalidStrDate = strDate + 'x'; |
|
683 |
createDatetime({ defaultValue: '', strictParsing: false, onChange: function( updated ){ |
|
684 |
assert.equal( mDate.format('L LT'), updated.format('L LT') ); |
|
685 |
done(); |
|
686 |
}}); |
|
687 |
|
|
688 |
dt.input().value = invalidStrDate; |
92a2c6
|
689 |
ev.change( dt.input() ); |
0eb226
|
690 |
}); |
c306f2
|
691 |
|
R |
692 |
it( 'disable months', function(){ |
|
693 |
createDatetime({ viewMode: 'months', isValidDate: function( current ){ |
|
694 |
return current.isBefore(moment('2016-06-01', 'YYYY-MM-DD')); |
|
695 |
}}); |
|
696 |
assert.equal( dt.month(0).className, 'rdtMonth' ); |
|
697 |
assert.equal( dt.month(4).className, 'rdtMonth' ); |
|
698 |
assert.equal( dt.month(5).className, 'rdtMonth rdtDisabled' ); |
|
699 |
assert.equal( dt.month(11).className, 'rdtMonth rdtDisabled' ); |
|
700 |
}); |
|
701 |
|
|
702 |
it( 'disable years', function(){ |
|
703 |
createDatetime({ viewMode: 'years', isValidDate: function( current ){ |
|
704 |
return current.isBefore(moment('2016-01-01', 'YYYY-MM-DD')); |
|
705 |
}}); |
|
706 |
assert.equal( dt.year(6).className, 'rdtYear' ); |
|
707 |
assert.equal( dt.year(7).className, 'rdtYear rdtDisabled' ); |
|
708 |
}); |
98310d
|
709 |
|
SE |
710 |
it( 'locale', function(){ |
|
711 |
createDatetime({ locale: 'nl' }); |
|
712 |
view = dt.view(); |
|
713 |
var weekDays = []; |
|
714 |
var weekDaysHtmlQuery = view.querySelectorAll('.rdtDays .dow'); |
|
715 |
Array.prototype.forEach.call(weekDaysHtmlQuery, function(el) { |
|
716 |
weekDays.push(el.innerHTML); |
|
717 |
}); |
|
718 |
weekDays = weekDays.splice(0, 7); |
|
719 |
var weekDayNames = ['Ma', 'Di', 'Wo', 'Do', 'Vr', 'Za', 'Zo']; |
|
720 |
weekDays.map(function(weekDayHtml, index) { |
|
721 |
assert.equal( weekDayHtml, weekDayNames[index] ); |
|
722 |
}); |
|
723 |
}); |
|
724 |
|
|
725 |
it( 'locale in viewMode=months', function(){ |
|
726 |
createDatetime({ viewMode: 'months', locale: 'nl' }); |
|
727 |
view = dt.view(); |
|
728 |
var thirdMonth = view.querySelectorAll('.rdtMonth')[2].innerHTML; |
|
729 |
var fifthMonth = view.querySelectorAll('.rdtMonth')[4].innerHTML; |
|
730 |
assert.equal( thirdMonth, 'Mrt' ); |
|
731 |
assert.equal( fifthMonth, 'Mei' ); |
|
732 |
}); |
0d9dc7
|
733 |
}); |