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" );
|
|
|
|
|
2014-06-03 21:18:51 +00:00
|
|
|
equal( picker.find( ".ui-calendar-month" ).html(), "January", "correct month displayed" );
|
|
|
|
equal( picker.find( ".ui-calendar-year" ).html(), "2014", "correct year displayed" );
|
|
|
|
equal( picker.find( ".ui-state-active" ).html(), "1", "correct day highlighted" );
|
2013-11-20 13:53:02 +00:00
|
|
|
|
|
|
|
input.val( "" ).datepicker( "destroy" );
|
|
|
|
});
|
|
|
|
|
2014-06-03 21:18:51 +00:00
|
|
|
asyncTest( "base structure", function() {
|
|
|
|
expect( 5 );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2014-06-03 21:18:51 +00:00
|
|
|
var input = TestHelpers.datepicker.initNewInput(),
|
|
|
|
widget = input.datepicker( "widget" );
|
2013-04-14 21:07:24 +00:00
|
|
|
|
2014-06-03 21:18:51 +00:00
|
|
|
input.focus();
|
2013-04-14 21:07:24 +00:00
|
|
|
|
2014-06-03 21:18:51 +00:00
|
|
|
setTimeout(function() {
|
|
|
|
ok( widget.is( ":visible" ), "Datepicker visible" );
|
2014-06-19 22:13:20 +00:00
|
|
|
equal( widget.children().length, 2, "Child count" );
|
2014-06-03 21:18:51 +00:00
|
|
|
ok( widget.is( ".ui-calendar" ), "Class ui-calendar" );
|
|
|
|
ok( widget.is( ".ui-datepicker" ), "Class ui-datepicker" );
|
|
|
|
ok( widget.is( ".ui-front" ), "Class ui-front" );
|
2013-04-14 21:07:24 +00:00
|
|
|
|
2014-06-03 21:18:51 +00:00
|
|
|
input.datepicker( "close" );
|
2013-11-02 13:54:05 +00:00
|
|
|
start();
|
2014-06-03 21:18:51 +00:00
|
|
|
}, 50 );
|
2013-11-02 13:54:05 +00:00
|
|
|
});
|
2013-04-14 21:07:24 +00:00
|
|
|
|
2014-05-15 22:19:32 +00:00
|
|
|
asyncTest( "Keyboard handling: input", function() {
|
2014-06-03 21:18:51 +00:00
|
|
|
expect( 10 );
|
2014-05-15 22:19:32 +00:00
|
|
|
var picker, instance,
|
|
|
|
input = $( "#datepicker" ).datepicker();
|
2013-11-22 14:30:11 +00:00
|
|
|
|
|
|
|
function step1() {
|
2014-05-15 22:19:32 +00:00
|
|
|
TestHelpers.datepicker.init( input );
|
2013-11-22 14:30:11 +00:00
|
|
|
picker = input.datepicker( "widget" );
|
2014-05-15 22:19:32 +00:00
|
|
|
|
2013-11-22 14:30:11 +00:00
|
|
|
ok( !picker.is( ":visible" ), "datepicker closed" );
|
|
|
|
|
2014-05-15 22:19:32 +00:00
|
|
|
input.val( "" ).simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
2013-11-22 14:30:11 +00:00
|
|
|
setTimeout(function() {
|
|
|
|
ok( picker.is( ":visible" ), "Keystroke down opens datepicker" );
|
|
|
|
input.datepicker( "destroy" );
|
|
|
|
step2();
|
2014-05-15 22:19:32 +00:00
|
|
|
}, 100 );
|
2014-04-23 15:49:03 +00:00
|
|
|
}
|
2013-11-22 14:30:11 +00:00
|
|
|
|
|
|
|
function step2() {
|
2014-05-15 22:19:32 +00:00
|
|
|
TestHelpers.datepicker.init( input );
|
2014-04-23 15:49:03 +00:00
|
|
|
picker = input.datepicker( "widget" );
|
2014-05-15 22:19:32 +00:00
|
|
|
|
2013-11-22 14:30:11 +00:00
|
|
|
ok( !picker.is( ":visible" ), "datepicker closed" );
|
|
|
|
|
2014-05-15 22:19:32 +00:00
|
|
|
input.val( "" ).simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
|
2013-11-22 14:30:11 +00:00
|
|
|
setTimeout(function() {
|
|
|
|
ok( picker.is( ":visible" ), "Keystroke up opens datepicker" );
|
|
|
|
input.datepicker( "destroy" );
|
|
|
|
step3();
|
2014-05-15 22:19:32 +00:00
|
|
|
}, 100 );
|
2014-04-23 15:49:03 +00:00
|
|
|
}
|
2013-11-22 14:30:11 +00:00
|
|
|
|
|
|
|
function step3() {
|
2014-05-15 22:19:32 +00:00
|
|
|
TestHelpers.datepicker.init( input );
|
|
|
|
instance = input.datepicker( "instance" );
|
2013-11-22 14:30:11 +00:00
|
|
|
|
2014-06-03 21:18:51 +00:00
|
|
|
// Enter = Select preset date
|
|
|
|
input
|
|
|
|
.val( "1/1/14" )
|
|
|
|
.datepicker( "refresh" )
|
|
|
|
.datepicker( "open" )
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
|
|
|
|
TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), new Date( 2014, 0, 1 ),
|
|
|
|
"Keystroke enter - preset" );
|
|
|
|
|
2014-05-15 22:19:32 +00:00
|
|
|
input
|
|
|
|
.val( "" )
|
|
|
|
.datepicker( "open" );
|
|
|
|
ok( instance.isOpen, "datepicker is open before escape" );
|
2013-11-22 14:30:11 +00:00
|
|
|
|
2014-05-15 22:19:32 +00:00
|
|
|
input.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
|
|
|
|
ok( !instance.isOpen, "escape closes the datepicker" );
|
2013-11-22 14:30:11 +00:00
|
|
|
|
2014-05-15 22:19:32 +00:00
|
|
|
input
|
2013-12-27 13:28:00 +00:00
|
|
|
.val( "1/1/14" )
|
2014-05-15 22:19:32 +00:00
|
|
|
.datepicker( "open" )
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
|
|
|
|
TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), new Date( 2014, 0, 1 ),
|
|
|
|
"Keystroke esc - preset" );
|
2013-11-22 14:30:11 +00:00
|
|
|
|
2014-05-15 22:19:32 +00:00
|
|
|
input
|
|
|
|
.val( "1/1/14" )
|
|
|
|
.datepicker( "open" )
|
|
|
|
.simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP } )
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
|
|
|
|
TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), new Date( 2014, 0, 1 ),
|
|
|
|
"Keystroke esc - abandoned" );
|
|
|
|
|
|
|
|
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" );
|
|
|
|
|
|
|
|
input.datepicker( "destroy" );
|
|
|
|
start();
|
2014-04-23 15:49:03 +00:00
|
|
|
}
|
2013-11-22 14:30:11 +00:00
|
|
|
|
2014-05-15 22:19:32 +00:00
|
|
|
step1();
|
|
|
|
});
|
2013-11-22 14:30:11 +00:00
|
|
|
|
2014-06-03 21:18:51 +00:00
|
|
|
// TODO: implement
|
|
|
|
test( "ARIA", function() {
|
|
|
|
expect( 0 );
|
2013-12-27 13:28:00 +00:00
|
|
|
});
|
|
|
|
|
2014-05-15 22:19:32 +00:00
|
|
|
asyncTest( "mouse", function() {
|
2014-06-03 21:18:51 +00:00
|
|
|
expect( 4 );
|
2014-05-15 22:19:32 +00:00
|
|
|
|
|
|
|
var input = TestHelpers.datepicker.init( $( "#datepicker" ).val( "" ) ),
|
|
|
|
picker = input.datepicker( "widget" );
|
|
|
|
|
|
|
|
input.datepicker( "open" );
|
|
|
|
|
|
|
|
setTimeout(function() {
|
2014-06-03 21:18:51 +00:00
|
|
|
input.val( "4/4/08" ).datepicker( "refresh" ).datepicker( "open" );
|
2015-01-20 17:23:49 +00:00
|
|
|
$( ".ui-calendar-calendar tbody button:contains(12)", picker ).simulate( "mousedown", {} );
|
2014-06-03 21:18:51 +00:00
|
|
|
TestHelpers.datepicker.equalsDate(
|
|
|
|
input.datepicker( "valueAsDate" ),
|
|
|
|
new Date( 2008, 4 - 1, 12 ),
|
|
|
|
"Mouse click - preset"
|
|
|
|
);
|
|
|
|
|
|
|
|
input.val( "" ).datepicker( "refresh" );
|
2014-05-15 22:19:32 +00:00
|
|
|
input.simulate( "click" );
|
|
|
|
strictEqual( input.datepicker( "valueAsDate" ), null, "Mouse click - close" );
|
|
|
|
|
2014-06-03 21:18:51 +00:00
|
|
|
input.val( "4/4/08" ).datepicker( "refresh" ).datepicker( "open" );
|
2014-05-15 22:19:32 +00:00
|
|
|
input.simulate( "click" );
|
|
|
|
TestHelpers.datepicker.equalsDate(
|
|
|
|
input.datepicker( "valueAsDate" ),
|
2014-06-03 21:18:51 +00:00
|
|
|
new Date( 2008, 4 - 1, 4 ),
|
2014-05-15 22:19:32 +00:00
|
|
|
"Mouse click - close + preset"
|
|
|
|
);
|
|
|
|
|
2014-06-03 21:18:51 +00:00
|
|
|
input.val( "4/4/08" ).datepicker( "refresh" ).datepicker( "open" );
|
2014-05-15 22:19:32 +00:00
|
|
|
picker.find( "a.ui-calendar-prev" ).simulate( "click" );
|
|
|
|
input.simulate( "click" );
|
|
|
|
TestHelpers.datepicker.equalsDate(
|
|
|
|
input.datepicker( "valueAsDate" ),
|
2014-06-03 21:18:51 +00:00
|
|
|
new Date( 2008, 4 - 1, 4 ),
|
2014-05-15 22:19:32 +00:00
|
|
|
"Mouse click - abandoned"
|
|
|
|
);
|
|
|
|
|
|
|
|
start();
|
|
|
|
}, 100 );
|
2009-02-02 14:36:08 +00:00
|
|
|
});
|
|
|
|
|
2013-11-20 13:53:02 +00:00
|
|
|
})( jQuery );
|
2014-06-03 21:18:51 +00:00
|
|
|
|