Datepicker: Re-adding mouse tests

This commit is contained in:
TJ VanToll 2014-01-02 16:25:38 -05:00 committed by Scott González
parent 605387d6fc
commit 104f3e6be0

View File

@ -498,109 +498,109 @@ asyncTest( "keyboard handling", function() {
*/ */
test( "mouse", function() { test( "mouse", function() {
// TODO: These tests use the old getDate() and setDate() methods. Re-activate these expect( 13 );
// tests when those methods are available. var input = $( "#datepicker" ).datepicker(),
expect( 0 ); picker = input.datepicker( "widget" ),
return; inline = $( "#inline" ).datepicker,
expect( 15 );
var inl,
inp = TestHelpers.datepicker.init( "#datepicker" ),
dp = inp.datepicker( "widget" ).find( ".ui-datepicker" ),
date = new Date(); date = new Date();
inp.val( "" ).datepicker( "open" ); input.val( "" ).datepicker( "open" );
$( ".ui-datepicker-calendar tbody a:contains(10)", dp ).simulate( "click", {} ); $( ".ui-datepicker-calendar tbody a:contains(10)", picker ).simulate( "mousedown", {} );
date.setDate( 10 ); date.setDate( 10 );
TestHelpers.datepicker.equalsDate( inp.datepicker( "getDate" ), date, "Mouse click" ); TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), date, "Mouse click" );
inp.val( "02/04/2008" ).datepicker( "open" ); input.val( "2/4/08" ).datepicker( "open" );
$( ".ui-datepicker-calendar tbody a:contains(12)", dp ).simulate( "click", {} ); $( ".ui-datepicker-calendar tbody a:contains(12)", picker ).simulate( "mousedown", {} );
TestHelpers.datepicker.equalsDate( inp.datepicker("getDate"), new Date( 2008, 2 - 1, 12 ), TestHelpers.datepicker.equalsDate( input.datepicker("valueAsDate"), new Date( 2008, 2 - 1, 12 ),
"Mouse click - preset") ; "Mouse click - preset") ;
inp.val( "02/04/2008" ).datepicker( "open" ); input.val( "" ).datepicker( "open" );
inp.val( "").datepicker( "open" ); $( "button.ui-datepicker-close", picker ).simulate( "click", {} );
$( "button.ui-datepicker-close", dp ).simulate( "click", {} ); ok( input.datepicker( "valueAsDate" ) == null, "Mouse click - close" );
ok( inp.datepicker( "getDate" ) == null, "Mouse click - close" );
inp.val( "02/04/2008" ).datepicker( "open" ); input.val( "2/4/08" ).datepicker( "open" );
$( "button.ui-datepicker-close", dp ).simulate( "click", {} ); $( "button.ui-datepicker-close", picker ).simulate( "click", {} );
TestHelpers.datepicker.equalsDate( inp.datepicker( "getDate" ), new Date( 2008, 2 - 1, 4 ), TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), new Date( 2008, 2 - 1, 4 ),
"Mouse click - close + preset" ); "Mouse click - close + preset" );
inp.val( "02/04/2008" ).datepicker( "open" ); input.val( "2/4/08" ).datepicker( "open" );
$( "a.ui-datepicker-prev", dp ).simulate( "click", {} ); $( "a.ui-datepicker-prev", picker ).simulate( "click", {} );
$( "button.ui-datepicker-close", dp ).simulate( "click", {} ); $( "button.ui-datepicker-close", picker ).simulate( "click", {} );
TestHelpers.datepicker.equalsDate( inp.datepicker( "getDate" ), new Date( 2008, 2 - 1, 4 ), TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), new Date( 2008, 2 - 1, 4 ),
"Mouse click - abandoned" ); "Mouse click - abandoned" );
// Current/previous/next // Current/previous/next
inp.val( "02/04/2008" ).datepicker( "option", { showButtonPanel: true }).datepicker( "open" ); input.val( "" ).datepicker( "open" );
$( ".ui-datepicker-current", dp ).simulate( "click", {} ); $( ".ui-datepicker-current", picker ).simulate( "click", {} );
$( ".ui-datepicker-calendar tbody a:contains(14)", dp ).simulate( "click", {} ); date.setDate( new Date().getDate() );
date.setDate( 14 ); TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), date, "Mouse click - current" );
TestHelpers.datepicker.equalsDate( inp.datepicker( "getDate" ), date, "Mouse click - current" );
inp.val( "02/04/2008" ).datepicker( "open" ); input.val( "2/4/08" ).datepicker( "open" );
$( ".ui-datepicker-prev", dp ).simulate( "click" ); $( ".ui-datepicker-prev", picker ).simulate( "click" );
$( ".ui-datepicker-calendar tbody a:contains(16)", dp ).simulate( "click" ); $( ".ui-datepicker-calendar tbody a:contains(16)", picker ).simulate( "mousedown" );
TestHelpers.datepicker.equalsDate( inp.datepicker( "getDate" ), new Date( 2008, 1 - 1, 16 ), TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), new Date( 2008, 1 - 1, 16 ),
"Mouse click - previous" ); "Mouse click - previous" );
inp.val( "02/04/2008" ).datepicker( "open" ); input.val( "2/4/08" ).datepicker( "open" );
$(".ui-datepicker-next", dp ).simulate( "click" ); $(".ui-datepicker-next", picker ).simulate( "click" );
$(".ui-datepicker-calendar tbody a:contains(18)", dp ).simulate( "click" ); $(".ui-datepicker-calendar tbody a:contains(18)", picker ).simulate( "mousedown" );
TestHelpers.datepicker.equalsDate( inp.datepicker("getDate"), new Date( 2008, 3 - 1, 18 ), TestHelpers.datepicker.equalsDate( input.datepicker("valueAsDate"), new Date( 2008, 3 - 1, 18 ),
"Mouse click - next" ); "Mouse click - next" );
/*
// TODO: Re-add when min and max options are introduced.
// Previous/next with minimum/maximum // Previous/next with minimum/maximum
inp.datepicker("option", { input.datepicker("option", {
minDate: new Date( 2008, 2 - 1, 2 ), minDate: new Date( 2008, 2 - 1, 2 ),
maxDate: new Date( 2008, 2 - 1, 26 ) maxDate: new Date( 2008, 2 - 1, 26 )
}).val( "02/04/2008" ).datepicker( "open" ); }).val( "2/4/08" ).datepicker( "open" );
$( ".ui-datepicker-prev", dp ).simulate( "click" ); $( ".ui-datepicker-prev", picker ).simulate( "click" );
$( ".ui-datepicker-calendar tbody a:contains(16)", dp ).simulate( "click" ); $( ".ui-datepicker-calendar tbody a:contains(16)", picker ).simulate( "mousedown" );
TestHelpers.datepicker.equalsDate( inp.datepicker( "getDate" ), new Date( 2008, 2 - 1, 16 ), TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), new Date( 2008, 2 - 1, 16 ),
"Mouse click - previous + min/max" ); "Mouse click - previous + min/max" );
inp.val( "02/04/2008" ).datepicker( "open" ); input.val( "2/4/08" ).datepicker( "open" );
$( ".ui-datepicker-next", dp ).simulate( "click" ); $( ".ui-datepicker-next", picker ).simulate( "click" );
$( ".ui-datepicker-calendar tbody a:contains(18)", dp ).simulate( "click" ); $( ".ui-datepicker-calendar tbody a:contains(18)", picker ).simulate( "mousedown" );
TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), new Date( 2008, 2 - 1, 18 ), TestHelpers.datepicker.equalsDate(input.datepicker( "valueAsDate" ), new Date( 2008, 2 - 1, 18 ),
"Mouse click - next + min/max" ); "Mouse click - next + min/max" );
*/
// Inline // Inline
inl = TestHelpers.datepicker.init( "#inline" ); inline = TestHelpers.datepicker.init( "#inline" );
dp = $( ".ui-datepicker-inline", inl ); picker = $( ".ui-datepicker-inline", inline );
date = new Date(); date = new Date();
inl.datepicker( "setDate", date ); inline.datepicker( "valueAsDate", date );
$( ".ui-datepicker-calendar tbody a:contains(10)", dp ).simulate( "click", {} ); $( ".ui-datepicker-calendar tbody a:contains(10)", picker ).simulate( "mousedown", {} );
date.setDate( 10 ); date.setDate( 10 );
TestHelpers.datepicker.equalsDate( inl.datepicker( "getDate" ), date, "Mouse click inline" ); TestHelpers.datepicker.equalsDate( inline.datepicker( "valueAsDate" ), date, "Mouse click inline" );
inl.datepicker( "option", { showButtonPanel: true }) inline.datepicker( "option", { showButtonPanel: true })
.datepicker( "setDate", new Date( 2008, 2 - 1, 4 )); .datepicker( "valueAsDate", new Date( 2008, 2 - 1, 4 ));
$( ".ui-datepicker-calendar tbody a:contains(12)", dp ).simulate( "click", {} ); $( ".ui-datepicker-calendar tbody a:contains(12)", picker ).simulate( "mousedown", {} );
TestHelpers.datepicker.equalsDate( inl.datepicker( "getDate" ), new Date( 2008, 2 - 1, 12 ), TestHelpers.datepicker.equalsDate( inline.datepicker( "valueAsDate" ), new Date( 2008, 2 - 1, 12 ),
"Mouse click inline - preset" ); "Mouse click inline - preset" );
inl.datepicker("option", { showButtonPanel: true }); inline.datepicker("option", { showButtonPanel: true });
$( ".ui-datepicker-current", dp ).simulate( "click", {} ); $( ".ui-datepicker-current", picker ).simulate( "click", {} );
$( ".ui-datepicker-calendar tbody a:contains(14)", dp ).simulate( "click", {} ); $( ".ui-datepicker-calendar tbody a:contains(14)", picker ).simulate( "mousedown", {} );
date.setDate( 14 ); date.setDate( 14 );
TestHelpers.datepicker.equalsDate( inl.datepicker( "getDate" ), date, "Mouse click inline - current" ); TestHelpers.datepicker.equalsDate( inline.datepicker( "valueAsDate" ), date, "Mouse click inline - current" );
inl.datepicker( "setDate", new Date( 2008, 2 - 1, 4) ); inline.datepicker( "valueAsDate", new Date( 2008, 2 - 1, 4) );
$( ".ui-datepicker-prev", dp ).simulate( "click" ); $( ".ui-datepicker-prev", picker ).simulate( "click" );
$( ".ui-datepicker-calendar tbody a:contains(16)", dp ).simulate( "click" ); $( ".ui-datepicker-calendar tbody a:contains(16)", picker ).simulate( "mousedown" );
TestHelpers.datepicker.equalsDate( inl.datepicker( "getDate" ), new Date( 2008, 1 - 1, 16 ), TestHelpers.datepicker.equalsDate( inline.datepicker( "valueAsDate" ), new Date( 2008, 1 - 1, 16 ),
"Mouse click inline - previous" ); "Mouse click inline - previous" );
inl.datepicker( "setDate", new Date( 2008, 2 - 1, 4) ); inline.datepicker( "valueAsDate", new Date( 2008, 2 - 1, 4) );
$( ".ui-datepicker-next", dp ).simulate( "click" ); $( ".ui-datepicker-next", picker ).simulate( "click" );
$( ".ui-datepicker-calendar tbody a:contains(18)", dp ).simulate( "click" ); $( ".ui-datepicker-calendar tbody a:contains(18)", picker ).simulate( "mousedown" );
TestHelpers.datepicker.equalsDate( inl.datepicker( "getDate" ), new Date( 2008, 3 - 1, 18 ), TestHelpers.datepicker.equalsDate( inline.datepicker( "valueAsDate" ), new Date( 2008, 3 - 1, 18 ),
"Mouse click inline - next" ); "Mouse click inline - next" );
input.datepicker( "destroy" );
inline.datepicker( "destroy" );
}); });
})( jQuery ); })( jQuery );