mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
139 lines
3.1 KiB
JavaScript
139 lines
3.1 KiB
JavaScript
define( [
|
|
"jquery",
|
|
"./helper",
|
|
"ui/datepicker"
|
|
], function( $, testHelper ) {
|
|
|
|
module( "datepicker: events" );
|
|
|
|
test( "beforeOpen", function() {
|
|
expect( 3 );
|
|
|
|
var input = testHelper.init( "#datepicker", {
|
|
beforeOpen: function() {
|
|
ok( true, "beforeOpen event fired before open" );
|
|
ok( input.datepicker( "widget" ).is( ":hidden" ), "calendar hidden on beforeOpen" );
|
|
},
|
|
open: function() {
|
|
ok( input.datepicker( "widget" ).is( ":visible" ), "calendar open on open" );
|
|
}
|
|
});
|
|
|
|
input
|
|
.datepicker( "open" )
|
|
.datepicker( "close" )
|
|
.datepicker( "option", {
|
|
beforeOpen: function() {
|
|
return false;
|
|
},
|
|
open: function() {
|
|
ok( false, "calendar should not open when openBefore is canceled" );
|
|
}
|
|
})
|
|
.datepicker( "open" );
|
|
});
|
|
|
|
test( "close", function() {
|
|
expect( 4 );
|
|
|
|
var shouldFire,
|
|
input = testHelper.init( "#datepicker", {
|
|
close: function() {
|
|
ok( shouldFire, "close event fired" );
|
|
}
|
|
});
|
|
|
|
shouldFire = false;
|
|
input.datepicker( "open" );
|
|
shouldFire = true;
|
|
input.datepicker( "close" );
|
|
|
|
shouldFire = false;
|
|
input.datepicker( "open" );
|
|
shouldFire = true;
|
|
$( "body" ).trigger( "mousedown" );
|
|
|
|
shouldFire = false;
|
|
input.datepicker( "open" );
|
|
shouldFire = true;
|
|
input.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
|
|
|
|
shouldFire = false;
|
|
input.datepicker( "open" );
|
|
shouldFire = true;
|
|
input.datepicker( "widget" ).find( "tbody tr:first button:first" ).simulate( "mousedown" );
|
|
});
|
|
|
|
test( "open", function() {
|
|
expect( 2 );
|
|
|
|
var input = testHelper.init( "#datepicker", {
|
|
open: function() {
|
|
ok( true, "open event fired on open" );
|
|
ok( widget.is( ":visible" ), "calendar open on open" );
|
|
}
|
|
}),
|
|
widget = input.datepicker( "widget" );
|
|
|
|
input.datepicker( "open" );
|
|
});
|
|
|
|
asyncTest( "select", function() {
|
|
expect( 4 );
|
|
|
|
var input = testHelper.init( "#datepicker", {
|
|
select: function( event ) {
|
|
ok( true, "select event fired " + message );
|
|
equal(
|
|
event.originalEvent.type,
|
|
"calendarselect",
|
|
"select originalEvent " + message
|
|
);
|
|
}
|
|
}),
|
|
widget = input.datepicker( "widget" ),
|
|
message = "";
|
|
|
|
function step1() {
|
|
message = "on calendar cell click";
|
|
input
|
|
.simulate( "focus" )
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
|
setTimeout(function() {
|
|
widget.find( "tbody tr:first button:first" ).simulate( "mousedown" );
|
|
input.datepicker( "close" );
|
|
step2();
|
|
}, 100 );
|
|
}
|
|
|
|
function step2() {
|
|
message = "on calendar cell enter";
|
|
input
|
|
.simulate( "focus" )
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
|
setTimeout(function() {
|
|
$( document.activeElement )
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } )
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
|
|
input.datepicker( "close" );
|
|
step3();
|
|
}, 100 );
|
|
}
|
|
|
|
function step3() {
|
|
message = "on calendar escape (not expected)";
|
|
input
|
|
.simulate( "focus" )
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
|
setTimeout(function() {
|
|
$( document.activeElement ).simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
|
|
input.datepicker( "close" );
|
|
start();
|
|
}, 100 );
|
|
}
|
|
|
|
step1();
|
|
});
|
|
|
|
} );
|