2013-11-20 13:53:02 +00:00
|
|
|
(function( $ ) {
|
2009-02-04 04:27:14 +00:00
|
|
|
|
2013-11-20 13:53:02 +00:00
|
|
|
module( "datepicker: core" );
|
2009-02-02 14:36:08 +00:00
|
|
|
|
2012-12-06 16:56:56 +00:00
|
|
|
TestHelpers.testJshint( "datepicker" );
|
|
|
|
|
2013-11-20 13:53:02 +00:00
|
|
|
test( "input's value determines starting date", function() {
|
|
|
|
expect( 3 );
|
|
|
|
|
2013-11-30 12:22:17 +00:00
|
|
|
var input = $( "#datepicker" ).val( "1/1/14" ).datepicker(),
|
2013-11-20 13:53:02 +00:00
|
|
|
picker = input.datepicker( "widget" );
|
|
|
|
|
|
|
|
input.datepicker( "open" );
|
|
|
|
|
|
|
|
equal( picker.find( ".ui-datepicker-month" ).html(), "January", "correct month displayed" );
|
|
|
|
equal( picker.find( ".ui-datepicker-year" ).html(), "2014", "correct year displayed" );
|
|
|
|
equal( picker.find( ".ui-state-focus" ).html(), "1", "correct day highlighted" );
|
|
|
|
|
|
|
|
input.val( "" ).datepicker( "destroy" );
|
|
|
|
});
|
|
|
|
|
2013-04-14 21:07:24 +00:00
|
|
|
asyncTest( "baseStructure", function() {
|
2013-11-02 13:54:05 +00:00
|
|
|
expect( 42 );
|
2012-04-19 15:17:35 +00:00
|
|
|
var header, title, table, thead, week, panel, inl, child,
|
2013-04-14 21:07:24 +00:00
|
|
|
inp = TestHelpers.datepicker.initNewInput(),
|
2013-11-02 13:54:05 +00:00
|
|
|
dp = inp.datepicker( "widget" ).find( ".ui-datepicker" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2012-12-11 15:06:13 +00:00
|
|
|
function step1() {
|
2013-11-02 13:54:05 +00:00
|
|
|
inp.focus();
|
|
|
|
setTimeout(function() {
|
2013-04-14 21:07:24 +00:00
|
|
|
ok( dp.is( ":visible" ), "Structure - datepicker visible" );
|
|
|
|
ok( !dp.is( ".ui-datepicker-rtl" ), "Structure - not right-to-left" );
|
|
|
|
ok( !dp.is( ".ui-datepicker-multi" ), "Structure - not multi-month" );
|
2013-11-02 13:54:05 +00:00
|
|
|
equal( dp.children().length, 3, "Structure - child count (header, calendar, buttonpane)" );
|
2012-12-11 15:06:13 +00:00
|
|
|
|
2013-04-14 21:07:24 +00:00
|
|
|
header = dp.children( ":first" );
|
|
|
|
ok( header.is( "div.ui-datepicker-header" ), "Structure - header division" );
|
|
|
|
equal( header.children().length, 3, "Structure - header child count" );
|
2013-11-02 13:54:05 +00:00
|
|
|
ok( header.children( ":first" ).is( ".ui-datepicker-prev" ) && header.children( ":first" ).html() !== "", "Structure - prev link" );
|
|
|
|
ok( header.children( ":eq(1)" ).is( ".ui-datepicker-next" ) && header.children( ":eq(1)" ).html() !== "", "Structure - next link" );
|
2013-04-14 21:07:24 +00:00
|
|
|
|
2013-11-02 13:54:05 +00:00
|
|
|
title = header.children( ":last" ).children( ":first" );
|
2013-04-14 21:07:24 +00:00
|
|
|
ok( title.is( "div.ui-datepicker-title" ) && title.html() !== "","Structure - title division" );
|
|
|
|
equal( title.children().length, 2, "Structure - title child count" );
|
|
|
|
ok( title.children( ":first" ).is( "span.ui-datepicker-month" ) && title.children( ":first" ).text() !== "", "Structure - month text" );
|
|
|
|
ok( title.children( ":last" ).is( "span.ui-datepicker-year" ) && title.children( ":last" ).text() !== "", "Structure - year text" );
|
|
|
|
|
|
|
|
table = dp.children( ":eq(1)" );
|
|
|
|
ok( table.is( "table.ui-datepicker-calendar" ), "Structure - month table" );
|
|
|
|
ok( table.children( ":first" ).is( "thead" ), "Structure - month table thead" );
|
|
|
|
|
|
|
|
thead = table.children( ":first" ).children( ":first" );
|
|
|
|
ok( thead.is( "tr" ), "Structure - month table title row" );
|
|
|
|
equal( thead.find( "th" ).length, 7, "Structure - month table title cells" );
|
|
|
|
ok( table.children( ":eq(1)" ).is( "tbody" ), "Structure - month table body" );
|
|
|
|
ok( table.children( ":eq(1)" ).children( "tr" ).length >= 4, "Structure - month table week count" );
|
|
|
|
|
|
|
|
week = table.children( ":eq(1)" ).children( ":first" );
|
|
|
|
ok( week.is( "tr" ), "Structure - month table week row" );
|
|
|
|
equal( week.children().length, 7, "Structure - week child count" );
|
2013-11-02 13:54:05 +00:00
|
|
|
// TODO: Preserve these class names or let the user use :first-child and :last-child?
|
|
|
|
// ok( week.children( ":first" ).is( "td.ui-datepicker-week-end" ), "Structure - month table first day cell" );
|
|
|
|
// ok( week.children( ":last" ).is( "td.ui-datepicker-week-end" ), "Structure - month table second day cell" );
|
2013-04-14 21:07:24 +00:00
|
|
|
|
2013-11-02 13:54:05 +00:00
|
|
|
inp.datepicker( "close" ).datepicker( "destroy" );
|
2012-12-11 15:06:13 +00:00
|
|
|
step2();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function step2() {
|
|
|
|
// Editable month/year and button panel
|
2013-04-14 21:07:24 +00:00
|
|
|
inp = TestHelpers.datepicker.initNewInput({
|
|
|
|
changeMonth: true,
|
|
|
|
changeYear: true,
|
|
|
|
showButtonPanel: true
|
|
|
|
});
|
2013-11-02 13:54:05 +00:00
|
|
|
dp = inp.datepicker( "widget" ).find( ".ui-datepicker" );
|
|
|
|
inp.focus();
|
|
|
|
setTimeout(function() {
|
2013-04-14 21:07:24 +00:00
|
|
|
title = dp.find( "div.ui-datepicker-title" );
|
2013-11-02 13:54:05 +00:00
|
|
|
// TODO: Re-add tests when changeMonth and changeYear are re-implemented
|
|
|
|
//ok( title.children( ":first" ).is( "select.ui-datepicker-month" ), "Structure - month selector" );
|
|
|
|
//ok( title.children( ":last" ).is( "select.ui-datepicker-year" ), "Structure - year selector" );
|
2012-12-11 15:06:13 +00:00
|
|
|
|
2013-04-14 21:07:24 +00:00
|
|
|
panel = dp.children( ":last" );
|
|
|
|
ok( panel.is( "div.ui-datepicker-buttonpane" ), "Structure - button panel division" );
|
|
|
|
equal( panel.children().length, 2, "Structure - button panel child count" );
|
|
|
|
ok( panel.children( ":first" ).is( "button.ui-datepicker-current" ), "Structure - today button" );
|
|
|
|
ok( panel.children( ":last" ).is( "button.ui-datepicker-close" ), "Structure - close button" );
|
|
|
|
|
2013-11-02 13:54:05 +00:00
|
|
|
inp.datepicker( "close" ).datepicker( "destroy" );
|
2012-12-11 15:06:13 +00:00
|
|
|
step3();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function step3() {
|
|
|
|
// Multi-month 2
|
2013-04-14 21:07:24 +00:00
|
|
|
inp = TestHelpers.datepicker.initNewInput({ numberOfMonths: 2 });
|
2013-11-02 13:54:05 +00:00
|
|
|
dp = inp.datepicker( "widget" ).find( ".ui-datepicker" );
|
|
|
|
inp.focus();
|
|
|
|
setTimeout(function() {
|
2013-04-14 21:07:24 +00:00
|
|
|
ok( dp.is( ".ui-datepicker-multi" ), "Structure multi [2] - multi-month" );
|
2013-11-02 13:54:05 +00:00
|
|
|
equal( dp.children().length, 4, "Structure multi [2] - child count" );
|
2013-04-14 21:07:24 +00:00
|
|
|
|
|
|
|
child = dp.children( ":first" );
|
2013-11-02 13:54:05 +00:00
|
|
|
// TODO: Implement ui-datepicker-group-first class name
|
|
|
|
// ok( child.is( "div.ui-datepicker-group" ) && child.is( "div.ui-datepicker-group-first" ), "Structure multi [2] - first month division" );
|
2012-12-11 15:06:13 +00:00
|
|
|
|
2013-04-14 21:07:24 +00:00
|
|
|
child = dp.children( ":eq(1)" );
|
2013-11-02 13:54:05 +00:00
|
|
|
// TODO: Implement ui-datepicker-group-last class name
|
|
|
|
// ok( child.is( "div.ui-datepicker-group" ) && child.is( "div.ui-datepicker-group-last" ), "Structure multi [2] - second month division" );
|
2013-04-14 21:07:24 +00:00
|
|
|
|
|
|
|
child = dp.children( ":eq(2)" );
|
|
|
|
ok( child.is( "div.ui-datepicker-row-break" ), "Structure multi [2] - row break" );
|
|
|
|
ok( dp.is( ".ui-datepicker-multi-2" ), "Structure multi [2] - multi-2" );
|
|
|
|
|
2013-11-02 13:54:05 +00:00
|
|
|
inp.datepicker( "close" ).datepicker( "destroy" );
|
2012-12-11 15:06:13 +00:00
|
|
|
step4();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function step4() {
|
|
|
|
// Multi-month 3
|
2013-04-14 21:07:24 +00:00
|
|
|
inp = TestHelpers.datepicker.initNewInput({ numberOfMonths: 3 });
|
2013-11-02 13:54:05 +00:00
|
|
|
dp = inp.datepicker( "widget" ).find( ".ui-datepicker" );
|
|
|
|
inp.focus();
|
|
|
|
setTimeout(function() {
|
2013-04-14 21:07:24 +00:00
|
|
|
ok( dp.is( ".ui-datepicker-multi-3" ), "Structure multi [3] - multi-3" );
|
|
|
|
ok( !dp.is( ".ui-datepicker-multi-2" ), "Structure multi [3] - Trac #6704" );
|
2012-12-11 15:06:13 +00:00
|
|
|
|
2013-11-02 13:54:05 +00:00
|
|
|
inp.datepicker( "close" ).datepicker( "destroy" );
|
2012-12-11 15:06:13 +00:00
|
|
|
step5();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function step5() {
|
|
|
|
// Multi-month [2, 2]
|
2013-04-14 21:07:24 +00:00
|
|
|
inp = TestHelpers.datepicker.initNewInput({ numberOfMonths: [ 2, 2 ] });
|
2013-11-02 13:54:05 +00:00
|
|
|
dp = inp.datepicker( "widget" ).find( ".ui-datepicker" );
|
|
|
|
inp.focus();
|
|
|
|
setTimeout(function() {
|
|
|
|
/*
|
|
|
|
TODO: Re-add after array form of the numberOfMonths option is implemented.
|
2013-04-14 21:07:24 +00:00
|
|
|
ok( dp.is( ".ui-datepicker-multi" ), "Structure multi - multi-month" );
|
|
|
|
equal( dp.children().length, 6, "Structure multi [2,2] - child count" );
|
|
|
|
|
|
|
|
child = dp.children( ":first" );
|
|
|
|
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)" );
|
|
|
|
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)" );
|
|
|
|
ok( child.is( "div.ui-datepicker-row-break" ), "Structure multi [2,2] - row break" );
|
|
|
|
|
|
|
|
child = dp.children( ":eq(3)" );
|
|
|
|
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)" );
|
|
|
|
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)" );
|
|
|
|
ok( child.is( "div.ui-datepicker-row-break" ), "Structure multi [2,2] - row break" );
|
2013-11-02 13:54:05 +00:00
|
|
|
*/
|
|
|
|
inp.datepicker( "close" ).datepicker( "destroy" );
|
|
|
|
step6();
|
2012-12-11 15:06:13 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-11-02 13:54:05 +00:00
|
|
|
function step6() {
|
|
|
|
// Inline
|
|
|
|
inl = TestHelpers.datepicker.init( "#inline" );
|
|
|
|
dp = inl.children();
|
2009-02-04 04:27:14 +00:00
|
|
|
|
2013-11-02 13:54:05 +00:00
|
|
|
ok( dp.is( ".ui-datepicker-inline" ), "Structure inline - main div" );
|
|
|
|
ok( !dp.is( ".ui-datepicker-rtl" ), "Structure inline - not right-to-left" );
|
|
|
|
ok( !dp.is( ".ui-datepicker-multi" ), "Structure inline - not multi-month" );
|
|
|
|
equal( dp.children().length, 3, "Structure inline - child count (header, calendar, buttonpane)" );
|
2013-04-14 21:07:24 +00:00
|
|
|
|
2013-11-02 13:54:05 +00:00
|
|
|
header = dp.children( ":first" );
|
|
|
|
ok( header.is( "div.ui-datepicker-header" ), "Structure inline - header division" );
|
|
|
|
equal( header.children().length, 3, "Structure inline - header child count" );
|
2013-04-14 21:07:24 +00:00
|
|
|
|
2013-11-02 13:54:05 +00:00
|
|
|
table = dp.children( ":eq(1)" );
|
|
|
|
ok( table.is( "table.ui-datepicker-calendar" ), "Structure inline - month table" );
|
|
|
|
ok( table.children( ":first" ).is( "thead" ), "Structure inline - month table thead" );
|
|
|
|
ok( table.children( ":eq(1)" ).is( "tbody" ), "Structure inline - month table body" );
|
2013-04-14 21:07:24 +00:00
|
|
|
|
2013-11-02 13:54:05 +00:00
|
|
|
inl.datepicker( "destroy" );
|
2013-04-14 21:07:24 +00:00
|
|
|
|
2013-11-02 13:54:05 +00:00
|
|
|
step7();
|
2013-04-14 21:07:24 +00:00
|
|
|
}
|
2009-02-04 04:27:14 +00:00
|
|
|
|
2013-11-02 13:54:05 +00:00
|
|
|
function step7() {
|
|
|
|
// Inline multi-month
|
|
|
|
inl = TestHelpers.datepicker.init( "#inline", { numberOfMonths: 2 } );
|
|
|
|
dp = inl.datepicker( "widget" ).find( ".ui-datepicker" );
|
2013-04-14 21:07:24 +00:00
|
|
|
|
2013-11-02 13:54:05 +00:00
|
|
|
ok( dp.is( ".ui-datepicker-inline" ) && dp.is( ".ui-datepicker-multi" ), "Structure inline multi - main div" );
|
|
|
|
equal( dp.children().length, 4, "Structure inline multi - child count" );
|
2013-04-14 21:07:24 +00:00
|
|
|
|
2013-11-02 13:54:05 +00:00
|
|
|
child = dp.children( ":first" );
|
|
|
|
// TODO: Implement ui-datepicker-group-first class name
|
|
|
|
// ok( child.is( "div.ui-datepicker-group" ) && child.is( "div.ui-datepicker-group-first" ), "Structure inline multi - first month division" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2013-11-02 13:54:05 +00:00
|
|
|
child = dp.children( ":eq(1)" );
|
|
|
|
// TODO: Implement ui-datepicker-group-last class name
|
|
|
|
// ok( child.is( "div.ui-datepicker-group" ) && child.is( "div.ui-datepicker-group-last" ), "Structure inline multi - second month division" );
|
2013-04-14 21:07:24 +00:00
|
|
|
|
2013-11-02 13:54:05 +00:00
|
|
|
child = dp.children( ":eq(2)" );
|
|
|
|
ok( child.is( "div.ui-datepicker-row-break" ), "Structure inline multi - row break" );
|
2013-04-14 21:07:24 +00:00
|
|
|
|
2013-11-02 13:54:05 +00:00
|
|
|
inl.datepicker( "destroy" );
|
|
|
|
start();
|
2013-04-14 21:07:24 +00:00
|
|
|
}
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2013-11-02 13:54:05 +00:00
|
|
|
step1();
|
|
|
|
});
|
2013-04-14 21:07:24 +00:00
|
|
|
|
2013-11-02 13:54:05 +00:00
|
|
|
test( "Keyboard handling", function() {
|
2014-01-03 14:55:06 +00:00
|
|
|
expect( 9 );
|
2013-11-22 14:30:11 +00:00
|
|
|
var input = $( "#datepicker" ).datepicker(),
|
|
|
|
instance = input.datepicker( "instance" ),
|
2013-11-02 13:54:05 +00:00
|
|
|
date = new Date();
|
2009-02-04 04:27:14 +00:00
|
|
|
|
2013-11-22 14:30:11 +00:00
|
|
|
input.datepicker( "open" )
|
2013-11-02 13:54:05 +00:00
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER });
|
2013-11-22 14:30:11 +00:00
|
|
|
TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), date, "Keystroke enter" );
|
2013-04-14 21:07:24 +00:00
|
|
|
|
2013-11-22 14:30:11 +00:00
|
|
|
// Enter = Select today's date by default
|
2013-11-30 12:22:17 +00:00
|
|
|
input.val( "1/1/14" ).datepicker( "open" )
|
2013-11-02 13:54:05 +00:00
|
|
|
.simulate("keydown", { keyCode: $.ui.keyCode.ENTER });
|
2013-11-22 14:30:11 +00:00
|
|
|
TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), new Date( 2014, 0, 1 ),
|
2013-11-02 13:54:05 +00:00
|
|
|
"Keystroke enter - preset" );
|
2013-04-14 21:07:24 +00:00
|
|
|
|
2013-11-22 14:30:11 +00:00
|
|
|
// Control + Home = Change the calendar to the current month
|
2013-11-30 12:22:17 +00:00
|
|
|
input.val( "1/1/14" ).datepicker( "open" )
|
2013-11-02 13:54:05 +00:00
|
|
|
.simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.HOME })
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER });
|
2013-11-22 14:30:11 +00:00
|
|
|
TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), date, "Keystroke ctrl+home" );
|
2013-04-14 21:07:24 +00:00
|
|
|
|
2013-11-22 14:30:11 +00:00
|
|
|
// Control + End = Close the calendar and clear the input
|
2013-11-30 12:22:17 +00:00
|
|
|
input.val( "1/1/14" ).datepicker( "open" )
|
2013-11-02 13:54:05 +00:00
|
|
|
.simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.END });
|
2013-11-22 14:30:11 +00:00
|
|
|
equal( input.val(), "", "Keystroke ctrl+end" );
|
2009-02-04 04:27:14 +00:00
|
|
|
|
2013-11-22 14:30:11 +00:00
|
|
|
input.val( "" ).datepicker( "open" );
|
|
|
|
ok( instance.isOpen, "datepicker is open before escape" );
|
|
|
|
input.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE });
|
|
|
|
ok( !instance.isOpen, "escape closes the datepicker" );
|
2013-11-02 13:54:05 +00:00
|
|
|
|
2013-11-30 12:22:17 +00:00
|
|
|
input.val( "1/1/14" ).datepicker( "open" )
|
2013-11-02 13:54:05 +00:00
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE });
|
2013-11-22 14:30:11 +00:00
|
|
|
TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), new Date( 2014, 0, 1 ),
|
2013-11-02 13:54:05 +00:00
|
|
|
"Keystroke esc - preset" );
|
|
|
|
|
2013-11-30 12:22:17 +00:00
|
|
|
input.val( "1/1/14" ).datepicker( "open" )
|
2013-11-02 13:54:05 +00:00
|
|
|
.simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP })
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE });
|
2013-11-22 14:30:11 +00:00
|
|
|
TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), new Date( 2014, 0, 1 ),
|
2013-11-02 13:54:05 +00:00
|
|
|
"Keystroke esc - abandoned" );
|
|
|
|
|
2014-01-03 14:55:06 +00:00
|
|
|
input.val( "1/2/14" )
|
|
|
|
.simulate( "keyup" );
|
|
|
|
TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), new Date( 2014, 0, 2 ),
|
|
|
|
"Picker updated as user types into input" );
|
|
|
|
|
2013-11-22 14:30:11 +00:00
|
|
|
input.datepicker( "destroy" );
|
|
|
|
});
|
|
|
|
|
2013-12-27 13:28:00 +00:00
|
|
|
asyncTest( "keyboard handling", function() {
|
|
|
|
expect( 14 );
|
2013-11-22 14:30:11 +00:00
|
|
|
var picker,
|
|
|
|
input = $( "#datepicker" ),
|
|
|
|
date = new Date();
|
|
|
|
|
|
|
|
function step1() {
|
|
|
|
input.datepicker();
|
|
|
|
picker = input.datepicker( "widget" );
|
|
|
|
ok( !picker.is( ":visible" ), "datepicker closed" );
|
|
|
|
input.val( "" )
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN });
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
ok( picker.is( ":visible" ), "Keystroke down opens datepicker" );
|
|
|
|
input.datepicker( "destroy" );
|
|
|
|
step2();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
function step2() {
|
|
|
|
input.datepicker();
|
|
|
|
picker = input.datepicker( "widget" )
|
|
|
|
ok( !picker.is( ":visible" ), "datepicker closed" );
|
|
|
|
input.val( "" )
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.UP });
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
ok( picker.is( ":visible" ), "Keystroke up opens datepicker" );
|
|
|
|
input.datepicker( "destroy" );
|
|
|
|
step3();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
function step3() {
|
|
|
|
input.datepicker()
|
2013-12-27 13:28:00 +00:00
|
|
|
.val( "1/1/14" )
|
2013-11-22 14:30:11 +00:00
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN });
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
$( ":focus" )
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT })
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER });
|
2013-12-27 13:28:00 +00:00
|
|
|
date = new Date( 2013, 12 - 1, 31 );
|
2013-11-22 14:30:11 +00:00
|
|
|
TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), date,
|
|
|
|
"Keystroke left to switch to previous day" );
|
|
|
|
|
|
|
|
input.datepicker( "destroy" );
|
|
|
|
step4();
|
2013-12-27 13:28:00 +00:00
|
|
|
}, 100 );
|
2013-11-22 14:30:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function step4() {
|
|
|
|
input.datepicker()
|
2013-12-27 13:28:00 +00:00
|
|
|
.val( "1/1/14" )
|
2013-11-22 14:30:11 +00:00
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN });
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
$( ":focus" )
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT })
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER });
|
2013-12-27 13:28:00 +00:00
|
|
|
date = new Date( 2014, 1 - 1, 2 );
|
2013-11-22 14:30:11 +00:00
|
|
|
TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), date,
|
|
|
|
"Keystroke right to switch to next day" );
|
|
|
|
|
|
|
|
input.datepicker( "destroy" );
|
2013-12-27 13:28:00 +00:00
|
|
|
step5();
|
|
|
|
}, 100 );
|
2013-11-22 14:30:11 +00:00
|
|
|
};
|
|
|
|
|
2013-12-27 13:28:00 +00:00
|
|
|
function step5() {
|
|
|
|
input.datepicker()
|
|
|
|
.val( "1/1/14" )
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN });
|
2013-11-22 14:30:11 +00:00
|
|
|
|
2013-12-27 13:28:00 +00:00
|
|
|
setTimeout(function() {
|
|
|
|
$( ":focus" )
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.UP })
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER });
|
|
|
|
date = new Date( 2013, 12 - 1, 25 );
|
|
|
|
TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), date,
|
|
|
|
"Keystroke up to move to the previous week" );
|
2013-11-02 13:54:05 +00:00
|
|
|
|
2013-12-27 13:28:00 +00:00
|
|
|
input.datepicker( "destroy" );
|
|
|
|
step6();
|
|
|
|
}, 100 );
|
|
|
|
};
|
2013-11-02 13:54:05 +00:00
|
|
|
|
2013-12-27 13:28:00 +00:00
|
|
|
function step6() {
|
|
|
|
input.datepicker()
|
|
|
|
.val( "1/1/14" )
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN });
|
2013-11-02 13:54:05 +00:00
|
|
|
|
2013-12-27 13:28:00 +00:00
|
|
|
setTimeout(function() {
|
|
|
|
$( ":focus" )
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN })
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER });
|
|
|
|
date = new Date( 2014, 1 - 1, 8 );
|
|
|
|
TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), date,
|
|
|
|
"Keystroke down to move to the next week" );
|
2013-11-02 13:54:05 +00:00
|
|
|
|
2013-12-27 13:28:00 +00:00
|
|
|
input.datepicker( "destroy" );
|
|
|
|
step7();
|
|
|
|
}, 100 );
|
|
|
|
};
|
|
|
|
|
|
|
|
function step7() {
|
|
|
|
input.datepicker()
|
|
|
|
.val( "1/1/14" )
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN });
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
$( ":focus" )
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP })
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER });
|
|
|
|
date = new Date( 2013, 12 - 1, 1 );
|
|
|
|
TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), date,
|
|
|
|
"Keystroke Page Up moves date to previous month" );
|
|
|
|
|
|
|
|
input.datepicker( "destroy" );
|
|
|
|
step8();
|
|
|
|
}, 100 );
|
|
|
|
};
|
|
|
|
|
|
|
|
function step8() {
|
|
|
|
input.datepicker()
|
|
|
|
.val( "1/1/14" )
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN });
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
$( ":focus" )
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP, altKey: true })
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER });
|
|
|
|
date = new Date( 2013, 1 - 1, 1 );
|
|
|
|
TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), date,
|
|
|
|
"Keystroke Page Up + Ctrl moves date to previous year" );
|
|
|
|
|
|
|
|
input.datepicker( "destroy" );
|
|
|
|
step9();
|
|
|
|
}, 100 );
|
|
|
|
};
|
|
|
|
|
|
|
|
function step9() {
|
|
|
|
input.datepicker()
|
|
|
|
.val( "1/1/14" )
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN });
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
$( ":focus" )
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN })
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER });
|
|
|
|
date = new Date( 2014, 2 - 1, 1 );
|
|
|
|
TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), date,
|
|
|
|
"Keystroke Page Down moves date to next month" );
|
|
|
|
|
|
|
|
input.datepicker( "destroy" );
|
|
|
|
step10();
|
|
|
|
}, 100 );
|
|
|
|
};
|
|
|
|
|
|
|
|
function step10() {
|
|
|
|
input.datepicker()
|
|
|
|
.val( "1/1/14" )
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN });
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
$( ":focus" )
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN, altKey: true })
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER });
|
|
|
|
date = new Date( 2015, 1 - 1, 1 );
|
|
|
|
TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), date,
|
|
|
|
"Keystroke Page Down + Ctrl moves date to next year" );
|
|
|
|
|
|
|
|
input.datepicker( "destroy" );
|
|
|
|
step11();
|
|
|
|
}, 100 );
|
|
|
|
};
|
2013-11-02 13:54:05 +00:00
|
|
|
|
2009-02-04 04:27:14 +00:00
|
|
|
// Check for moving to short months
|
2013-12-27 13:28:00 +00:00
|
|
|
function step11() {
|
|
|
|
input.datepicker()
|
|
|
|
.val( "3/31/14" )
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN });
|
2013-11-02 13:54:05 +00:00
|
|
|
|
2013-12-27 13:28:00 +00:00
|
|
|
setTimeout(function() {
|
|
|
|
$( ":focus" )
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP })
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER });
|
|
|
|
date = new Date( 2014, 2 - 1, 28 );
|
|
|
|
TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), date,
|
|
|
|
"Keystroke Page Up and short months" );
|
2013-11-02 13:54:05 +00:00
|
|
|
|
2013-12-27 13:28:00 +00:00
|
|
|
input.datepicker( "destroy" );
|
|
|
|
step12();
|
|
|
|
}, 100 );
|
|
|
|
};
|
2013-11-02 13:54:05 +00:00
|
|
|
|
2013-12-27 13:28:00 +00:00
|
|
|
function step12() {
|
|
|
|
input.datepicker()
|
|
|
|
.val( "1/30/16" )
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN });
|
2013-11-02 13:54:05 +00:00
|
|
|
|
2013-12-27 13:28:00 +00:00
|
|
|
setTimeout(function() {
|
|
|
|
$( ":focus" )
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN })
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER });
|
|
|
|
date = new Date( 2016, 2 - 1, 29 );
|
|
|
|
TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), date,
|
|
|
|
"Keystroke Page Down and leap years" );
|
2013-11-02 13:54:05 +00:00
|
|
|
|
2013-12-27 13:28:00 +00:00
|
|
|
input.datepicker( "destroy" );
|
|
|
|
start();
|
|
|
|
}, 100 );
|
|
|
|
};
|
|
|
|
|
|
|
|
step1();
|
|
|
|
});
|
|
|
|
|
|
|
|
/*
|
|
|
|
// TODO: Re-add tests if we implement a stepMonths option
|
2013-11-22 14:30:11 +00:00
|
|
|
input.datepicker( "option", { stepMonths: 2, gotoCurrent: false })
|
2013-11-02 13:54:05 +00:00
|
|
|
.datepicker( "close" ).val( "02/04/2008" ).datepicker( "open" )
|
|
|
|
.late( "keydown", { keyCode: $.ui.keyCode.PAGE_UP })
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER });
|
2013-11-22 14:30:11 +00:00
|
|
|
TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), new Date( 2007, 12 - 1, 4 ),
|
2013-11-02 13:54:05 +00:00
|
|
|
"Keystroke pgup step 2" );
|
|
|
|
|
2013-11-22 14:30:11 +00:00
|
|
|
input.val( "02/04/2008" ).datepicker( "open" )
|
2013-11-02 13:54:05 +00:00
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN })
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER });
|
2013-11-22 14:30:11 +00:00
|
|
|
TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), new Date( 2008, 4 - 1, 4 ),
|
2013-11-02 13:54:05 +00:00
|
|
|
"Keystroke pgdn step 2" );
|
2013-11-22 14:30:11 +00:00
|
|
|
*/
|
2009-02-04 04:27:14 +00:00
|
|
|
|
2013-11-02 13:54:05 +00:00
|
|
|
test( "mouse", function() {
|
2014-01-02 21:25:38 +00:00
|
|
|
expect( 13 );
|
|
|
|
var input = $( "#datepicker" ).datepicker(),
|
|
|
|
picker = input.datepicker( "widget" ),
|
|
|
|
inline = $( "#inline" ).datepicker,
|
2012-04-19 15:17:35 +00:00
|
|
|
date = new Date();
|
2013-11-02 13:54:05 +00:00
|
|
|
|
2014-01-02 21:25:38 +00:00
|
|
|
input.val( "" ).datepicker( "open" );
|
|
|
|
$( ".ui-datepicker-calendar tbody a:contains(10)", picker ).simulate( "mousedown", {} );
|
2013-11-02 13:54:05 +00:00
|
|
|
date.setDate( 10 );
|
2014-01-02 21:25:38 +00:00
|
|
|
TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), date, "Mouse click" );
|
2013-11-02 13:54:05 +00:00
|
|
|
|
2014-01-02 21:25:38 +00:00
|
|
|
input.val( "2/4/08" ).datepicker( "open" );
|
|
|
|
$( ".ui-datepicker-calendar tbody a:contains(12)", picker ).simulate( "mousedown", {} );
|
|
|
|
TestHelpers.datepicker.equalsDate( input.datepicker("valueAsDate"), new Date( 2008, 2 - 1, 12 ),
|
2013-11-02 13:54:05 +00:00
|
|
|
"Mouse click - preset") ;
|
|
|
|
|
2014-01-02 21:25:38 +00:00
|
|
|
input.val( "" ).datepicker( "open" );
|
|
|
|
$( "button.ui-datepicker-close", picker ).simulate( "click", {} );
|
|
|
|
ok( input.datepicker( "valueAsDate" ) == null, "Mouse click - close" );
|
|
|
|
|
|
|
|
input.val( "2/4/08" ).datepicker( "open" );
|
|
|
|
$( "button.ui-datepicker-close", picker ).simulate( "click", {} );
|
|
|
|
TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), new Date( 2008, 2 - 1, 4 ),
|
2013-11-02 13:54:05 +00:00
|
|
|
"Mouse click - close + preset" );
|
|
|
|
|
2014-01-02 21:25:38 +00:00
|
|
|
input.val( "2/4/08" ).datepicker( "open" );
|
|
|
|
$( "a.ui-datepicker-prev", picker ).simulate( "click", {} );
|
|
|
|
$( "button.ui-datepicker-close", picker ).simulate( "click", {} );
|
|
|
|
TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), new Date( 2008, 2 - 1, 4 ),
|
2013-11-02 13:54:05 +00:00
|
|
|
"Mouse click - abandoned" );
|
|
|
|
|
2009-02-04 04:27:14 +00:00
|
|
|
// Current/previous/next
|
2014-01-02 21:25:38 +00:00
|
|
|
input.val( "" ).datepicker( "open" );
|
|
|
|
$( ".ui-datepicker-current", picker ).simulate( "click", {} );
|
|
|
|
date.setDate( new Date().getDate() );
|
|
|
|
TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), date, "Mouse click - current" );
|
|
|
|
|
|
|
|
input.val( "2/4/08" ).datepicker( "open" );
|
|
|
|
$( ".ui-datepicker-prev", picker ).simulate( "click" );
|
|
|
|
$( ".ui-datepicker-calendar tbody a:contains(16)", picker ).simulate( "mousedown" );
|
|
|
|
TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), new Date( 2008, 1 - 1, 16 ),
|
2013-11-02 13:54:05 +00:00
|
|
|
"Mouse click - previous" );
|
|
|
|
|
2014-01-02 21:25:38 +00:00
|
|
|
input.val( "2/4/08" ).datepicker( "open" );
|
|
|
|
$(".ui-datepicker-next", picker ).simulate( "click" );
|
|
|
|
$(".ui-datepicker-calendar tbody a:contains(18)", picker ).simulate( "mousedown" );
|
|
|
|
TestHelpers.datepicker.equalsDate( input.datepicker("valueAsDate"), new Date( 2008, 3 - 1, 18 ),
|
2013-11-02 13:54:05 +00:00
|
|
|
"Mouse click - next" );
|
|
|
|
|
2014-01-02 21:25:38 +00:00
|
|
|
/*
|
|
|
|
// TODO: Re-add when min and max options are introduced.
|
2009-02-04 04:27:14 +00:00
|
|
|
// Previous/next with minimum/maximum
|
2014-01-02 21:25:38 +00:00
|
|
|
input.datepicker("option", {
|
2013-11-02 13:54:05 +00:00
|
|
|
minDate: new Date( 2008, 2 - 1, 2 ),
|
|
|
|
maxDate: new Date( 2008, 2 - 1, 26 )
|
2014-01-02 21:25:38 +00:00
|
|
|
}).val( "2/4/08" ).datepicker( "open" );
|
|
|
|
$( ".ui-datepicker-prev", picker ).simulate( "click" );
|
|
|
|
$( ".ui-datepicker-calendar tbody a:contains(16)", picker ).simulate( "mousedown" );
|
|
|
|
TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), new Date( 2008, 2 - 1, 16 ),
|
2013-11-02 13:54:05 +00:00
|
|
|
"Mouse click - previous + min/max" );
|
|
|
|
|
2014-01-02 21:25:38 +00:00
|
|
|
input.val( "2/4/08" ).datepicker( "open" );
|
|
|
|
$( ".ui-datepicker-next", picker ).simulate( "click" );
|
|
|
|
$( ".ui-datepicker-calendar tbody a:contains(18)", picker ).simulate( "mousedown" );
|
|
|
|
TestHelpers.datepicker.equalsDate(input.datepicker( "valueAsDate" ), new Date( 2008, 2 - 1, 18 ),
|
2013-11-02 13:54:05 +00:00
|
|
|
"Mouse click - next + min/max" );
|
2014-01-02 21:25:38 +00:00
|
|
|
*/
|
2013-11-02 13:54:05 +00:00
|
|
|
|
2009-02-04 04:27:14 +00:00
|
|
|
// Inline
|
2014-01-02 21:25:38 +00:00
|
|
|
inline = TestHelpers.datepicker.init( "#inline" );
|
|
|
|
picker = $( ".ui-datepicker-inline", inline );
|
2012-04-19 15:17:35 +00:00
|
|
|
date = new Date();
|
2014-01-02 21:25:38 +00:00
|
|
|
inline.datepicker( "valueAsDate", date );
|
|
|
|
$( ".ui-datepicker-calendar tbody a:contains(10)", picker ).simulate( "mousedown", {} );
|
2013-11-02 13:54:05 +00:00
|
|
|
date.setDate( 10 );
|
2014-01-02 21:25:38 +00:00
|
|
|
TestHelpers.datepicker.equalsDate( inline.datepicker( "valueAsDate" ), date, "Mouse click inline" );
|
2013-11-02 13:54:05 +00:00
|
|
|
|
2014-01-02 21:25:38 +00:00
|
|
|
inline.datepicker( "option", { showButtonPanel: true })
|
|
|
|
.datepicker( "valueAsDate", new Date( 2008, 2 - 1, 4 ));
|
|
|
|
$( ".ui-datepicker-calendar tbody a:contains(12)", picker ).simulate( "mousedown", {} );
|
|
|
|
TestHelpers.datepicker.equalsDate( inline.datepicker( "valueAsDate" ), new Date( 2008, 2 - 1, 12 ),
|
2013-11-02 13:54:05 +00:00
|
|
|
"Mouse click inline - preset" );
|
|
|
|
|
2014-01-02 21:25:38 +00:00
|
|
|
inline.datepicker("option", { showButtonPanel: true });
|
|
|
|
$( ".ui-datepicker-current", picker ).simulate( "click", {} );
|
|
|
|
$( ".ui-datepicker-calendar tbody a:contains(14)", picker ).simulate( "mousedown", {} );
|
2013-11-02 13:54:05 +00:00
|
|
|
date.setDate( 14 );
|
2014-01-02 21:25:38 +00:00
|
|
|
TestHelpers.datepicker.equalsDate( inline.datepicker( "valueAsDate" ), date, "Mouse click inline - current" );
|
2013-11-02 13:54:05 +00:00
|
|
|
|
2014-01-02 21:25:38 +00:00
|
|
|
inline.datepicker( "valueAsDate", new Date( 2008, 2 - 1, 4) );
|
|
|
|
$( ".ui-datepicker-prev", picker ).simulate( "click" );
|
|
|
|
$( ".ui-datepicker-calendar tbody a:contains(16)", picker ).simulate( "mousedown" );
|
|
|
|
TestHelpers.datepicker.equalsDate( inline.datepicker( "valueAsDate" ), new Date( 2008, 1 - 1, 16 ),
|
2013-11-02 13:54:05 +00:00
|
|
|
"Mouse click inline - previous" );
|
|
|
|
|
2014-01-02 21:25:38 +00:00
|
|
|
inline.datepicker( "valueAsDate", new Date( 2008, 2 - 1, 4) );
|
|
|
|
$( ".ui-datepicker-next", picker ).simulate( "click" );
|
|
|
|
$( ".ui-datepicker-calendar tbody a:contains(18)", picker ).simulate( "mousedown" );
|
|
|
|
TestHelpers.datepicker.equalsDate( inline.datepicker( "valueAsDate" ), new Date( 2008, 3 - 1, 18 ),
|
2013-11-02 13:54:05 +00:00
|
|
|
"Mouse click inline - next" );
|
2014-01-02 21:25:38 +00:00
|
|
|
|
|
|
|
input.datepicker( "destroy" );
|
|
|
|
inline.datepicker( "destroy" );
|
2009-02-02 14:36:08 +00:00
|
|
|
});
|
|
|
|
|
2013-11-20 13:53:02 +00:00
|
|
|
})( jQuery );
|