2014-04-23 15:49:03 +00:00
|
|
|
// The implement of events is completely changing therefore these tests are no longer directly
|
|
|
|
// relevant. Leaving them around commented out so we can ensure the functionality is replicated.
|
|
|
|
// For example:
|
|
|
|
// TODO: In the old implementation the Enter key select's today's date when the <input> has
|
|
|
|
// focus and is empty. Do we want to replicate this behavior in the rewrite?
|
|
|
|
/*
|
|
|
|
|
2013-11-02 13:54:05 +00:00
|
|
|
(function( $ ) {
|
|
|
|
|
|
|
|
module( "datepicker: events" );
|
|
|
|
|
|
|
|
test( "beforeOpen", function() {
|
|
|
|
expect( 0 );
|
|
|
|
});
|
|
|
|
|
|
|
|
test( "close", function() {
|
2014-06-16 22:46:08 +00:00
|
|
|
expect( 4 );
|
|
|
|
|
|
|
|
var shouldFire,
|
|
|
|
input = TestHelpers.datepicker.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 a:first" ).simulate( "mousedown" );
|
2013-11-02 13:54:05 +00:00
|
|
|
});
|
2009-02-02 14:36:08 +00:00
|
|
|
|
2013-11-02 13:54:05 +00:00
|
|
|
test( "open", function() {
|
2014-06-16 22:46:08 +00:00
|
|
|
expect( 2 );
|
2013-11-02 13:54:05 +00:00
|
|
|
|
2014-06-16 22:46:08 +00:00
|
|
|
var input = TestHelpers.datepicker.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" );
|
2013-11-02 13:54:05 +00:00
|
|
|
});
|
2009-02-02 14:36:08 +00:00
|
|
|
|
2012-04-19 15:17:35 +00:00
|
|
|
var selectedThis = null,
|
|
|
|
selectedDate = null,
|
|
|
|
selectedInst = null;
|
2009-02-04 04:27:14 +00:00
|
|
|
|
|
|
|
function callback(date, inst) {
|
|
|
|
selectedThis = this;
|
|
|
|
selectedDate = date;
|
|
|
|
selectedInst = inst;
|
|
|
|
}
|
|
|
|
|
|
|
|
function callback2(year, month, inst) {
|
|
|
|
selectedThis = this;
|
2012-12-26 13:08:48 +00:00
|
|
|
selectedDate = year + "/" + month;
|
2009-02-04 04:27:14 +00:00
|
|
|
selectedInst = inst;
|
|
|
|
}
|
|
|
|
|
2014-04-23 15:49:03 +00:00
|
|
|
test( "events", function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 26 );
|
2012-04-19 15:17:35 +00:00
|
|
|
var dateStr, newMonthYear, inp2,
|
2014-04-23 15:49:03 +00:00
|
|
|
inp = TestHelpers.datepicker.init( "#inp", {onSelect: callback}),
|
2012-04-19 15:17:35 +00:00
|
|
|
date = new Date();
|
2009-02-04 04:27:14 +00:00
|
|
|
// onSelect
|
2014-04-23 15:49:03 +00:00
|
|
|
inp.val( "" ).datepicker( "show" ).
|
|
|
|
simulate( "keydown", {keyCode: $.ui.keyCode.ENTER});
|
|
|
|
equal(selectedThis, inp[0], "Callback selected this" );
|
|
|
|
equal(selectedInst, $.data(inp[0], TestHelpers.datepicker.PROP_NAME), "Callback selected inst" );
|
|
|
|
equal(selectedDate, $.datepicker.formatDate( "mm/dd/yy", date),
|
|
|
|
"Callback selected date" );
|
|
|
|
inp.val( "" ).datepicker( "show" ).
|
|
|
|
simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.DOWN}).
|
|
|
|
simulate( "keydown", {keyCode: $.ui.keyCode.ENTER});
|
2009-02-04 04:27:14 +00:00
|
|
|
date.setDate(date.getDate() + 7);
|
2014-04-23 15:49:03 +00:00
|
|
|
equal(selectedDate, $.datepicker.formatDate( "mm/dd/yy", date),
|
|
|
|
"Callback selected date - ctrl+down" );
|
|
|
|
inp.val( "" ).datepicker( "show" ).
|
|
|
|
simulate( "keydown", {keyCode: $.ui.keyCode.ESCAPE});
|
|
|
|
equal(selectedDate, $.datepicker.formatDate( "mm/dd/yy", date),
|
|
|
|
"Callback selected date - esc" );
|
2012-12-26 13:08:48 +00:00
|
|
|
dateStr = "02/04/2008";
|
2014-04-23 15:49:03 +00:00
|
|
|
inp.val(dateStr).datepicker( "show" ).
|
|
|
|
simulate( "keydown", {keyCode: $.ui.keyCode.ENTER});
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(dateStr, selectedDate,
|
2014-04-23 15:49:03 +00:00
|
|
|
"onSelect is called after enter keydown" );
|
2009-02-04 04:27:14 +00:00
|
|
|
// onChangeMonthYear
|
2014-04-23 15:49:03 +00:00
|
|
|
inp.datepicker( "option", {onChangeMonthYear: callback2, onSelect: null}).
|
|
|
|
val( "" ).datepicker( "show" );
|
2012-04-19 15:17:35 +00:00
|
|
|
newMonthYear = function(date) {
|
2012-12-26 13:08:48 +00:00
|
|
|
return date.getFullYear() + "/" + (date.getMonth() + 1);
|
2009-02-04 04:27:14 +00:00
|
|
|
};
|
|
|
|
date = new Date();
|
|
|
|
date.setDate(1);
|
2014-04-23 15:49:03 +00:00
|
|
|
inp.simulate( "keydown", {keyCode: $.ui.keyCode.PAGE_UP});
|
2009-02-04 04:27:14 +00:00
|
|
|
date.setMonth(date.getMonth() - 1);
|
2014-04-23 15:49:03 +00:00
|
|
|
equal(selectedThis, inp[0], "Callback change month/year this" );
|
|
|
|
equal(selectedInst, $.data(inp[0], TestHelpers.datepicker.PROP_NAME), "Callback change month/year inst" );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(selectedDate, newMonthYear(date),
|
2014-04-23 15:49:03 +00:00
|
|
|
"Callback change month/year date - pgup" );
|
|
|
|
inp.simulate( "keydown", {keyCode: $.ui.keyCode.PAGE_DOWN});
|
2009-02-04 04:27:14 +00:00
|
|
|
date.setMonth(date.getMonth() + 1);
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(selectedDate, newMonthYear(date),
|
2014-04-23 15:49:03 +00:00
|
|
|
"Callback change month/year date - pgdn" );
|
|
|
|
inp.simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP});
|
2009-02-04 04:27:14 +00:00
|
|
|
date.setFullYear(date.getFullYear() - 1);
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(selectedDate, newMonthYear(date),
|
2014-04-23 15:49:03 +00:00
|
|
|
"Callback change month/year date - ctrl+pgup" );
|
|
|
|
inp.simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.HOME});
|
2009-02-04 04:27:14 +00:00
|
|
|
date.setFullYear(date.getFullYear() + 1);
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(selectedDate, newMonthYear(date),
|
2014-04-23 15:49:03 +00:00
|
|
|
"Callback change month/year date - ctrl+home" );
|
|
|
|
inp.simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN});
|
2009-02-04 04:27:14 +00:00
|
|
|
date.setFullYear(date.getFullYear() + 1);
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(selectedDate, newMonthYear(date),
|
2014-04-23 15:49:03 +00:00
|
|
|
"Callback change month/year date - ctrl+pgdn" );
|
|
|
|
inp.datepicker( "setDate", new Date(2007, 1 - 1, 26));
|
|
|
|
equal(selectedDate, "2007/1", "Callback change month/year date - setDate" );
|
2009-02-04 04:27:14 +00:00
|
|
|
selectedDate = null;
|
2014-04-23 15:49:03 +00:00
|
|
|
inp.datepicker( "setDate", new Date(2007, 1 - 1, 12));
|
|
|
|
ok(selectedDate == null, "Callback change month/year date - setDate no change" );
|
2009-02-04 04:27:14 +00:00
|
|
|
// onChangeMonthYear step by 2
|
2014-04-23 15:49:03 +00:00
|
|
|
inp.datepicker( "option", {stepMonths: 2}).
|
|
|
|
datepicker( "hide" ).val( "" ).datepicker( "show" ).
|
|
|
|
simulate( "keydown", {keyCode: $.ui.keyCode.PAGE_UP});
|
2009-02-04 04:27:14 +00:00
|
|
|
date.setMonth(date.getMonth() - 14);
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(selectedDate, newMonthYear(date),
|
2014-04-23 15:49:03 +00:00
|
|
|
"Callback change month/year by 2 date - pgup" );
|
|
|
|
inp.simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP});
|
2009-02-04 04:27:14 +00:00
|
|
|
date.setMonth(date.getMonth() - 12);
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(selectedDate, newMonthYear(date),
|
2014-04-23 15:49:03 +00:00
|
|
|
"Callback change month/year by 2 date - ctrl+pgup" );
|
|
|
|
inp.simulate( "keydown", {keyCode: $.ui.keyCode.PAGE_DOWN});
|
2009-02-04 04:27:14 +00:00
|
|
|
date.setMonth(date.getMonth() + 2);
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(selectedDate, newMonthYear(date),
|
2014-04-23 15:49:03 +00:00
|
|
|
"Callback change month/year by 2 date - pgdn" );
|
|
|
|
inp.simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN});
|
2009-02-04 04:27:14 +00:00
|
|
|
date.setMonth(date.getMonth() + 12);
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(selectedDate, newMonthYear(date),
|
2014-04-23 15:49:03 +00:00
|
|
|
"Callback change month/year by 2 date - ctrl+pgdn" );
|
2009-02-04 04:27:14 +00:00
|
|
|
// onClose
|
2014-04-23 15:49:03 +00:00
|
|
|
inp.datepicker( "option", {onClose: callback, onChangeMonthYear: null, stepMonths: 1}).
|
|
|
|
val( "" ).datepicker( "show" ).
|
|
|
|
simulate( "keydown", {keyCode: $.ui.keyCode.ESCAPE});
|
|
|
|
equal(selectedThis, inp[0], "Callback close this" );
|
|
|
|
equal(selectedInst, $.data(inp[0], TestHelpers.datepicker.PROP_NAME), "Callback close inst" );
|
|
|
|
equal(selectedDate, "", "Callback close date - esc" );
|
|
|
|
inp.val( "" ).datepicker( "show" ).
|
|
|
|
simulate( "keydown", {keyCode: $.ui.keyCode.ENTER});
|
|
|
|
equal(selectedDate, $.datepicker.formatDate( "mm/dd/yy", new Date()),
|
|
|
|
"Callback close date - enter" );
|
|
|
|
inp.val( "02/04/2008" ).datepicker( "show" ).
|
|
|
|
simulate( "keydown", {keyCode: $.ui.keyCode.ESCAPE});
|
|
|
|
equal(selectedDate, "02/04/2008", "Callback close date - preset" );
|
|
|
|
inp.val( "02/04/2008" ).datepicker( "show" ).
|
|
|
|
simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.END});
|
|
|
|
equal(selectedDate, "", "Callback close date - ctrl+end" );
|
2011-05-06 20:58:06 +00:00
|
|
|
|
2014-04-23 15:49:03 +00:00
|
|
|
inp2 = TestHelpers.datepicker.init( "#inp2" );
|
|
|
|
inp2.datepicker().datepicker( "option", {onClose: callback}).datepicker( "show" );
|
|
|
|
inp.datepicker( "show" );
|
|
|
|
equal(selectedThis, inp2[0], "Callback close this" );
|
2009-02-02 14:36:08 +00:00
|
|
|
});
|
|
|
|
|
2013-11-02 13:54:05 +00:00
|
|
|
})( jQuery );
|
2014-04-23 15:49:03 +00:00
|
|
|
*/
|