Debian Codegraph @

tests/unit/datepicker/core.js

raw symbols SCIP
1 define( [
2 "qunit",
3 "jquery",
4 "lib/common",
5 "lib/helper",
6 "./helper",
7 "ui/widgets/datepicker",
8 "ui/i18n/datepicker-he"
9 ], function( QUnit, $, common, helper, testHelper ) {
10 "use strict";
11
12 QUnit.module( "datepicker: core", {
13 beforeEach: function() {
14 $( "body" ).trigger( "focus" );
15 },
16 afterEach: helper.moduleAfterEach
17 } );
18
19 QUnit.test( "initialization - Reinitialization after body had been emptied.", function( assert ) {
20 assert.expect( 1 );
21 var bodyContent = $( "body" ).children(), inp = $( "#inp" );
22 $( "#inp" ).datepicker();
23 $( "body" ).empty().append( inp );
24 $( "#inp" ).datepicker();
25 assert.ok( $( "#" + $.datepicker._mainDivId ).length === 1, "Datepicker container added" );
26 $( "body" ).empty().append( bodyContent ); // Returning to initial state for later tests
27 } );
28
29 QUnit.test( "widget method - empty collection", function( assert ) {
30 assert.expect( 1 );
31 $( "#nonExist" ).datepicker(); // Should create nothing
32 assert.ok( !$( "#ui-datepicker-div" ).length, "Non init on empty collection" );
33 } );
34
35 QUnit.test( "widget method", function( assert ) {
36 assert.expect( 1 );
37 var actual = $( "#inp" ).datepicker().datepicker( "widget" )[ 0 ];
38 assert.deepEqual( $( "body > #ui-datepicker-div:last-child" )[ 0 ], actual );
39 } );
40
41 QUnit.test( "baseStructure", function( assert ) {
42 var ready = assert.async();
43 assert.expect( 58 );
44 var header, title, table, thead, week, panel, inl, child,
45 inp = testHelper.initNewInput(),
46 dp = $( "#ui-datepicker-div" );
47
48 function step1() {
49 testHelper.onFocus( inp, function() {
50 assert.ok( dp.is( ":visible" ), "Structure - datepicker visible" );
51 assert.ok( !dp.is( ".ui-datepicker-rtl" ), "Structure - not right-to-left" );
52 assert.ok( !dp.is( ".ui-datepicker-multi" ), "Structure - not multi-month" );
53 assert.equal( dp.children().length, 2, "Structure - child count" );
54
55 header = dp.children().first();
56 assert.ok( header.is( "div.ui-datepicker-header" ), "Structure - header division" );
57 assert.equal( header.children().length, 3, "Structure - header child count" );
58 assert.ok( header.children().first().is( "a.ui-datepicker-prev" ) && header.children().first().html() !== "", "Structure - prev link" );
59 assert.ok( header.children().eq( 1 ).is( "a.ui-datepicker-next" ) && header.children().eq( 1 ).html() !== "", "Structure - next link" );
60
61 title = header.children().last();
62 assert.ok( title.is( "div.ui-datepicker-title" ) && title.html() !== "", "Structure - title division" );
63 assert.equal( title.children().length, 2, "Structure - title child count" );
64 assert.ok( title.children().first().is( "span.ui-datepicker-month" ) && title.children().first().text() !== "", "Structure - month text" );
65 assert.ok( title.children().last().is( "span.ui-datepicker-year" ) && title.children().last().text() !== "", "Structure - year text" );
66
67 table = dp.children().eq( 1 );
68 assert.ok( table.is( "table.ui-datepicker-calendar" ), "Structure - month table" );
69 assert.ok( table.children().first().is( "thead" ), "Structure - month table thead" );
70
71 thead = table.children().first().children().first();
72 assert.ok( thead.is( "tr" ), "Structure - month table title row" );
73 assert.equal( thead.find( "th" ).length, 7, "Structure - month table title cells" );
74 assert.ok( table.children().eq( 1 ).is( "tbody" ), "Structure - month table body" );
75 assert.ok( table.children().eq( 1 ).children( "tr" ).length >= 4, "Structure - month table week count" );
76
77 week = table.children().eq( 1 ).children().first();
78 assert.ok( week.is( "tr" ), "Structure - month table week row" );
79 assert.equal( week.children().length, 7, "Structure - week child count" );
80 assert.ok( week.children().first().is( "td.ui-datepicker-week-end" ), "Structure - month table first day cell" );
81 assert.ok( week.children().last().is( "td.ui-datepicker-week-end" ), "Structure - month table second day cell" );
82
83 inp.datepicker( "hide" ).datepicker( "destroy" );
84 step2();
85 } );
86 }
87
88 function step2() {
89
90 // Editable month/year and button panel
91 inp = testHelper.initNewInput( {
92 changeMonth: true,
93 changeYear: true,
94 showButtonPanel: true
95 } );
96 testHelper.onFocus( inp, function() {
97 title = dp.find( "div.ui-datepicker-title" );
98 assert.ok( title.children().first().is( "select.ui-datepicker-month" ), "Structure - month selector" );
99 assert.ok( title.children().last().is( "select.ui-datepicker-year" ), "Structure - year selector" );
100
101 panel = dp.children().last();
102 assert.ok( panel.is( "div.ui-datepicker-buttonpane" ), "Structure - button panel division" );
103 assert.equal( panel.children().length, 2, "Structure - button panel child count" );
104 assert.ok( panel.children().first().is( "button.ui-datepicker-current" ), "Structure - today button" );
105 assert.ok( panel.children().last().is( "button.ui-datepicker-close" ), "Structure - close button" );
106
107 inp.datepicker( "hide" ).datepicker( "destroy" );
108 step3();
109 } );
110 }
111
112 function step3() {
113
114 // Multi-month 2
115 inp = testHelper.initNewInput( { numberOfMonths: 2 } );
116 testHelper.onFocus( inp, function() {
117 assert.ok( dp.is( ".ui-datepicker-multi" ), "Structure multi [2] - multi-month" );
118 assert.equal( dp.children().length, 3, "Structure multi [2] - child count" );
119
120 child = dp.children().first();
121 assert.ok( child.is( "div.ui-datepicker-group" ) && child.is( "div.ui-datepicker-group-first" ), "Structure multi [2] - first month division" );
122
123 child = dp.children().eq( 1 );
124 assert.ok( child.is( "div.ui-datepicker-group" ) && child.is( "div.ui-datepicker-group-last" ), "Structure multi [2] - second month division" );
125
126 child = dp.children().eq( 2 );
127 assert.ok( child.is( "div.ui-datepicker-row-break" ), "Structure multi [2] - row break" );
128 assert.ok( dp.is( ".ui-datepicker-multi-2" ), "Structure multi [2] - multi-2" );
129
130 inp.datepicker( "hide" ).datepicker( "destroy" );
131 step4();
132 } );
133 }
134
135 function step4() {
136
137 // Multi-month 3
138 inp = testHelper.initNewInput( { numberOfMonths: 3 } );
139 testHelper.onFocus( inp, function() {
140 assert.ok( dp.is( ".ui-datepicker-multi-3" ), "Structure multi [3] - multi-3" );
141 assert.ok( !dp.is( ".ui-datepicker-multi-2" ), "Structure multi [3] - Trac #6704" );
142
143 inp.datepicker( "hide" ).datepicker( "destroy" );
144 step5();
145 } );
146 }
147
148 function step5() {
149
150 // Multi-month [2, 2]
151 inp = testHelper.initNewInput( { numberOfMonths: [ 2, 2 ] } );
152 testHelper.onFocus( inp, function() {
153 assert.ok( dp.is( ".ui-datepicker-multi" ), "Structure multi - multi-month" );
154 assert.equal( dp.children().length, 6, "Structure multi [2,2] - child count" );
155
156 child = dp.children().first();
157 assert.ok( child.is( "div.ui-datepicker-group" ) && child.is( "div.ui-datepicker-group-first" ), "Structure multi [2,2] - first month division" );
158
159 child = dp.children().eq( 1 );
160 assert.ok( child.is( "div.ui-datepicker-group" ) && child.is( "div.ui-datepicker-group-last" ), "Structure multi [2,2] - second month division" );
161
162 child = dp.children().eq( 2 );
163 assert.ok( child.is( "div.ui-datepicker-row-break" ), "Structure multi [2,2] - row break" );
164
165 child = dp.children().eq( 3 );
166 assert.ok( child.is( "div.ui-datepicker-group" ) && child.is( "div.ui-datepicker-group-first" ), "Structure multi [2,2] - third month division" );
167
168 child = dp.children().eq( 4 );
169 assert.ok( child.is( "div.ui-datepicker-group" ) && child.is( "div.ui-datepicker-group-last" ), "Structure multi [2,2] - fourth month division" );
170
171 child = dp.children().eq( 5 );
172 assert.ok( child.is( "div.ui-datepicker-row-break" ), "Structure multi [2,2] - row break" );
173
174 inp.datepicker( "hide" ).datepicker( "destroy" );
175
176 // Inline
177 inl = testHelper.init( "#inl" );
178 dp = inl.children();
179
180 assert.ok( dp.is( ".ui-datepicker-inline" ), "Structure inline - main div" );
181 assert.ok( !dp.is( ".ui-datepicker-rtl" ), "Structure inline - not right-to-left" );
182 assert.ok( !dp.is( ".ui-datepicker-multi" ), "Structure inline - not multi-month" );
183 assert.equal( dp.children().length, 2, "Structure inline - child count" );
184
185 header = dp.children().first();
186 assert.ok( header.is( "div.ui-datepicker-header" ), "Structure inline - header division" );
187 assert.equal( header.children().length, 3, "Structure inline - header child count" );
188
189 table = dp.children().eq( 1 );
190 assert.ok( table.is( "table.ui-datepicker-calendar" ), "Structure inline - month table" );
191 assert.ok( table.children().first().is( "thead" ), "Structure inline - month table thead" );
192 assert.ok( table.children().eq( 1 ).is( "tbody" ), "Structure inline - month table body" );
193
194 inl.datepicker( "destroy" );
195
196 // Inline multi-month
197 inl = testHelper.init( "#inl", { numberOfMonths: 2 } );
198 dp = inl.children();
199
200 assert.ok( dp.is( ".ui-datepicker-inline" ) && dp.is( ".ui-datepicker-multi" ), "Structure inline multi - main div" );
201 assert.equal( dp.children().length, 3, "Structure inline multi - child count" );
202
203 child = dp.children().first();
204 assert.ok( child.is( "div.ui-datepicker-group" ) && child.is( "div.ui-datepicker-group-first" ), "Structure inline multi - first month division" );
205
206 child = dp.children().eq( 1 );
207 assert.ok( child.is( "div.ui-datepicker-group" ) && child.is( "div.ui-datepicker-group-last" ), "Structure inline multi - second month division" );
208
209 child = dp.children().eq( 2 );
210 assert.ok( child.is( "div.ui-datepicker-row-break" ), "Structure inline multi - row break" );
211
212 inl.datepicker( "destroy" );
213 ready();
214 } );
215 }
216
217 step1();
218 } );
219
220 QUnit.test( "customStructure", function( assert ) {
221 var ready = assert.async();
222 assert.expect( 20 );
223 var header, panel, title, thead,
224 inp = testHelper.initNewInput( $.datepicker.regional.he ),
225 dp = $( "#ui-datepicker-div" );
226
227 function step1() {
228 inp.datepicker( "option", "showButtonPanel", true );
229
230 testHelper.onFocus( inp, function() {
231 assert.ok( dp.is( ".ui-datepicker-rtl" ), "Structure RTL - right-to-left" );
232
233 header = dp.children().first();
234 assert.ok( header.is( "div.ui-datepicker-header" ), "Structure RTL - header division" );
235 assert.equal( header.children().length, 3, "Structure RTL - header child count" );
236 assert.ok( header.children().first().is( "a.ui-datepicker-next" ), "Structure RTL - prev link" );
237 assert.ok( header.children().eq( 1 ).is( "a.ui-datepicker-prev" ), "Structure RTL - next link" );
238
239 panel = dp.children().last();
240 assert.ok( panel.is( "div.ui-datepicker-buttonpane" ), "Structure RTL - button division" );
241 assert.equal( panel.children().length, 2, "Structure RTL - button panel child count" );
242 assert.ok( panel.children().first().is( "button.ui-datepicker-close" ), "Structure RTL - close button" );
243 assert.ok( panel.children().last().is( "button.ui-datepicker-current" ), "Structure RTL - today button" );
244
245 inp.datepicker( "hide" ).datepicker( "destroy" );
246 step2();
247 } );
248 }
249
250 // Hide prev/next
251 function step2() {
252 inp = testHelper.initNewInput( {
253 hideIfNoPrevNext: true,
254 minDate: new Date( 2008, 2 - 1, 4 ),
255 maxDate: new Date( 2008, 2 - 1, 14 )
256 } );
257 inp.val( "02/10/2008" );
258
259 testHelper.onFocus( inp, function() {
260 header = dp.children().first();
261 assert.ok( header.is( "div.ui-datepicker-header" ), "Structure hide prev/next - header division" );
262 assert.equal( header.children().length, 1, "Structure hide prev/next - links child count" );
263 assert.ok( header.children().first().is( "div.ui-datepicker-title" ), "Structure hide prev/next - title division" );
264
265 inp.datepicker( "hide" ).datepicker( "destroy" );
266 step3();
267 } );
268 }
269
270 // Changeable Month with read-only year
271 function step3() {
272 inp = testHelper.initNewInput( { changeMonth: true } );
273
274 testHelper.onFocus( inp, function() {
275 title = dp.children().first().children().last();
276 assert.equal( title.children().length, 2, "Structure changeable month - title child count" );
277 assert.ok( title.children().first().is( "select.ui-datepicker-month" ), "Structure changeable month - month selector" );
278 assert.ok( title.children().last().is( "span.ui-datepicker-year" ), "Structure changeable month - read-only year" );
279
280 inp.datepicker( "hide" ).datepicker( "destroy" );
281 step4();
282 } );
283 }
284
285 // Changeable year with read-only month
286 function step4() {
287 inp = testHelper.initNewInput( { changeYear: true } );
288
289 testHelper.onFocus( inp, function() {
290 title = dp.children().first().children().last();
291 assert.equal( title.children().length, 2, "Structure changeable year - title child count" );
292 assert.ok( title.children().first().is( "span.ui-datepicker-month" ), "Structure changeable year - read-only month" );
293 assert.ok( title.children().last().is( "select.ui-datepicker-year" ), "Structure changeable year - year selector" );
294
295 inp.datepicker( "hide" ).datepicker( "destroy" );
296 step5();
297 } );
298 }
299
300 // Read-only first day of week
301 function step5() {
302 inp = testHelper.initNewInput( { changeFirstDay: false } );
303
304 testHelper.onFocus( inp, function() {
305 thead = dp.find( ".ui-datepicker-calendar thead tr" );
306 assert.equal( thead.children().length, 7, "Structure read-only first day - thead child count" );
307 assert.equal( thead.find( "a" ).length, 0, "Structure read-only first day - thead links count" );
308
309 inp.datepicker( "hide" ).datepicker( "destroy" );
310 ready();
311 } );
312 }
313
314 setTimeout( step1 );
315 } );
316
317 QUnit.test( "keystrokes", function( assert ) {
318 assert.expect( 26 );
319 var inp = testHelper.init( "#inp" ),
320 date = new Date();
321 inp.val( "" ).datepicker( "show" ).
322 simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
323 testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Keystroke enter" );
324 inp.val( "02/04/2008" ).datepicker( "show" ).
325 simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
326 testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2008, 2 - 1, 4 ),
327 "Keystroke enter - preset" );
328 inp.val( "02/04/2008" ).datepicker( "show" ).
329 simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.HOME } ).
330 simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
331 testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Keystroke ctrl+home" );
332 inp.val( "02/04/2008" ).datepicker( "show" ).
333 simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.END } );
334 assert.ok( inp.datepicker( "getDate" ) == null, "Keystroke ctrl+end" );
335 inp.val( "" ).datepicker( "show" ).
336 simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
337 assert.ok( inp.datepicker( "getDate" ) == null, "Keystroke esc" );
338 inp.val( "02/04/2008" ).datepicker( "show" ).
339 simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
340 testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2008, 2 - 1, 4 ),
341 "Keystroke esc - preset" );
342 inp.val( "02/04/2008" ).datepicker( "show" ).
343 simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP } ).
344 simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
345 testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2008, 2 - 1, 4 ),
346 "Keystroke esc - abandoned" );
347
348 // Moving by day or week
349 inp.val( "" ).datepicker( "show" ).
350 simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.LEFT } ).
351 simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
352 date.setDate( date.getDate() - 1 );
353 testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Keystroke ctrl+left" );
354 inp.val( "" ).datepicker( "show" ).
355 simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ).
356 simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
357 date.setDate( date.getDate() + 1 );
358 testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Keystroke left" );
359 inp.val( "" ).datepicker( "show" ).
360 simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.RIGHT } ).
361 simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
362 date.setDate( date.getDate() + 1 );
363 testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Keystroke ctrl+right" );
364 inp.val( "" ).datepicker( "show" ).
365 simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } ).
366 simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
367 date.setDate( date.getDate() - 1 );
368 testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Keystroke right" );
369 inp.val( "" ).datepicker( "show" ).
370 simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.UP } ).
371 simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
372 date.setDate( date.getDate() - 7 );
373 testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Keystroke ctrl+up" );
374 inp.val( "" ).datepicker( "show" ).
375 simulate( "keydown", { keyCode: $.ui.keyCode.UP } ).
376 simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
377 date.setDate( date.getDate() + 7 );
378 testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Keystroke up" );
379 inp.val( "" ).datepicker( "show" ).
380 simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.DOWN } ).
381 simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
382 date.setDate( date.getDate() + 7 );
383 testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Keystroke ctrl+down" );
384 inp.val( "" ).datepicker( "show" ).
385 simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ).
386 simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
387 date.setDate( date.getDate() - 7 );
388 testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Keystroke down" );
389
390 // Moving by month or year
391 inp.val( "02/04/2008" ).datepicker( "show" ).
392 simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ).
393 simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
394 testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2008, 1 - 1, 4 ),
395 "Keystroke pgup" );
396 inp.val( "02/04/2008" ).datepicker( "show" ).
397 simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ).
398 simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
399 testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2008, 3 - 1, 4 ),
400 "Keystroke pgdn" );
401 inp.val( "02/04/2008" ).datepicker( "show" ).
402 simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP } ).
403 simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
404 testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2007, 2 - 1, 4 ),
405 "Keystroke ctrl+pgup" );
406 inp.val( "02/04/2008" ).datepicker( "show" ).
407 simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN } ).
408 simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
409 testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2009, 2 - 1, 4 ),
410 "Keystroke ctrl+pgdn" );
411
412 // Check for moving to short months
413 inp.val( "03/31/2008" ).datepicker( "show" ).
414 simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ).
415 simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
416 testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2008, 2 - 1, 29 ),
417 "Keystroke pgup - Feb" );
418 inp.val( "01/30/2008" ).datepicker( "show" ).
419 simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ).
420 simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
421 testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2008, 2 - 1, 29 ),
422 "Keystroke pgdn - Feb" );
423 inp.val( "02/29/2008" ).datepicker( "show" ).
424 simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP } ).
425 simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
426 testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2007, 2 - 1, 28 ),
427 "Keystroke ctrl+pgup - Feb" );
428 inp.val( "02/29/2008" ).datepicker( "show" ).
429 simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN } ).
430 simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
431 testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2009, 2 - 1, 28 ),
432 "Keystroke ctrl+pgdn - Feb" );
433
434 // Goto current
435 inp.datepicker( "option", { gotoCurrent: true } ).
436 datepicker( "hide" ).val( "02/04/2008" ).datepicker( "show" ).
437 simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ).
438 simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.HOME } ).
439 simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
440 testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2008, 2 - 1, 4 ),
441 "Keystroke ctrl+home" );
442
443 // Change steps
444 inp.datepicker( "option", { stepMonths: 2, gotoCurrent: false } ).
445 datepicker( "hide" ).val( "02/04/2008" ).datepicker( "show" ).
446 simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ).
447 simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
448 testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2007, 12 - 1, 4 ),
449 "Keystroke pgup step 2" );
450 inp.val( "02/04/2008" ).datepicker( "show" ).
451 simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ).
452 simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
453 testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2008, 4 - 1, 4 ),
454 "Keystroke pgdn step 2" );
455 } );
456
457 QUnit.test( "mouse", function( assert ) {
458 assert.expect( 15 );
459 var inl,
460 inp = testHelper.init( "#inp" ),
461 dp = $( "#ui-datepicker-div" ),
462 date = new Date();
463 inp.val( "" ).datepicker( "show" );
464 $( ".ui-datepicker-calendar tbody a:contains(10)", dp ).simulate( "click", {} );
465 date.setDate( 10 );
466 testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Mouse click" );
467 inp.val( "02/04/2008" ).datepicker( "show" );
468 $( ".ui-datepicker-calendar tbody a:contains(12)", dp ).simulate( "click", {} );
469 testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2008, 2 - 1, 12 ),
470 "Mouse click - preset" );
471 inp.val( "02/04/2008" ).datepicker( "show" );
472 inp.val( "" ).datepicker( "show" );
473 $( "button.ui-datepicker-close", dp ).simulate( "click", {} );
474 assert.ok( inp.datepicker( "getDate" ) == null, "Mouse click - close" );
475 inp.val( "02/04/2008" ).datepicker( "show" );
476 $( "button.ui-datepicker-close", dp ).simulate( "click", {} );
477 testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2008, 2 - 1, 4 ),
478 "Mouse click - close + preset" );
479 inp.val( "02/04/2008" ).datepicker( "show" );
480 $( "a.ui-datepicker-prev", dp ).simulate( "click", {} );
481 $( "button.ui-datepicker-close", dp ).simulate( "click", {} );
482 testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2008, 2 - 1, 4 ),
483 "Mouse click - abandoned" );
484
485 // Current/previous/next
486 inp.val( "02/04/2008" ).datepicker( "option", { showButtonPanel: true } ).datepicker( "show" );
487 $( ".ui-datepicker-current", dp ).simulate( "click", {} );
488 $( ".ui-datepicker-calendar tbody a:contains(14)", dp ).simulate( "click", {} );
489 date.setDate( 14 );
490 testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Mouse click - current" );
491 inp.val( "02/04/2008" ).datepicker( "show" );
492 $( ".ui-datepicker-prev", dp ).simulate( "click" );
493 $( ".ui-datepicker-calendar tbody a:contains(16)", dp ).simulate( "click" );
494 testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2008, 1 - 1, 16 ),
495 "Mouse click - previous" );
496 inp.val( "02/04/2008" ).datepicker( "show" );
497 $( ".ui-datepicker-next", dp ).simulate( "click" );
498 $( ".ui-datepicker-calendar tbody a:contains(18)", dp ).simulate( "click" );
499 testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2008, 3 - 1, 18 ),
500 "Mouse click - next" );
501
502 // Previous/next with minimum/maximum
503 inp.datepicker( "option", { minDate: new Date( 2008, 2 - 1, 2 ),
504 maxDate: new Date( 2008, 2 - 1, 26 ) } ).val( "02/04/2008" ).datepicker( "show" );
505 $( ".ui-datepicker-prev", dp ).simulate( "click" );
506 $( ".ui-datepicker-calendar tbody a:contains(16)", dp ).simulate( "click" );
507 testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2008, 2 - 1, 16 ),
508 "Mouse click - previous + min/max" );
509 inp.val( "02/04/2008" ).datepicker( "show" );
510 $( ".ui-datepicker-next", dp ).simulate( "click" );
511 $( ".ui-datepicker-calendar tbody a:contains(18)", dp ).simulate( "click" );
512 testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2008, 2 - 1, 18 ),
513 "Mouse click - next + min/max" );
514
515 // Inline
516 inl = testHelper.init( "#inl" );
517 dp = $( ".ui-datepicker-inline", inl );
518 date = new Date();
519 inl.datepicker( "setDate", date );
520 $( ".ui-datepicker-calendar tbody a:contains(10)", dp ).simulate( "click", {} );
521 date.setDate( 10 );
522 testHelper.equalsDate( assert, inl.datepicker( "getDate" ), date, "Mouse click inline" );
523 inl.datepicker( "option", { showButtonPanel: true } ).datepicker( "setDate", new Date( 2008, 2 - 1, 4 ) );
524 $( ".ui-datepicker-calendar tbody a:contains(12)", dp ).simulate( "click", {} );
525 testHelper.equalsDate( assert, inl.datepicker( "getDate" ), new Date( 2008, 2 - 1, 12 ), "Mouse click inline - preset" );
526 inl.datepicker( "option", { showButtonPanel: true } );
527 $( ".ui-datepicker-current", dp ).simulate( "click", {} );
528 $( ".ui-datepicker-calendar tbody a:contains(14)", dp ).simulate( "click", {} );
529 date.setDate( 14 );
530 testHelper.equalsDate( assert, inl.datepicker( "getDate" ), date, "Mouse click inline - current" );
531 inl.datepicker( "setDate", new Date( 2008, 2 - 1, 4 ) );
532 $( ".ui-datepicker-prev", dp ).simulate( "click" );
533 $( ".ui-datepicker-calendar tbody a:contains(16)", dp ).simulate( "click" );
534 testHelper.equalsDate( assert, inl.datepicker( "getDate" ), new Date( 2008, 1 - 1, 16 ),
535 "Mouse click inline - previous" );
536 inl.datepicker( "setDate", new Date( 2008, 2 - 1, 4 ) );
537 $( ".ui-datepicker-next", dp ).simulate( "click" );
538 $( ".ui-datepicker-calendar tbody a:contains(18)", dp ).simulate( "click" );
539 testHelper.equalsDate( assert, inl.datepicker( "getDate" ), new Date( 2008, 3 - 1, 18 ),
540 "Mouse click inline - next" );
541 } );
542
543 } );