2009-02-02 14:36:08 +00:00
|
|
|
/*
|
|
|
|
* datepicker_core.js
|
|
|
|
*/
|
2009-02-04 04:27:14 +00:00
|
|
|
|
|
|
|
function equalsDate(d1, d2, message) {
|
|
|
|
if (!d1 || !d2) {
|
|
|
|
ok(false, message + ' - missing date');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
d1 = new Date(d1.getFullYear(), d1.getMonth(), d1.getDate());
|
|
|
|
d2 = new Date(d2.getFullYear(), d2.getMonth(), d2.getDate());
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(d1.toString(), d2.toString(), message);
|
2009-02-04 04:27:14 +00:00
|
|
|
}
|
|
|
|
|
2012-10-23 02:37:42 +00:00
|
|
|
TestHelpers.addMonths = function(date, offset) {
|
2009-04-01 10:15:29 +00:00
|
|
|
var maxDay = 32 - new Date(date.getFullYear(), date.getMonth() + offset, 32).getDate();
|
|
|
|
date.setDate(Math.min(date.getDate(), maxDay));
|
|
|
|
date.setMonth(date.getMonth() + offset);
|
|
|
|
return date;
|
2012-10-23 02:37:42 +00:00
|
|
|
};
|
2009-04-01 10:15:29 +00:00
|
|
|
|
2009-02-04 04:27:14 +00:00
|
|
|
function init(id, options) {
|
|
|
|
$.datepicker.setDefaults($.datepicker.regional['']);
|
2009-12-01 01:24:00 +00:00
|
|
|
return $(id).datepicker($.extend({showAnim: ''}, options || {}));
|
2009-02-04 04:27:14 +00:00
|
|
|
}
|
|
|
|
|
2012-10-23 02:37:42 +00:00
|
|
|
TestHelpers.PROP_NAME = 'datepicker';
|
2009-02-04 04:27:14 +00:00
|
|
|
|
2009-02-02 14:36:08 +00:00
|
|
|
(function($) {
|
|
|
|
|
2011-02-18 15:08:17 +00:00
|
|
|
module("datepicker: core");
|
2009-02-02 14:36:08 +00:00
|
|
|
|
2011-02-15 18:15:46 +00:00
|
|
|
test( "widget method - empty collection", function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 1 );
|
2011-02-15 18:15:46 +00:00
|
|
|
$( "#nonExist" ).datepicker(); // should create nothing
|
|
|
|
ok( !$( "#ui-datepicker-div" ).length, "Non init on empty collection" );
|
|
|
|
});
|
|
|
|
|
2010-01-07 03:19:50 +00:00
|
|
|
test("widget method", function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 1 );
|
2010-01-07 03:19:50 +00:00
|
|
|
var actual = $("#inp").datepicker().datepicker("widget")[0];
|
2012-02-28 14:56:32 +00:00
|
|
|
deepEqual($("body > #ui-datepicker-div:last-child")[0], actual);
|
2010-01-07 03:19:50 +00:00
|
|
|
});
|
|
|
|
|
2009-02-04 04:27:14 +00:00
|
|
|
test('baseStructure', function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 59 );
|
2012-04-19 15:17:35 +00:00
|
|
|
var header, title, table, thead, week, panel, inl, child,
|
|
|
|
inp = init('#inp').focus(),
|
|
|
|
dp = $('#ui-datepicker-div'),
|
2012-10-10 15:45:48 +00:00
|
|
|
iframe = ($.ui.ie6);
|
2009-02-04 04:27:14 +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');
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(dp.children().length, 2 + (iframe ? 1 : 0), 'Structure - child count');
|
|
|
|
|
2012-04-19 15:17:35 +00:00
|
|
|
header = dp.children(':first');
|
2009-02-04 04:27:14 +00:00
|
|
|
ok(header.is('div.ui-datepicker-header'), 'Structure - header division');
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(header.children().length, 3, 'Structure - header child count');
|
2012-04-19 15:17:35 +00:00
|
|
|
ok(header.children(':first').is('a.ui-datepicker-prev') && header.children(':first').html() !== '', 'Structure - prev link');
|
|
|
|
ok(header.children(':eq(1)').is('a.ui-datepicker-next') && header.children(':eq(1)').html() !== '', 'Structure - next link');
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2012-04-19 15:17:35 +00:00
|
|
|
title = header.children(':last');
|
|
|
|
ok(title.is('div.ui-datepicker-title') && title.html() !== '','Structure - title division');
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(title.children().length, 2, 'Structure - title child count');
|
2012-04-19 15:17:35 +00:00
|
|
|
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');
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2012-04-19 15:17:35 +00:00
|
|
|
table = dp.children(':eq(1)');
|
2009-02-04 04:27:14 +00:00
|
|
|
ok(table.is('table.ui-datepicker-calendar'), 'Structure - month table');
|
|
|
|
ok(table.children(':first').is('thead'), 'Structure - month table thead');
|
2012-04-19 15:17:35 +00:00
|
|
|
thead = table.children(':first').children(':first');
|
2009-02-04 04:27:14 +00:00
|
|
|
ok(thead.is('tr'), 'Structure - month table title row');
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(thead.find('th').length, 7, 'Structure - month table title cells');
|
2009-02-04 04:27:14 +00:00
|
|
|
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');
|
2012-04-19 15:17:35 +00:00
|
|
|
week = table.children(':eq(1)').children(':first');
|
2009-02-04 04:27:14 +00:00
|
|
|
ok(week.is('tr'), 'Structure - month table week row');
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(week.children().length, 7, 'Structure - week child count');
|
2009-02-04 04:27:14 +00:00
|
|
|
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');
|
2012-04-19 15:17:35 +00:00
|
|
|
ok(dp.children('iframe').length === (iframe ? 1 : 0), 'Structure - iframe');
|
2009-02-04 04:27:14 +00:00
|
|
|
inp.datepicker('hide').datepicker('destroy');
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2009-02-04 04:27:14 +00:00
|
|
|
// Editable month/year and button panel
|
|
|
|
inp = init('#inp', {changeMonth: true, changeYear: true, showButtonPanel: true});
|
|
|
|
inp.focus();
|
|
|
|
|
2012-04-19 15:17:35 +00:00
|
|
|
title = dp.find('div.ui-datepicker-title');
|
2009-02-04 04:27:14 +00:00
|
|
|
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-02-28 14:56:32 +00:00
|
|
|
|
2012-04-19 15:17:35 +00:00
|
|
|
panel = dp.children(':last');
|
2009-02-04 04:27:14 +00:00
|
|
|
ok(panel.is('div.ui-datepicker-buttonpane'), 'Structure - button panel division');
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(panel.children().length, 2, 'Structure - button panel child count');
|
2009-02-04 04:27:14 +00:00
|
|
|
ok(panel.children(':first').is('button.ui-datepicker-current'), 'Structure - today button');
|
|
|
|
ok(panel.children(':last').is('button.ui-datepicker-close'), 'Structure - close button');
|
|
|
|
inp.datepicker('hide').datepicker('destroy');
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2009-02-04 04:27:14 +00:00
|
|
|
// Multi-month 2
|
|
|
|
inp = init('#inp', {numberOfMonths: 2});
|
|
|
|
inp.focus();
|
|
|
|
ok(dp.is('.ui-datepicker-multi'), 'Structure multi [2] - multi-month');
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(dp.children().length, 3 + (iframe ? 1 : 0), 'Structure multi [2] - child count');
|
2012-04-19 15:17:35 +00:00
|
|
|
child = dp.children(':first');
|
2009-04-01 10:15:29 +00:00
|
|
|
ok(child.is('div.ui-datepicker-group') && child.is('div.ui-datepicker-group-first'), 'Structure multi [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] - second month division');
|
|
|
|
child = dp.children(':eq(2)');
|
|
|
|
ok(child.is('div.ui-datepicker-row-break'), 'Structure multi [2] - row break');
|
2011-05-04 19:07:43 +00:00
|
|
|
ok(dp.is('.ui-datepicker-multi-2'), 'Structure multi [2] - multi-2');
|
2009-02-04 04:27:14 +00:00
|
|
|
inp.datepicker('hide').datepicker('destroy');
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2011-05-04 19:07:43 +00:00
|
|
|
// Multi-month 3
|
|
|
|
inp = init('#inp', {numberOfMonths: 3});
|
|
|
|
inp.focus();
|
|
|
|
ok(dp.is('.ui-datepicker-multi-3'), 'Structure multi [3] - multi-3');
|
|
|
|
ok(! dp.is('.ui-datepicker-multi-2'), 'Structure multi [3] - Trac #6704');
|
|
|
|
inp.datepicker('hide').datepicker('destroy');
|
|
|
|
|
2009-02-04 04:27:14 +00:00
|
|
|
// Multi-month [2, 2]
|
|
|
|
inp = init('#inp', {numberOfMonths: [2, 2]});
|
|
|
|
inp.focus();
|
|
|
|
ok(dp.is('.ui-datepicker-multi'), 'Structure multi - multi-month');
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(dp.children().length, 6 + (iframe ? 1 : 0), 'Structure multi [2,2] - child count');
|
2009-04-01 10:15:29 +00:00
|
|
|
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');
|
2009-02-04 04:27:14 +00:00
|
|
|
inp.datepicker('hide').datepicker('destroy');
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2009-02-04 04:27:14 +00:00
|
|
|
// Inline
|
2012-04-19 15:17:35 +00:00
|
|
|
inl = init('#inl');
|
2009-02-04 04:27:14 +00:00
|
|
|
dp = inl.children();
|
|
|
|
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');
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(dp.children().length, 2, 'Structure inline - child count');
|
2012-04-19 15:17:35 +00:00
|
|
|
header = dp.children(':first');
|
2009-02-04 04:27:14 +00:00
|
|
|
ok(header.is('div.ui-datepicker-header'), 'Structure inline - header division');
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(header.children().length, 3, 'Structure inline - header child count');
|
2012-04-19 15:17:35 +00:00
|
|
|
table = dp.children(':eq(1)');
|
2009-02-04 04:27:14 +00:00
|
|
|
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');
|
|
|
|
inl.datepicker('destroy');
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2009-02-04 04:27:14 +00:00
|
|
|
// Inline multi-month
|
|
|
|
inl = init('#inl', {numberOfMonths: 2});
|
|
|
|
dp = inl.children();
|
2012-02-28 14:56:32 +00:00
|
|
|
ok(dp.is('.ui-datepicker-inline') && dp.is('.ui-datepicker-multi'), 'Structure inline multi - main div');
|
|
|
|
equal(dp.children().length, 3 + (iframe ? 1 : 0), 'Structure inline multi - child count');
|
2009-04-01 10:15:29 +00:00
|
|
|
child = dp.children(':first');
|
|
|
|
ok(child.is('div.ui-datepicker-group') && child.is('div.ui-datepicker-group-first'), 'Structure inline multi - first month division');
|
|
|
|
child = dp.children(':eq(1)');
|
|
|
|
ok(child.is('div.ui-datepicker-group') && child.is('div.ui-datepicker-group-last'), 'Structure inline multi - second month division');
|
|
|
|
child = dp.children(':eq(2)');
|
|
|
|
ok(child.is('div.ui-datepicker-row-break'), 'Structure inline multi - row break');
|
2009-02-04 04:27:14 +00:00
|
|
|
inl.datepicker('destroy');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('customStructure', function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 20 );
|
2012-04-19 15:17:35 +00:00
|
|
|
var iframe, header, panel, title, thead,
|
|
|
|
dp = $('#ui-datepicker-div'),
|
|
|
|
// Check right-to-left localisation
|
|
|
|
inp = init('#inp', $.datepicker.regional.he);
|
2009-02-04 04:27:14 +00:00
|
|
|
inp.data('showButtonPanel.datepicker',true);
|
|
|
|
inp.focus();
|
2012-10-10 15:45:48 +00:00
|
|
|
iframe = ($.ui.ie6);
|
2009-02-04 04:27:14 +00:00
|
|
|
ok(dp.is('.ui-datepicker-rtl'), 'Structure RTL - right-to-left');
|
2012-04-19 15:17:35 +00:00
|
|
|
header = dp.children(':first');
|
2009-02-04 04:27:14 +00:00
|
|
|
ok(header.is('div.ui-datepicker-header'), 'Structure RTL - header division');
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(header.children().length, 3, 'Structure RTL - header child count');
|
2009-02-04 04:27:14 +00:00
|
|
|
ok(header.children(':first').is('a.ui-datepicker-next'), 'Structure RTL - prev link');
|
2012-02-28 14:56:32 +00:00
|
|
|
ok(header.children(':eq(1)').is('a.ui-datepicker-prev'), 'Structure RTL - next link');
|
2012-04-19 15:17:35 +00:00
|
|
|
panel = dp.children(':last');
|
2009-02-04 04:27:14 +00:00
|
|
|
ok(panel.is('div.ui-datepicker-buttonpane'), 'Structure RTL - button division');
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(panel.children().length, 2, 'Structure RTL - button panel child count');
|
2009-02-04 04:27:14 +00:00
|
|
|
ok(panel.children(':first').is('button.ui-datepicker-close'), 'Structure RTL - close button');
|
|
|
|
ok(panel.children(':last').is('button.ui-datepicker-current'), 'Structure RTL - today button');
|
|
|
|
inp.datepicker('hide').datepicker('destroy');
|
|
|
|
|
|
|
|
// Hide prev/next
|
|
|
|
inp = init('#inp', {hideIfNoPrevNext: true, minDate: new Date(2008, 2 - 1, 4), maxDate: new Date(2008, 2 - 1, 14)});
|
|
|
|
inp.val('02/10/2008').focus();
|
2012-04-19 15:17:35 +00:00
|
|
|
header = dp.children(':first');
|
2009-02-04 04:27:14 +00:00
|
|
|
ok(header.is('div.ui-datepicker-header'), 'Structure hide prev/next - header division');
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(header.children().length, 1, 'Structure hide prev/next - links child count');
|
2009-02-04 04:27:14 +00:00
|
|
|
ok(header.children(':first').is('div.ui-datepicker-title'), 'Structure hide prev/next - title division');
|
|
|
|
inp.datepicker('hide').datepicker('destroy');
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2009-02-04 04:27:14 +00:00
|
|
|
// Changeable Month with read-only year
|
|
|
|
inp = init('#inp', {changeMonth: true});
|
|
|
|
inp.focus();
|
2012-04-19 15:17:35 +00:00
|
|
|
title = dp.children(':first').children(':last');
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(title.children().length, 2, 'Structure changeable month - title child count');
|
2009-02-04 04:27:14 +00:00
|
|
|
ok(title.children(':first').is('select.ui-datepicker-month'), 'Structure changeable month - month selector');
|
|
|
|
ok(title.children(':last').is('span.ui-datepicker-year'), 'Structure changeable month - read-only year');
|
|
|
|
inp.datepicker('hide').datepicker('destroy');
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2009-02-04 04:27:14 +00:00
|
|
|
// Changeable year with read-only month
|
|
|
|
inp = init('#inp', {changeYear: true});
|
|
|
|
inp.focus();
|
2012-04-19 15:17:35 +00:00
|
|
|
title = dp.children(':first').children(':last');
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(title.children().length, 2, 'Structure changeable year - title child count');
|
2009-02-04 04:27:14 +00:00
|
|
|
ok(title.children(':first').is('span.ui-datepicker-month'), 'Structure changeable year - read-only month');
|
|
|
|
ok(title.children(':last').is('select.ui-datepicker-year'), 'Structure changeable year - year selector');
|
|
|
|
inp.datepicker('hide').datepicker('destroy');
|
|
|
|
|
|
|
|
// Read-only first day of week
|
|
|
|
inp = init('#inp', {changeFirstDay: false});
|
|
|
|
inp.focus();
|
2012-04-19 15:17:35 +00:00
|
|
|
thead = dp.find('.ui-datepicker-calendar thead tr');
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(thead.children().length, 7, 'Structure read-only first day - thead child count');
|
|
|
|
equal(thead.find('a').length, 0, 'Structure read-only first day - thead links count');
|
2009-02-04 04:27:14 +00:00
|
|
|
inp.datepicker('hide').datepicker('destroy');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('keystrokes', function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 26 );
|
2012-04-19 15:17:35 +00:00
|
|
|
var inp = init('#inp'),
|
|
|
|
date = new Date();
|
2009-02-04 04:27:14 +00:00
|
|
|
inp.val('').datepicker('show').
|
2012-03-27 18:46:13 +00:00
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
|
2009-02-04 04:27:14 +00:00
|
|
|
equalsDate(inp.datepicker('getDate'), date, 'Keystroke enter');
|
|
|
|
inp.val('02/04/2008').datepicker('show').
|
2012-03-27 18:46:13 +00:00
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
|
2009-02-04 04:27:14 +00:00
|
|
|
equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4),
|
|
|
|
'Keystroke enter - preset');
|
|
|
|
inp.val('02/04/2008').datepicker('show').
|
2012-03-27 18:46:13 +00:00
|
|
|
simulate('keydown', {ctrlKey: true, keyCode: $.ui.keyCode.HOME}).
|
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
|
2009-02-04 04:27:14 +00:00
|
|
|
equalsDate(inp.datepicker('getDate'), date, 'Keystroke ctrl+home');
|
|
|
|
inp.val('02/04/2008').datepicker('show').
|
2012-03-27 18:46:13 +00:00
|
|
|
simulate('keydown', {ctrlKey: true, keyCode: $.ui.keyCode.END});
|
2009-02-04 04:27:14 +00:00
|
|
|
ok(inp.datepicker('getDate') == null, 'Keystroke ctrl+end');
|
|
|
|
inp.val('').datepicker('show').
|
2012-03-27 18:46:13 +00:00
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.ESCAPE});
|
2009-02-04 04:27:14 +00:00
|
|
|
ok(inp.datepicker('getDate') == null, 'Keystroke esc');
|
|
|
|
inp.val('02/04/2008').datepicker('show').
|
2012-03-27 18:46:13 +00:00
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.ESCAPE});
|
2009-02-04 04:27:14 +00:00
|
|
|
equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4),
|
|
|
|
'Keystroke esc - preset');
|
|
|
|
inp.val('02/04/2008').datepicker('show').
|
2012-03-27 18:46:13 +00:00
|
|
|
simulate('keydown', {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}).
|
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.ESCAPE});
|
2009-02-04 04:27:14 +00:00
|
|
|
equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4),
|
|
|
|
'Keystroke esc - abandoned');
|
|
|
|
// Moving by day or week
|
|
|
|
inp.val('').datepicker('show').
|
2012-03-27 18:46:13 +00:00
|
|
|
simulate('keydown', {ctrlKey: true, keyCode: $.ui.keyCode.LEFT}).
|
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
|
2009-02-04 04:27:14 +00:00
|
|
|
date.setDate(date.getDate() - 1);
|
|
|
|
equalsDate(inp.datepicker('getDate'), date, 'Keystroke ctrl+left');
|
|
|
|
inp.val('').datepicker('show').
|
2012-03-27 18:46:13 +00:00
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.LEFT}).
|
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
|
2009-02-04 04:27:14 +00:00
|
|
|
date.setDate(date.getDate() + 1);
|
|
|
|
equalsDate(inp.datepicker('getDate'), date, 'Keystroke left');
|
|
|
|
inp.val('').datepicker('show').
|
2012-03-27 18:46:13 +00:00
|
|
|
simulate('keydown', {ctrlKey: true, keyCode: $.ui.keyCode.RIGHT}).
|
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
|
2009-02-04 04:27:14 +00:00
|
|
|
date.setDate(date.getDate() + 1);
|
|
|
|
equalsDate(inp.datepicker('getDate'), date, 'Keystroke ctrl+right');
|
|
|
|
inp.val('').datepicker('show').
|
2012-03-27 18:46:13 +00:00
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.RIGHT}).
|
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
|
2009-02-04 04:27:14 +00:00
|
|
|
date.setDate(date.getDate() - 1);
|
|
|
|
equalsDate(inp.datepicker('getDate'), date, 'Keystroke right');
|
|
|
|
inp.val('').datepicker('show').
|
2012-03-27 18:46:13 +00:00
|
|
|
simulate('keydown', {ctrlKey: true, keyCode: $.ui.keyCode.UP}).
|
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
|
2009-02-04 04:27:14 +00:00
|
|
|
date.setDate(date.getDate() - 7);
|
|
|
|
equalsDate(inp.datepicker('getDate'), date, 'Keystroke ctrl+up');
|
|
|
|
inp.val('').datepicker('show').
|
2012-03-27 18:46:13 +00:00
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.UP}).
|
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
|
2009-02-04 04:27:14 +00:00
|
|
|
date.setDate(date.getDate() + 7);
|
|
|
|
equalsDate(inp.datepicker('getDate'), date, 'Keystroke up');
|
|
|
|
inp.val('').datepicker('show').
|
2012-03-27 18:46:13 +00:00
|
|
|
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);
|
|
|
|
equalsDate(inp.datepicker('getDate'), date, 'Keystroke ctrl+down');
|
|
|
|
inp.val('').datepicker('show').
|
2012-03-27 18:46:13 +00:00
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.DOWN}).
|
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
|
2009-02-04 04:27:14 +00:00
|
|
|
date.setDate(date.getDate() - 7);
|
|
|
|
equalsDate(inp.datepicker('getDate'), date, 'Keystroke down');
|
|
|
|
// Moving by month or year
|
|
|
|
inp.val('02/04/2008').datepicker('show').
|
2012-03-27 18:46:13 +00:00
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.PAGE_UP}).
|
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
|
2009-02-04 04:27:14 +00:00
|
|
|
equalsDate(inp.datepicker('getDate'), new Date(2008, 1 - 1, 4),
|
|
|
|
'Keystroke pgup');
|
|
|
|
inp.val('02/04/2008').datepicker('show').
|
2012-03-27 18:46:13 +00:00
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.PAGE_DOWN}).
|
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
|
2009-02-04 04:27:14 +00:00
|
|
|
equalsDate(inp.datepicker('getDate'), new Date(2008, 3 - 1, 4),
|
|
|
|
'Keystroke pgdn');
|
|
|
|
inp.val('02/04/2008').datepicker('show').
|
2012-03-27 18:46:13 +00:00
|
|
|
simulate('keydown', {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}).
|
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
|
2009-02-04 04:27:14 +00:00
|
|
|
equalsDate(inp.datepicker('getDate'), new Date(2007, 2 - 1, 4),
|
|
|
|
'Keystroke ctrl+pgup');
|
|
|
|
inp.val('02/04/2008').datepicker('show').
|
2012-03-27 18:46:13 +00:00
|
|
|
simulate('keydown', {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN}).
|
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
|
2009-02-04 04:27:14 +00:00
|
|
|
equalsDate(inp.datepicker('getDate'), new Date(2009, 2 - 1, 4),
|
|
|
|
'Keystroke ctrl+pgdn');
|
|
|
|
// Check for moving to short months
|
|
|
|
inp.val('03/31/2008').datepicker('show').
|
2012-03-27 18:46:13 +00:00
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.PAGE_UP}).
|
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
|
2009-02-04 04:27:14 +00:00
|
|
|
equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 29),
|
|
|
|
'Keystroke pgup - Feb');
|
|
|
|
inp.val('01/30/2008').datepicker('show').
|
2012-03-27 18:46:13 +00:00
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.PAGE_DOWN}).
|
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
|
2012-02-28 14:56:32 +00:00
|
|
|
equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 29),
|
2009-02-04 04:27:14 +00:00
|
|
|
'Keystroke pgdn - Feb');
|
|
|
|
inp.val('02/29/2008').datepicker('show').
|
2012-03-27 18:46:13 +00:00
|
|
|
simulate('keydown', {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}).
|
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
|
2009-02-04 04:27:14 +00:00
|
|
|
equalsDate(inp.datepicker('getDate'), new Date(2007, 2 - 1, 28),
|
|
|
|
'Keystroke ctrl+pgup - Feb');
|
|
|
|
inp.val('02/29/2008').datepicker('show').
|
2012-03-27 18:46:13 +00:00
|
|
|
simulate('keydown', {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN}).
|
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
|
2009-02-04 04:27:14 +00:00
|
|
|
equalsDate(inp.datepicker('getDate'), new Date(2009, 2 - 1, 28),
|
|
|
|
'Keystroke ctrl+pgdn - Feb');
|
|
|
|
// Goto current
|
|
|
|
inp.datepicker('option', {gotoCurrent: true}).
|
|
|
|
datepicker('hide').val('02/04/2008').datepicker('show').
|
2012-03-27 18:46:13 +00:00
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.PAGE_DOWN}).
|
|
|
|
simulate('keydown', {ctrlKey: true, keyCode: $.ui.keyCode.HOME}).
|
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
|
2009-02-04 04:27:14 +00:00
|
|
|
equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4),
|
|
|
|
'Keystroke ctrl+home');
|
|
|
|
// Change steps
|
|
|
|
inp.datepicker('option', {stepMonths: 2, gotoCurrent: false}).
|
|
|
|
datepicker('hide').val('02/04/2008').datepicker('show').
|
2012-03-27 18:46:13 +00:00
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.PAGE_UP}).
|
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
|
2009-02-04 04:27:14 +00:00
|
|
|
equalsDate(inp.datepicker('getDate'), new Date(2007, 12 - 1, 4),
|
|
|
|
'Keystroke pgup step 2');
|
|
|
|
inp.val('02/04/2008').datepicker('show').
|
2012-03-27 18:46:13 +00:00
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.PAGE_DOWN}).
|
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
|
2009-02-04 04:27:14 +00:00
|
|
|
equalsDate(inp.datepicker('getDate'), new Date(2008, 4 - 1, 4),
|
|
|
|
'Keystroke pgdn step 2');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('mouse', function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 15 );
|
2012-04-19 15:17:35 +00:00
|
|
|
var inl,
|
|
|
|
inp = init('#inp'),
|
|
|
|
dp = $('#ui-datepicker-div'),
|
|
|
|
date = new Date();
|
2009-02-04 04:27:14 +00:00
|
|
|
inp.val('').datepicker('show');
|
|
|
|
$('.ui-datepicker-calendar tbody a:contains(10)', dp).simulate('click', {});
|
|
|
|
date.setDate(10);
|
|
|
|
equalsDate(inp.datepicker('getDate'), date, 'Mouse click');
|
|
|
|
inp.val('02/04/2008').datepicker('show');
|
|
|
|
$('.ui-datepicker-calendar tbody a:contains(12)', dp).simulate('click', {});
|
|
|
|
equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 12),
|
|
|
|
'Mouse click - preset');
|
|
|
|
inp.val('02/04/2008').datepicker('show');
|
|
|
|
inp.val('').datepicker('show');
|
|
|
|
$('button.ui-datepicker-close', dp).simulate('click', {});
|
|
|
|
ok(inp.datepicker('getDate') == null, 'Mouse click - close');
|
|
|
|
inp.val('02/04/2008').datepicker('show');
|
|
|
|
$('button.ui-datepicker-close', dp).simulate('click', {});
|
|
|
|
equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4),
|
|
|
|
'Mouse click - close + preset');
|
|
|
|
inp.val('02/04/2008').datepicker('show');
|
|
|
|
$('a.ui-datepicker-prev', dp).simulate('click', {});
|
|
|
|
$('button.ui-datepicker-close', dp).simulate('click', {});
|
|
|
|
equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4),
|
|
|
|
'Mouse click - abandoned');
|
|
|
|
// Current/previous/next
|
|
|
|
inp.val('02/04/2008').datepicker('option', {showButtonPanel: true}).datepicker('show');
|
|
|
|
$('.ui-datepicker-current', dp).simulate('click', {});
|
|
|
|
$('.ui-datepicker-calendar tbody a:contains(14)', dp).simulate('click', {});
|
|
|
|
date.setDate(14);
|
|
|
|
equalsDate(inp.datepicker('getDate'), date, 'Mouse click - current');
|
|
|
|
inp.val('02/04/2008').datepicker('show');
|
|
|
|
$('.ui-datepicker-prev', dp).simulate('click');
|
|
|
|
$('.ui-datepicker-calendar tbody a:contains(16)', dp).simulate('click');
|
|
|
|
equalsDate(inp.datepicker('getDate'), new Date(2008, 1 - 1, 16),
|
|
|
|
'Mouse click - previous');
|
|
|
|
inp.val('02/04/2008').datepicker('show');
|
|
|
|
$('.ui-datepicker-next', dp).simulate('click');
|
|
|
|
$('.ui-datepicker-calendar tbody a:contains(18)', dp).simulate('click');
|
|
|
|
equalsDate(inp.datepicker('getDate'), new Date(2008, 3 - 1, 18),
|
|
|
|
'Mouse click - next');
|
|
|
|
// Previous/next with minimum/maximum
|
|
|
|
inp.datepicker('option', {minDate: new Date(2008, 2 - 1, 2),
|
|
|
|
maxDate: new Date(2008, 2 - 1, 26)}).val('02/04/2008').datepicker('show');
|
|
|
|
$('.ui-datepicker-prev', dp).simulate('click');
|
|
|
|
$('.ui-datepicker-calendar tbody a:contains(16)', dp).simulate('click');
|
|
|
|
equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 16),
|
|
|
|
'Mouse click - previous + min/max');
|
|
|
|
inp.val('02/04/2008').datepicker('show');
|
|
|
|
$('.ui-datepicker-next', dp).simulate('click');
|
|
|
|
$('.ui-datepicker-calendar tbody a:contains(18)', dp).simulate('click');
|
|
|
|
equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 18),
|
|
|
|
'Mouse click - next + min/max');
|
|
|
|
// Inline
|
2012-04-19 15:17:35 +00:00
|
|
|
inl = init('#inl');
|
|
|
|
dp = $('.ui-datepicker-inline', inl);
|
|
|
|
date = new Date();
|
2009-02-04 04:27:14 +00:00
|
|
|
inl.datepicker('setDate', date);
|
|
|
|
$('.ui-datepicker-calendar tbody a:contains(10)', dp).simulate('click', {});
|
|
|
|
date.setDate(10);
|
|
|
|
equalsDate(inl.datepicker('getDate'), date, 'Mouse click inline');
|
|
|
|
inl.datepicker('option', {showButtonPanel: true}).datepicker('setDate', new Date(2008, 2 - 1, 4));
|
|
|
|
$('.ui-datepicker-calendar tbody a:contains(12)', dp).simulate('click', {});
|
|
|
|
equalsDate(inl.datepicker('getDate'), new Date(2008, 2 - 1, 12), 'Mouse click inline - preset');
|
|
|
|
inl.datepicker('option', {showButtonPanel: true});
|
|
|
|
$('.ui-datepicker-current', dp).simulate('click', {});
|
|
|
|
$('.ui-datepicker-calendar tbody a:contains(14)', dp).simulate('click', {});
|
|
|
|
date.setDate(14);
|
|
|
|
equalsDate(inl.datepicker('getDate'), date, 'Mouse click inline - current');
|
|
|
|
inl.datepicker('setDate', new Date(2008, 2 - 1, 4));
|
|
|
|
$('.ui-datepicker-prev', dp).simulate('click');
|
|
|
|
$('.ui-datepicker-calendar tbody a:contains(16)', dp).simulate('click');
|
|
|
|
equalsDate(inl.datepicker('getDate'), new Date(2008, 1 - 1, 16),
|
|
|
|
'Mouse click inline - previous');
|
|
|
|
inl.datepicker('setDate', new Date(2008, 2 - 1, 4));
|
|
|
|
$('.ui-datepicker-next', dp).simulate('click');
|
|
|
|
$('.ui-datepicker-calendar tbody a:contains(18)', dp).simulate('click');
|
|
|
|
equalsDate(inl.datepicker('getDate'), new Date(2008, 3 - 1, 18),
|
|
|
|
'Mouse click inline - next');
|
2009-02-02 14:36:08 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
})(jQuery);
|