aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/datepicker/core.js
blob: edc16d005dfaea10017ac2719d2b533a2a39c7b0 (plain)
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
define( [
	"qunit",
	"jquery",
	"lib/common",
	"lib/helper",
	"./helper",
	"ui/widgets/datepicker",
	"ui/i18n/datepicker-he"
], function( QUnit, $, common, helper, testHelper ) {
"use strict";

QUnit.module( "datepicker: core", {
	beforeEach: function() {
		$( "body" ).trigger( "focus" );
	},
	afterEach: helper.moduleAfterEach
} );

QUnit.test( "initialization - Reinitialization after body had been emptied.", function( assert ) {
	assert.expect( 1 );
	var bodyContent = $( "body" ).children(), inp = $( "#inp" );
	$( "#inp" ).datepicker();
	$( "body" ).empty().append( inp );
	$( "#inp" ).datepicker();
	assert.ok( $( "#" + $.datepicker._mainDivId ).length === 1, "Datepicker container added" );
	$( "body" ).empty().append( bodyContent ); // Returning to initial state for later tests
} );

QUnit.test( "widget method - empty collection", function( assert ) {
	assert.expect( 1 );
	$( "#nonExist" ).datepicker(); // Should create nothing
	assert.ok( !$( "#ui-datepicker-div" ).length, "Non init on empty collection" );
} );

QUnit.test( "widget method", function( assert ) {
	assert.expect( 1 );
	var actual = $( "#inp" ).datepicker().datepicker( "widget" )[ 0 ];
	assert.deepEqual( $( "body > #ui-datepicker-div:last-child" )[ 0 ], actual );
} );

QUnit.test( "baseStructure", function( assert ) {
	var ready = assert.async();
	assert.expect( 58 );
	var header, title, table, thead, week, panel, inl, child,
		inp = testHelper.initNewInput(),
		dp = $( "#ui-datepicker-div" );

	function step1() {
		testHelper.onFocus( inp, function() {
			assert.ok( dp.is( ":visible" ), "Structure - datepicker visible" );
			assert.ok( !dp.is( ".ui-datepicker-rtl" ), "Structure - not right-to-left" );
			assert.ok( !dp.is( ".ui-datepicker-multi" ), "Structure - not multi-month" );
			assert.equal( dp.children().length, 2, "Structure - child count" );

			header = dp.children().first();
			assert.ok( header.is( "div.ui-datepicker-header" ), "Structure - header division" );
			assert.equal( header.children().length, 3, "Structure - header child count" );
			assert.ok( header.children().first().is( "a.ui-datepicker-prev" ) && header.children().first().html() !== "", "Structure - prev link" );
			assert.ok( header.children().eq( 1 ).is( "a.ui-datepicker-next" ) && header.children().eq( 1 ).html() !== "", "Structure - next link" );

			title = header.children().last();
			assert.ok( title.is( "div.ui-datepicker-title" ) && title.html() !== "", "Structure - title division" );
			assert.equal( title.children().length, 2, "Structure - title child count" );
			assert.ok( title.children().first().is( "span.ui-datepicker-month" ) && title.children().first().text() !== "", "Structure - month text" );
			assert.ok( title.children().last().is( "span.ui-datepicker-year" ) && title.children().last().text() !== "", "Structure - year text" );

			table = dp.children().eq( 1 );
			assert.ok( table.is( "table.ui-datepicker-calendar" ), "Structure - month table" );
			assert.ok( table.children().first().is( "thead" ), "Structure - month table thead" );

			thead = table.children().first().children().first();
			assert.ok( thead.is( "tr" ), "Structure - month table title row" );
			assert.equal( thead.find( "th" ).length, 7, "Structure - month table title cells" );
			assert.ok( table.children().eq( 1 ).is( "tbody" ), "Structure - month table body" );
			assert.ok( table.children().eq( 1 ).children( "tr" ).length >= 4, "Structure - month table week count" );

			week = table.children().eq( 1 ).children().first();
			assert.ok( week.is( "tr" ), "Structure - month table week row" );
			assert.equal( week.children().length, 7, "Structure - week child count" );
			assert.ok( week.children().first().is( "td.ui-datepicker-week-end" ), "Structure - month table first day cell" );
			assert.ok( week.children().last().is( "td.ui-datepicker-week-end" ), "Structure - month table second day cell" );

			inp.datepicker( "hide" ).datepicker( "destroy" );
			step2();
		} );
	}

	function step2() {

		// Editable month/year and button panel
		inp = testHelper.initNewInput( {
			changeMonth: true,
			changeYear: true,
			showButtonPanel: true
		} );
		testHelper.onFocus( inp, function() {
			title = dp.find( "div.ui-datepicker-title" );
			assert.ok( title.children().first().is( "select.ui-datepicker-month" ), "Structure - month selector" );
			assert.ok( title.children().last().is( "select.ui-datepicker-year" ), "Structure - year selector" );

			panel = dp.children().last();
			assert.ok( panel.is( "div.ui-datepicker-buttonpane" ), "Structure - button panel division" );
			assert.equal( panel.children().length, 2, "Structure - button panel child count" );
			assert.ok( panel.children().first().is( "button.ui-datepicker-current" ), "Structure - today button" );
			assert.ok( panel.children().last().is( "button.ui-datepicker-close" ), "Structure - close button" );

			inp.datepicker( "hide" ).datepicker( "destroy" );
			step3();
		} );
	}

	function step3() {

		// Multi-month 2
		inp = testHelper.initNewInput( { numberOfMonths: 2 } );
		testHelper.onFocus( inp, function() {
			assert.ok( dp.is( ".ui-datepicker-multi" ), "Structure multi [2] - multi-month" );
			assert.equal( dp.children().length, 3, "Structure multi [2] - child count" );

			child = dp.children().first();
			assert.ok( child.is( "div.ui-datepicker-group" ) && child.is( "div.ui-datepicker-group-first" ), "Structure multi [2] - first month division" );

			child = dp.children().eq( 1 );
			assert.ok( child.is( "div.ui-datepicker-group" ) && child.is( "div.ui-datepicker-group-last" ), "Structure multi [2] - second month division" );

			child = dp.children().eq( 2 );
			assert.ok( child.is( "div.ui-datepicker-row-break" ), "Structure multi [2] - row break" );
			assert.ok( dp.is( ".ui-datepicker-multi-2" ), "Structure multi [2] - multi-2" );

			inp.datepicker( "hide" ).datepicker( "destroy" );
			step4();
		} );
	}

	function step4() {

		// Multi-month 3
		inp = testHelper.initNewInput( { numberOfMonths: 3 } );
		testHelper.onFocus( inp, function() {
			assert.ok( dp.is( ".ui-datepicker-multi-3" ), "Structure multi [3] - multi-3" );
			assert.ok( !dp.is( ".ui-datepicker-multi-2" ), "Structure multi [3] - Trac #6704" );

			inp.datepicker( "hide" ).datepicker( "destroy" );
			step5();
		} );
	}

	function step5() {

		// Multi-month [2, 2]
		inp = testHelper.initNewInput( { numberOfMonths: [ 2, 2 ] } );
		testHelper.onFocus( inp, function() {
			assert.ok( dp.is( ".ui-datepicker-multi" ), "Structure multi - multi-month" );
			assert.equal( dp.children().length, 6, "Structure multi [2,2] - child count" );

			child = dp.children().first();
			assert.ok( child.is( "div.ui-datepicker-group" ) && child.is( "div.ui-datepicker-group-first" ), "Structure multi [2,2] - first month division" );

			child = dp.children().eq( 1 );
			assert.ok( child.is( "div.ui-datepicker-group" ) && child.is( "div.ui-datepicker-group-last" ), "Structure multi [2,2] - second month division" );

			child = dp.children().eq( 2 );
			assert.ok( child.is( "div.ui-datepicker-row-break" ), "Structure multi [2,2] - row break" );

			child = dp.children().eq( 3 );
			assert.ok( child.is( "div.ui-datepicker-group" ) && child.is( "div.ui-datepicker-group-first" ), "Structure multi [2,2] - third month division" );

			child = dp.children().eq( 4 );
			assert.ok( child.is( "div.ui-datepicker-group" ) && child.is( "div.ui-datepicker-group-last" ), "Structure multi [2,2] - fourth month division" );

			child = dp.children().eq( 5 );
			assert.ok( child.is( "div.ui-datepicker-row-break" ), "Structure multi [2,2] - row break" );

			inp.datepicker( "hide" ).datepicker( "destroy" );

			// Inline
			inl = testHelper.init( "#inl" );
			dp = inl.children();

			assert.ok( dp.is( ".ui-datepicker-inline" ), "Structure inline - main div" );
			assert.ok( !dp.is( ".ui-datepicker-rtl" ), "Structure inline - not right-to-left" );
			assert.ok( !dp.is( ".ui-datepicker-multi" ), "Structure inline - not multi-month" );
			assert.equal( dp.children().length, 2, "Structure inline - child count" );

			header = dp.children().first();
			assert.ok( header.is( "div.ui-datepicker-header" ), "Structure inline - header division" );
			assert.equal( header.children().length, 3, "Structure inline - header child count" );

			table = dp.children().eq( 1 );
			assert.ok( table.is( "table.ui-datepicker-calendar" ), "Structure inline - month table" );
			assert.ok( table.children().first().is( "thead" ), "Structure inline - month table thead" );
			assert.ok( table.children().eq( 1 ).is( "tbody" ), "Structure inline - month table body" );

			inl.datepicker( "destroy" );

			// Inline multi-month
			inl = testHelper.init( "#inl", { numberOfMonths: 2 } );
			dp = inl.children();

			assert.ok( dp.is( ".ui-datepicker-inline" ) && dp.is( ".ui-datepicker-multi" ), "Structure inline multi - main div" );
			assert.equal( dp.children().length, 3, "Structure inline multi - child count" );

			child = dp.children().first();
			assert.ok( child.is( "div.ui-datepicker-group" ) && child.is( "div.ui-datepicker-group-first" ), "Structure inline multi - first month division" );

			child = dp.children().eq( 1 );
			assert.ok( child.is( "div.ui-datepicker-group" ) && child.is( "div.ui-datepicker-group-last" ), "Structure inline multi - second month division" );

			child = dp.children().eq( 2 );
			assert.ok( child.is( "div.ui-datepicker-row-break" ), "Structure inline multi - row break" );

			inl.datepicker( "destroy" );
			ready();
		} );
	}

	step1();
} );

QUnit.test( "customStructure", function( assert ) {
	var ready = assert.async();
	assert.expect( 20 );
	var header, panel, title, thead,
		inp = testHelper.initNewInput( $.datepicker.regional.he ),
		dp = $( "#ui-datepicker-div" );

	function step1() {
		inp.datepicker( "option", "showButtonPanel", true );

		testHelper.onFocus( inp, function() {
			assert.ok( dp.is( ".ui-datepicker-rtl" ), "Structure RTL - right-to-left" );

			header = dp.children().first();
			assert.ok( header.is( "div.ui-datepicker-header" ), "Structure RTL - header division" );
			assert.equal( header.children().length, 3, "Structure RTL - header child count" );
			assert.ok( header.children().first().is( "a.ui-datepicker-next" ), "Structure RTL - prev link" );
			assert.ok( header.children().eq( 1 ).is( "a.ui-datepicker-prev" ), "Structure RTL - next link" );

			panel = dp.children().last();
			assert.ok( panel.is( "div.ui-datepicker-buttonpane" ), "Structure RTL - button division" );
			assert.equal( panel.children().length, 2, "Structure RTL - button panel child count" );
			assert.ok( panel.children().first().is( "button.ui-datepicker-close" ), "Structure RTL - close button" );
			assert.ok( panel.children().last().is( "button.ui-datepicker-current" ), "Structure RTL - today button" );

			inp.datepicker( "hide" ).datepicker( "destroy" );
			step2();
		} );
	}

	// Hide prev/next
	function step2() {
		inp = testHelper.initNewInput( {
			hideIfNoPrevNext: true,
			minDate: new Date( 2008, 2 - 1, 4 ),
			maxDate: new Date( 2008, 2 - 1, 14 )
		} );
		inp.val( "02/10/2008" );

		testHelper.onFocus( inp, function() {
			header = dp.children().first();
			assert.ok( header.is( "div.ui-datepicker-header" ), "Structure hide prev/next - header division" );
			assert.equal( header.children().length, 1, "Structure hide prev/next - links child count" );
			assert.ok( header.children().first().is( "div.ui-datepicker-title" ), "Structure hide prev/next - title division" );

			inp.datepicker( "hide" ).datepicker( "destroy" );
			step3();
		} );
	}

	// Changeable Month with read-only year
	function step3() {
		inp = testHelper.initNewInput( { changeMonth: true } );

		testHelper.onFocus( inp, function() {
			title = dp.children().first().children().last();
			assert.equal( title.children().length, 2, "Structure changeable month - title child count" );
			assert.ok( title.children().first().is( "select.ui-datepicker-month" ), "Structure changeable month - month selector" );
			assert.ok( title.children().last().is( "span.ui-datepicker-year" ), "Structure changeable month - read-only year" );

			inp.datepicker( "hide" ).datepicker( "destroy" );
			step4();
		} );
	}

	// Changeable year with read-only month
	function step4() {
		inp = testHelper.initNewInput( { changeYear: true } );

		testHelper.onFocus( inp, function() {
			title = dp.children().first().children().last();
			assert.equal( title.children().length, 2, "Structure changeable year - title child count" );
			assert.ok( title.children().first().is( "span.ui-datepicker-month" ), "Structure changeable year - read-only month" );
			assert.ok( title.children().last().is( "select.ui-datepicker-year" ), "Structure changeable year - year selector" );

			inp.datepicker( "hide" ).datepicker( "destroy" );
			step5();
		} );
	}

	// Read-only first day of week
	function step5() {
		inp = testHelper.initNewInput( { changeFirstDay: false } );

		testHelper.onFocus( inp, function() {
			thead = dp.find( ".ui-datepicker-calendar thead tr" );
			assert.equal( thead.children().length, 7, "Structure read-only first day - thead child count" );
			assert.equal( thead.find( "a" ).length, 0, "Structure read-only first day - thead links count" );

			inp.datepicker( "hide" ).datepicker( "destroy" );
			ready();
		} );
	}

	setTimeout( step1 );
} );

QUnit.test( "keystrokes", function( assert ) {
	assert.expect( 26 );
	var inp = testHelper.init( "#inp" ),
		date = new Date();
	inp.val( "" ).datepicker( "show" ).
		simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
	testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Keystroke enter" );
	inp.val( "02/04/2008" ).datepicker( "show" ).
		simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
	testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2008, 2 - 1, 4 ),
		"Keystroke enter - preset" );
	inp.val( "02/04/2008" ).datepicker( "show" ).
		simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.HOME } ).
		simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
	testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Keystroke ctrl+home" );
	inp.val( "02/04/2008" ).datepicker( "show" ).
		simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.END } );
	assert.ok( inp.datepicker( "getDate" ) == null, "Keystroke ctrl+end" );
	inp.val( "" ).datepicker( "show" ).
		simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
	assert.ok( inp.datepicker( "getDate" ) == null, "Keystroke esc" );
	inp.val( "02/04/2008" ).datepicker( "show" ).
		simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
	testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2008, 2 - 1, 4 ),
		"Keystroke esc - preset" );
	inp.val( "02/04/2008" ).datepicker( "show" ).
		simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP } ).
		simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
	testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2008, 2 - 1, 4 ),
		"Keystroke esc - abandoned" );

	// Moving by day or week
	inp.val( "" ).datepicker( "show" ).
		simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.LEFT } ).
		simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
	date.setDate( date.getDate() - 1 );
	testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Keystroke ctrl+left" );
	inp.val( "" ).datepicker( "show" ).
		simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ).
		simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
	date.setDate( date.getDate() + 1 );
	testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Keystroke left" );
	inp.val( "" ).datepicker( "show" ).
		simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.RIGHT } ).
		simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
	date.setDate( date.getDate() + 1 );
	testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Keystroke ctrl+right" );
	inp.val( "" ).datepicker( "show" ).
		simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } ).
		simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
	date.setDate( date.getDate() - 1 );
	testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Keystroke right" );
	inp.val( "" ).datepicker( "show" ).
		simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.UP } ).
		simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
	date.setDate( date.getDate() - 7 );
	testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Keystroke ctrl+up" );
	inp.val( "" ).datepicker( "show" ).
		simulate( "keydown", { keyCode: $.ui.keyCode.UP } ).
		simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
	date.setDate( date.getDate() + 7 );
	testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Keystroke up" );
	inp.val( "" ).datepicker( "show" ).
		simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.DOWN } ).
		simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
	date.setDate( date.getDate() + 7 );
	testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Keystroke ctrl+down" );
	inp.val( "" ).datepicker( "show" ).
		simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ).
		simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
	date.setDate( date.getDate() - 7 );
	testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Keystroke down" );

	// Moving by month or year
	inp.val( "02/04/2008" ).datepicker( "show" ).
		simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ).
		simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
	testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2008, 1 - 1, 4 ),
		"Keystroke pgup" );
	inp.val( "02/04/2008" ).datepicker( "show" ).
		simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ).
		simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
	testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2008, 3 - 1, 4 ),
		"Keystroke pgdn" );
	inp.val( "02/04/2008" ).datepicker( "show" ).
		simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP } ).
		simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
	testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2007, 2 - 1, 4 ),
		"Keystroke ctrl+pgup" );
	inp.val( "02/04/2008" ).datepicker( "show" ).
		simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN } ).
		simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
	testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2009, 2 - 1, 4 ),
		"Keystroke ctrl+pgdn" );

	// Check for moving to short months
	inp.val( "03/31/2008" ).datepicker( "show" ).
		simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ).
		simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
	testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2008, 2 - 1, 29 ),
		"Keystroke pgup - Feb" );
	inp.val( "01/30/2008" ).datepicker( "show" ).
		simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ).
		simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
	testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2008, 2 - 1, 29 ),
		"Keystroke pgdn - Feb" );
	inp.val( "02/29/2008" ).datepicker( "show" ).
		simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP } ).
		simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
	testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2007, 2 - 1, 28 ),
		"Keystroke ctrl+pgup - Feb" );
	inp.val( "02/29/2008" ).datepicker( "show" ).
		simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN } ).
		simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
	testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2009, 2 - 1, 28 ),
		"Keystroke ctrl+pgdn - Feb" );

	// Goto current
	inp.datepicker( "option", { gotoCurrent: true } ).
		datepicker( "hide" ).val( "02/04/2008" ).datepicker( "show" ).
		simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ).
		simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.HOME } ).
		simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
	testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2008, 2 - 1, 4 ),
		"Keystroke ctrl+home" );

	// Change steps
	inp.datepicker( "option", { stepMonths: 2, gotoCurrent: false } ).
		datepicker( "hide" ).val( "02/04/2008" ).datepicker( "show" ).
		simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ).
		simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
	testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2007, 12 - 1, 4 ),
		"Keystroke pgup step 2" );
	inp.val( "02/04/2008" ).datepicker( "show" ).
		simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ).
		simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
	testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2008, 4 - 1, 4 ),
		"Keystroke pgdn step 2" );
} );

QUnit.test( "mouse", function( assert ) {
	assert.expect( 15 );
	var inl,
		inp = testHelper.init( "#inp" ),
		dp = $( "#ui-datepicker-div" ),
		date = new Date();
	inp.val( "" ).datepicker( "show" );
	$( ".ui-datepicker-calendar tbody a:contains(10)", dp ).simulate( "click", {} );
	date.setDate( 10 );
	testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Mouse click" );
	inp.val( "02/04/2008" ).datepicker( "show" );
	$( ".ui-datepicker-calendar tbody a:contains(12)", dp ).simulate( "click", {} );
	testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2008, 2 - 1, 12 ),
		"Mouse click - preset" );
	inp.val( "02/04/2008" ).datepicker( "show" );
	inp.val( "" ).datepicker( "show" );
	$( "button.ui-datepicker-close", dp ).simulate( "click", {} );
	assert.ok( inp.datepicker( "getDate" ) == null, "Mouse click - close" );
	inp.val( "02/04/2008" ).datepicker( "show" );
	$( "button.ui-datepicker-close", dp ).simulate( "click", {} );
	testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2008, 2 - 1, 4 ),
		"Mouse click - close + preset" );
	inp.val( "02/04/2008" ).datepicker( "show" );
	$( "a.ui-datepicker-prev", dp ).simulate( "click", {} );
	$( "button.ui-datepicker-close", dp ).simulate( "click", {} );
	testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2008, 2 - 1, 4 ),
		"Mouse click - abandoned" );

	// Current/previous/next
	inp.val( "02/04/2008" ).datepicker( "option", { showButtonPanel: true } ).datepicker( "show" );
	$( ".ui-datepicker-current", dp ).simulate( "click", {} );
	$( ".ui-datepicker-calendar tbody a:contains(14)", dp ).simulate( "click", {} );
	date.setDate( 14 );
	testHelper.equalsDate( assert, inp.datepicker( "getDate" ), date, "Mouse click - current" );
	inp.val( "02/04/2008" ).datepicker( "show" );
	$( ".ui-datepicker-prev", dp ).simulate( "click" );
	$( ".ui-datepicker-calendar tbody a:contains(16)", dp ).simulate( "click" );
	testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2008, 1 - 1, 16 ),
		"Mouse click - previous" );
	inp.val( "02/04/2008" ).datepicker( "show" );
	$( ".ui-datepicker-next", dp ).simulate( "click" );
	$( ".ui-datepicker-calendar tbody a:contains(18)", dp ).simulate( "click" );
	testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2008, 3 - 1, 18 ),
		"Mouse click - next" );

	// Previous/next with minimum/maximum
	inp.datepicker( "option", { minDate: new Date( 2008, 2 - 1, 2 ),
		maxDate: new Date( 2008, 2 - 1, 26 ) } ).val( "02/04/2008" ).datepicker( "show" );
	$( ".ui-datepicker-prev", dp ).simulate( "click" );
	$( ".ui-datepicker-calendar tbody a:contains(16)", dp ).simulate( "click" );
	testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2008, 2 - 1, 16 ),
		"Mouse click - previous + min/max" );
	inp.val( "02/04/2008" ).datepicker( "show" );
	$( ".ui-datepicker-next", dp ).simulate( "click" );
	$( ".ui-datepicker-calendar tbody a:contains(18)", dp ).simulate( "click" );
	testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2008, 2 - 1, 18 ),
		"Mouse click - next + min/max" );

	// Inline
	inl = testHelper.init( "#inl" );
	dp = $( ".ui-datepicker-inline", inl );
	date = new Date();
	inl.datepicker( "setDate", date );
	$( ".ui-datepicker-calendar tbody a:contains(10)", dp ).simulate( "click", {} );
	date.setDate( 10 );
	testHelper.equalsDate( assert, inl.datepicker( "getDate" ), date, "Mouse click inline" );
	inl.datepicker( "option", { showButtonPanel: true } ).datepicker( "setDate", new Date( 2008, 2 - 1, 4 ) );
	$( ".ui-datepicker-calendar tbody a:contains(12)", dp ).simulate( "click", {} );
	testHelper.equalsDate( assert, inl.datepicker( "getDate" ), new Date( 2008, 2 - 1, 12 ), "Mouse click inline - preset" );
	inl.datepicker( "option", { showButtonPanel: true } );
	$( ".ui-datepicker-current", dp ).simulate( "click", {} );
	$( ".ui-datepicker-calendar tbody a:contains(14)", dp ).simulate( "click", {} );
	date.setDate( 14 );
	testHelper.equalsDate( assert, inl.datepicker( "getDate" ), date, "Mouse click inline - current" );
	inl.datepicker( "setDate", new Date( 2008, 2 - 1, 4 ) );
	$( ".ui-datepicker-prev", dp ).simulate( "click" );
	$( ".ui-datepicker-calendar tbody a:contains(16)", dp ).simulate( "click" );
	testHelper.equalsDate( assert, inl.datepicker( "getDate" ), new Date( 2008, 1 - 1, 16 ),
		"Mouse click inline - previous" );
	inl.datepicker( "setDate", new Date( 2008, 2 - 1, 4 ) );
	$( ".ui-datepicker-next", dp ).simulate( "click" );
	$( ".ui-datepicker-calendar tbody a:contains(18)", dp ).simulate( "click" );
	testHelper.equalsDate( assert, inl.datepicker( "getDate" ), new Date( 2008, 3 - 1, 18 ),
		"Mouse click inline - next" );
} );

} );