Datepicker: Convert tests to new infrastructure

Ref #10119
Ref gh-1528
This commit is contained in:
Scott González 2015-04-06 20:06:31 -04:00
parent 8bda52c8d1
commit 7d168ce630
6 changed files with 251 additions and 259 deletions

View File

@ -4,32 +4,8 @@
<meta charset="utf-8"> <meta charset="utf-8">
<title>jQuery UI Datepicker Test Suite</title> <title>jQuery UI Datepicker Test Suite</title>
<script src="../../jquery.js"></script> <script src="../../lib/css.js" data-modules="core datepicker"></script>
<link rel="stylesheet" href="../../../external/qunit/qunit.css"> <script src="../../lib/bootstrap.js" data-widget="datepicker"></script>
<script src="../../../external/qunit/qunit.js"></script>
<script src="../../../external/jquery-simulate/jquery.simulate.js"></script>
<script src="../testsuite.js"></script>
<script>
TestHelpers.loadResources({
css: [ "core", "datepicker" ],
js: [
"ui/core.js",
"ui/datepicker.js",
"ui/i18n/datepicker-fr.js",
"ui/i18n/datepicker-he.js",
"ui/i18n/datepicker-zh-CN.js"
]
});
</script>
<script src="datepicker_common.js"></script>
<script src="datepicker_core.js"></script>
<script src="datepicker_events.js"></script>
<script src="datepicker_methods.js"></script>
<script src="datepicker_options.js"></script>
<script src="datepicker_test_helpers.js"></script>
<script src="../swarminject.js"></script>
</head> </head>
<body> <body>

View File

@ -1,8 +1,10 @@
/* define( [
* datepicker_core.js "jquery",
*/ "lib/common",
"./datepicker_test_helpers",
(function($) { "ui/datepicker",
"ui/i18n/datepicker-he"
], function( $, common, datepickerTestHelpers ) {
module( "datepicker: core", { module( "datepicker: core", {
setup: function() { setup: function() {
@ -10,7 +12,7 @@ module( "datepicker: core", {
} }
}); });
TestHelpers.testJshint( "datepicker" ); common.testJshint( "datepicker" );
test("initialization - Reinitialization after body had been emptied.", function() { test("initialization - Reinitialization after body had been emptied.", function() {
expect( 1 ); expect( 1 );
@ -37,11 +39,11 @@ test("widget method", function() {
asyncTest( "baseStructure", function() { asyncTest( "baseStructure", function() {
expect( 58 ); expect( 58 );
var header, title, table, thead, week, panel, inl, child, var header, title, table, thead, week, panel, inl, child,
inp = TestHelpers.datepicker.initNewInput(), inp = datepickerTestHelpers.initNewInput(),
dp = $( "#ui-datepicker-div" ); dp = $( "#ui-datepicker-div" );
function step1() { function step1() {
TestHelpers.datepicker.onFocus( inp, function() { datepickerTestHelpers.onFocus( inp, function() {
ok( dp.is( ":visible" ), "Structure - datepicker visible" ); ok( dp.is( ":visible" ), "Structure - datepicker visible" );
ok( !dp.is( ".ui-datepicker-rtl" ), "Structure - not right-to-left" ); ok( !dp.is( ".ui-datepicker-rtl" ), "Structure - not right-to-left" );
ok( !dp.is( ".ui-datepicker-multi" ), "Structure - not multi-month" ); ok( !dp.is( ".ui-datepicker-multi" ), "Structure - not multi-month" );
@ -82,12 +84,12 @@ asyncTest( "baseStructure", function() {
function step2() { function step2() {
// Editable month/year and button panel // Editable month/year and button panel
inp = TestHelpers.datepicker.initNewInput({ inp = datepickerTestHelpers.initNewInput({
changeMonth: true, changeMonth: true,
changeYear: true, changeYear: true,
showButtonPanel: true showButtonPanel: true
}); });
TestHelpers.datepicker.onFocus( inp, function() { datepickerTestHelpers.onFocus( inp, function() {
title = dp.find( "div.ui-datepicker-title" ); title = dp.find( "div.ui-datepicker-title" );
ok( title.children( ":first" ).is( "select.ui-datepicker-month" ), "Structure - month selector" ); ok( title.children( ":first" ).is( "select.ui-datepicker-month" ), "Structure - month selector" );
ok( title.children( ":last" ).is( "select.ui-datepicker-year" ), "Structure - year selector" ); ok( title.children( ":last" ).is( "select.ui-datepicker-year" ), "Structure - year selector" );
@ -105,8 +107,8 @@ asyncTest( "baseStructure", function() {
function step3() { function step3() {
// Multi-month 2 // Multi-month 2
inp = TestHelpers.datepicker.initNewInput({ numberOfMonths: 2 }); inp = datepickerTestHelpers.initNewInput({ numberOfMonths: 2 });
TestHelpers.datepicker.onFocus( inp, function() { datepickerTestHelpers.onFocus( inp, function() {
ok( dp.is( ".ui-datepicker-multi" ), "Structure multi [2] - multi-month" ); ok( dp.is( ".ui-datepicker-multi" ), "Structure multi [2] - multi-month" );
equal( dp.children().length, 3, "Structure multi [2] - child count" ); equal( dp.children().length, 3, "Structure multi [2] - child count" );
@ -127,8 +129,8 @@ asyncTest( "baseStructure", function() {
function step4() { function step4() {
// Multi-month 3 // Multi-month 3
inp = TestHelpers.datepicker.initNewInput({ numberOfMonths: 3 }); inp = datepickerTestHelpers.initNewInput({ numberOfMonths: 3 });
TestHelpers.datepicker.onFocus( inp, function() { datepickerTestHelpers.onFocus( inp, function() {
ok( dp.is( ".ui-datepicker-multi-3" ), "Structure multi [3] - multi-3" ); ok( dp.is( ".ui-datepicker-multi-3" ), "Structure multi [3] - multi-3" );
ok( !dp.is( ".ui-datepicker-multi-2" ), "Structure multi [3] - Trac #6704" ); ok( !dp.is( ".ui-datepicker-multi-2" ), "Structure multi [3] - Trac #6704" );
@ -139,8 +141,8 @@ asyncTest( "baseStructure", function() {
function step5() { function step5() {
// Multi-month [2, 2] // Multi-month [2, 2]
inp = TestHelpers.datepicker.initNewInput({ numberOfMonths: [ 2, 2 ] }); inp = datepickerTestHelpers.initNewInput({ numberOfMonths: [ 2, 2 ] });
TestHelpers.datepicker.onFocus( inp, function() { datepickerTestHelpers.onFocus( inp, function() {
ok( dp.is( ".ui-datepicker-multi" ), "Structure multi - multi-month" ); ok( dp.is( ".ui-datepicker-multi" ), "Structure multi - multi-month" );
equal( dp.children().length, 6, "Structure multi [2,2] - child count" ); equal( dp.children().length, 6, "Structure multi [2,2] - child count" );
@ -165,7 +167,7 @@ asyncTest( "baseStructure", function() {
inp.datepicker( "hide" ).datepicker( "destroy" ); inp.datepicker( "hide" ).datepicker( "destroy" );
// Inline // Inline
inl = TestHelpers.datepicker.init( "#inl" ); inl = datepickerTestHelpers.init( "#inl" );
dp = inl.children(); dp = inl.children();
ok( dp.is( ".ui-datepicker-inline" ), "Structure inline - main div" ); ok( dp.is( ".ui-datepicker-inline" ), "Structure inline - main div" );
@ -185,7 +187,7 @@ asyncTest( "baseStructure", function() {
inl.datepicker( "destroy" ); inl.datepicker( "destroy" );
// Inline multi-month // Inline multi-month
inl = TestHelpers.datepicker.init( "#inl", { numberOfMonths: 2 } ); inl = datepickerTestHelpers.init( "#inl", { numberOfMonths: 2 } );
dp = inl.children(); dp = inl.children();
ok( dp.is( ".ui-datepicker-inline" ) && dp.is( ".ui-datepicker-multi" ), "Structure inline multi - main div" ); ok( dp.is( ".ui-datepicker-inline" ) && dp.is( ".ui-datepicker-multi" ), "Structure inline multi - main div" );
@ -211,13 +213,13 @@ asyncTest( "baseStructure", function() {
asyncTest( "customStructure", function() { asyncTest( "customStructure", function() {
expect( 20 ); expect( 20 );
var header, panel, title, thead, var header, panel, title, thead,
inp = TestHelpers.datepicker.initNewInput( $.datepicker.regional.he ), inp = datepickerTestHelpers.initNewInput( $.datepicker.regional.he ),
dp = $( "#ui-datepicker-div" ); dp = $( "#ui-datepicker-div" );
function step1() { function step1() {
inp.datepicker( "option", "showButtonPanel", true ); inp.datepicker( "option", "showButtonPanel", true );
TestHelpers.datepicker.onFocus( inp, function() { datepickerTestHelpers.onFocus( inp, function() {
ok( dp.is( ".ui-datepicker-rtl" ), "Structure RTL - right-to-left" ); ok( dp.is( ".ui-datepicker-rtl" ), "Structure RTL - right-to-left" );
header = dp.children( ":first" ); header = dp.children( ":first" );
@ -239,14 +241,14 @@ asyncTest( "customStructure", function() {
// Hide prev/next // Hide prev/next
function step2() { function step2() {
inp = TestHelpers.datepicker.initNewInput({ inp = datepickerTestHelpers.initNewInput({
hideIfNoPrevNext: true, hideIfNoPrevNext: true,
minDate: new Date( 2008, 2 - 1, 4 ), minDate: new Date( 2008, 2 - 1, 4 ),
maxDate: new Date( 2008, 2 - 1, 14 ) maxDate: new Date( 2008, 2 - 1, 14 )
}); });
inp.val( "02/10/2008" ); inp.val( "02/10/2008" );
TestHelpers.datepicker.onFocus( inp, function() { datepickerTestHelpers.onFocus( inp, function() {
header = dp.children( ":first" ); header = dp.children( ":first" );
ok( header.is( "div.ui-datepicker-header" ), "Structure hide prev/next - header division" ); ok( header.is( "div.ui-datepicker-header" ), "Structure hide prev/next - header division" );
equal( header.children().length, 1, "Structure hide prev/next - links child count" ); equal( header.children().length, 1, "Structure hide prev/next - links child count" );
@ -259,9 +261,9 @@ asyncTest( "customStructure", function() {
// Changeable Month with read-only year // Changeable Month with read-only year
function step3() { function step3() {
inp = TestHelpers.datepicker.initNewInput({ changeMonth: true }); inp = datepickerTestHelpers.initNewInput({ changeMonth: true });
TestHelpers.datepicker.onFocus( inp, function() { datepickerTestHelpers.onFocus( inp, function() {
title = dp.children( ":first" ).children( ":last" ); title = dp.children( ":first" ).children( ":last" );
equal( title.children().length, 2, "Structure changeable month - title child count" ); equal( title.children().length, 2, "Structure changeable month - title child count" );
ok( title.children( ":first" ).is( "select.ui-datepicker-month" ), "Structure changeable month - month selector" ); ok( title.children( ":first" ).is( "select.ui-datepicker-month" ), "Structure changeable month - month selector" );
@ -274,9 +276,9 @@ asyncTest( "customStructure", function() {
// Changeable year with read-only month // Changeable year with read-only month
function step4() { function step4() {
inp = TestHelpers.datepicker.initNewInput({ changeYear: true }); inp = datepickerTestHelpers.initNewInput({ changeYear: true });
TestHelpers.datepicker.onFocus( inp, function() { datepickerTestHelpers.onFocus( inp, function() {
title = dp.children( ":first" ).children( ":last" ); title = dp.children( ":first" ).children( ":last" );
equal( title.children().length, 2, "Structure changeable year - title child count" ); equal( title.children().length, 2, "Structure changeable year - title child count" );
ok( title.children( ":first" ).is( "span.ui-datepicker-month" ), "Structure changeable year - read-only month" ); ok( title.children( ":first" ).is( "span.ui-datepicker-month" ), "Structure changeable year - read-only month" );
@ -289,9 +291,9 @@ asyncTest( "customStructure", function() {
// Read-only first day of week // Read-only first day of week
function step5() { function step5() {
inp = TestHelpers.datepicker.initNewInput({ changeFirstDay: false }); inp = datepickerTestHelpers.initNewInput({ changeFirstDay: false });
TestHelpers.datepicker.onFocus( inp, function() { datepickerTestHelpers.onFocus( inp, function() {
thead = dp.find( ".ui-datepicker-calendar thead tr" ); thead = dp.find( ".ui-datepicker-calendar thead tr" );
equal( thead.children().length, 7, "Structure read-only first day - thead child count" ); 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" ); equal( thead.find( "a" ).length, 0, "Structure read-only first day - thead links count" );
@ -309,19 +311,19 @@ asyncTest( "customStructure", function() {
test("keystrokes", function() { test("keystrokes", function() {
expect( 26 ); expect( 26 );
var inp = TestHelpers.datepicker.init("#inp"), var inp = datepickerTestHelpers.init("#inp"),
date = new Date(); date = new Date();
inp.val("").datepicker("show"). inp.val("").datepicker("show").
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Keystroke enter"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), date, "Keystroke enter");
inp.val("02/04/2008").datepicker("show"). inp.val("02/04/2008").datepicker("show").
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), new Date(2008, 2 - 1, 4), datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), new Date(2008, 2 - 1, 4),
"Keystroke enter - preset"); "Keystroke enter - preset");
inp.val("02/04/2008").datepicker("show"). inp.val("02/04/2008").datepicker("show").
simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.HOME}). simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.HOME}).
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Keystroke ctrl+home"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), date, "Keystroke ctrl+home");
inp.val("02/04/2008").datepicker("show"). inp.val("02/04/2008").datepicker("show").
simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.END}); simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.END});
ok(inp.datepicker("getDate") == null, "Keystroke ctrl+end"); ok(inp.datepicker("getDate") == null, "Keystroke ctrl+end");
@ -330,95 +332,95 @@ test("keystrokes", function() {
ok(inp.datepicker("getDate") == null, "Keystroke esc"); ok(inp.datepicker("getDate") == null, "Keystroke esc");
inp.val("02/04/2008").datepicker("show"). inp.val("02/04/2008").datepicker("show").
simulate("keydown", {keyCode: $.ui.keyCode.ESCAPE}); simulate("keydown", {keyCode: $.ui.keyCode.ESCAPE});
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), new Date(2008, 2 - 1, 4), datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), new Date(2008, 2 - 1, 4),
"Keystroke esc - preset"); "Keystroke esc - preset");
inp.val("02/04/2008").datepicker("show"). inp.val("02/04/2008").datepicker("show").
simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}). simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}).
simulate("keydown", {keyCode: $.ui.keyCode.ESCAPE}); simulate("keydown", {keyCode: $.ui.keyCode.ESCAPE});
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), new Date(2008, 2 - 1, 4), datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), new Date(2008, 2 - 1, 4),
"Keystroke esc - abandoned"); "Keystroke esc - abandoned");
// Moving by day or week // Moving by day or week
inp.val("").datepicker("show"). inp.val("").datepicker("show").
simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.LEFT}). simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.LEFT}).
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
date.setDate(date.getDate() - 1); date.setDate(date.getDate() - 1);
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Keystroke ctrl+left"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), date, "Keystroke ctrl+left");
inp.val("").datepicker("show"). inp.val("").datepicker("show").
simulate("keydown", {keyCode: $.ui.keyCode.LEFT}). simulate("keydown", {keyCode: $.ui.keyCode.LEFT}).
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
date.setDate(date.getDate() + 1); date.setDate(date.getDate() + 1);
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Keystroke left"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), date, "Keystroke left");
inp.val("").datepicker("show"). inp.val("").datepicker("show").
simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.RIGHT}). simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.RIGHT}).
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
date.setDate(date.getDate() + 1); date.setDate(date.getDate() + 1);
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Keystroke ctrl+right"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), date, "Keystroke ctrl+right");
inp.val("").datepicker("show"). inp.val("").datepicker("show").
simulate("keydown", {keyCode: $.ui.keyCode.RIGHT}). simulate("keydown", {keyCode: $.ui.keyCode.RIGHT}).
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
date.setDate(date.getDate() - 1); date.setDate(date.getDate() - 1);
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Keystroke right"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), date, "Keystroke right");
inp.val("").datepicker("show"). inp.val("").datepicker("show").
simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.UP}). simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.UP}).
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
date.setDate(date.getDate() - 7); date.setDate(date.getDate() - 7);
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Keystroke ctrl+up"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), date, "Keystroke ctrl+up");
inp.val("").datepicker("show"). inp.val("").datepicker("show").
simulate("keydown", {keyCode: $.ui.keyCode.UP}). simulate("keydown", {keyCode: $.ui.keyCode.UP}).
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
date.setDate(date.getDate() + 7); date.setDate(date.getDate() + 7);
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Keystroke up"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), date, "Keystroke up");
inp.val("").datepicker("show"). inp.val("").datepicker("show").
simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.DOWN}). simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.DOWN}).
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
date.setDate(date.getDate() + 7); date.setDate(date.getDate() + 7);
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Keystroke ctrl+down"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), date, "Keystroke ctrl+down");
inp.val("").datepicker("show"). inp.val("").datepicker("show").
simulate("keydown", {keyCode: $.ui.keyCode.DOWN}). simulate("keydown", {keyCode: $.ui.keyCode.DOWN}).
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
date.setDate(date.getDate() - 7); date.setDate(date.getDate() - 7);
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Keystroke down"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), date, "Keystroke down");
// Moving by month or year // Moving by month or year
inp.val("02/04/2008").datepicker("show"). inp.val("02/04/2008").datepicker("show").
simulate("keydown", {keyCode: $.ui.keyCode.PAGE_UP}). simulate("keydown", {keyCode: $.ui.keyCode.PAGE_UP}).
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), new Date(2008, 1 - 1, 4), datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), new Date(2008, 1 - 1, 4),
"Keystroke pgup"); "Keystroke pgup");
inp.val("02/04/2008").datepicker("show"). inp.val("02/04/2008").datepicker("show").
simulate("keydown", {keyCode: $.ui.keyCode.PAGE_DOWN}). simulate("keydown", {keyCode: $.ui.keyCode.PAGE_DOWN}).
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), new Date(2008, 3 - 1, 4), datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), new Date(2008, 3 - 1, 4),
"Keystroke pgdn"); "Keystroke pgdn");
inp.val("02/04/2008").datepicker("show"). inp.val("02/04/2008").datepicker("show").
simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}). simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}).
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), new Date(2007, 2 - 1, 4), datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), new Date(2007, 2 - 1, 4),
"Keystroke ctrl+pgup"); "Keystroke ctrl+pgup");
inp.val("02/04/2008").datepicker("show"). inp.val("02/04/2008").datepicker("show").
simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN}). simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN}).
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), new Date(2009, 2 - 1, 4), datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), new Date(2009, 2 - 1, 4),
"Keystroke ctrl+pgdn"); "Keystroke ctrl+pgdn");
// Check for moving to short months // Check for moving to short months
inp.val("03/31/2008").datepicker("show"). inp.val("03/31/2008").datepicker("show").
simulate("keydown", {keyCode: $.ui.keyCode.PAGE_UP}). simulate("keydown", {keyCode: $.ui.keyCode.PAGE_UP}).
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), new Date(2008, 2 - 1, 29), datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), new Date(2008, 2 - 1, 29),
"Keystroke pgup - Feb"); "Keystroke pgup - Feb");
inp.val("01/30/2008").datepicker("show"). inp.val("01/30/2008").datepicker("show").
simulate("keydown", {keyCode: $.ui.keyCode.PAGE_DOWN}). simulate("keydown", {keyCode: $.ui.keyCode.PAGE_DOWN}).
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), new Date(2008, 2 - 1, 29), datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), new Date(2008, 2 - 1, 29),
"Keystroke pgdn - Feb"); "Keystroke pgdn - Feb");
inp.val("02/29/2008").datepicker("show"). inp.val("02/29/2008").datepicker("show").
simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}). simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}).
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), new Date(2007, 2 - 1, 28), datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), new Date(2007, 2 - 1, 28),
"Keystroke ctrl+pgup - Feb"); "Keystroke ctrl+pgup - Feb");
inp.val("02/29/2008").datepicker("show"). inp.val("02/29/2008").datepicker("show").
simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN}). simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN}).
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), new Date(2009, 2 - 1, 28), datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), new Date(2009, 2 - 1, 28),
"Keystroke ctrl+pgdn - Feb"); "Keystroke ctrl+pgdn - Feb");
// Goto current // Goto current
inp.datepicker("option", {gotoCurrent: true}). inp.datepicker("option", {gotoCurrent: true}).
@ -426,35 +428,35 @@ test("keystrokes", function() {
simulate("keydown", {keyCode: $.ui.keyCode.PAGE_DOWN}). simulate("keydown", {keyCode: $.ui.keyCode.PAGE_DOWN}).
simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.HOME}). simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.HOME}).
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), new Date(2008, 2 - 1, 4), datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), new Date(2008, 2 - 1, 4),
"Keystroke ctrl+home"); "Keystroke ctrl+home");
// Change steps // Change steps
inp.datepicker("option", {stepMonths: 2, gotoCurrent: false}). inp.datepicker("option", {stepMonths: 2, gotoCurrent: false}).
datepicker("hide").val("02/04/2008").datepicker("show"). datepicker("hide").val("02/04/2008").datepicker("show").
simulate("keydown", {keyCode: $.ui.keyCode.PAGE_UP}). simulate("keydown", {keyCode: $.ui.keyCode.PAGE_UP}).
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), new Date(2007, 12 - 1, 4), datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), new Date(2007, 12 - 1, 4),
"Keystroke pgup step 2"); "Keystroke pgup step 2");
inp.val("02/04/2008").datepicker("show"). inp.val("02/04/2008").datepicker("show").
simulate("keydown", {keyCode: $.ui.keyCode.PAGE_DOWN}). simulate("keydown", {keyCode: $.ui.keyCode.PAGE_DOWN}).
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), new Date(2008, 4 - 1, 4), datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), new Date(2008, 4 - 1, 4),
"Keystroke pgdn step 2"); "Keystroke pgdn step 2");
}); });
test("mouse", function() { test("mouse", function() {
expect( 15 ); expect( 15 );
var inl, var inl,
inp = TestHelpers.datepicker.init("#inp"), inp = datepickerTestHelpers.init("#inp"),
dp = $("#ui-datepicker-div"), dp = $("#ui-datepicker-div"),
date = new Date(); date = new Date();
inp.val("").datepicker("show"); inp.val("").datepicker("show");
$(".ui-datepicker-calendar tbody a:contains(10)", dp).simulate("click", {}); $(".ui-datepicker-calendar tbody a:contains(10)", dp).simulate("click", {});
date.setDate(10); date.setDate(10);
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Mouse click"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), date, "Mouse click");
inp.val("02/04/2008").datepicker("show"); inp.val("02/04/2008").datepicker("show");
$(".ui-datepicker-calendar tbody a:contains(12)", dp).simulate("click", {}); $(".ui-datepicker-calendar tbody a:contains(12)", dp).simulate("click", {});
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), new Date(2008, 2 - 1, 12), datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), new Date(2008, 2 - 1, 12),
"Mouse click - preset"); "Mouse click - preset");
inp.val("02/04/2008").datepicker("show"); inp.val("02/04/2008").datepicker("show");
inp.val("").datepicker("show"); inp.val("").datepicker("show");
@ -462,67 +464,67 @@ test("mouse", function() {
ok(inp.datepicker("getDate") == null, "Mouse click - close"); ok(inp.datepicker("getDate") == null, "Mouse click - close");
inp.val("02/04/2008").datepicker("show"); inp.val("02/04/2008").datepicker("show");
$("button.ui-datepicker-close", dp).simulate("click", {}); $("button.ui-datepicker-close", dp).simulate("click", {});
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), new Date(2008, 2 - 1, 4), datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), new Date(2008, 2 - 1, 4),
"Mouse click - close + preset"); "Mouse click - close + preset");
inp.val("02/04/2008").datepicker("show"); inp.val("02/04/2008").datepicker("show");
$("a.ui-datepicker-prev", dp).simulate("click", {}); $("a.ui-datepicker-prev", dp).simulate("click", {});
$("button.ui-datepicker-close", dp).simulate("click", {}); $("button.ui-datepicker-close", dp).simulate("click", {});
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), new Date(2008, 2 - 1, 4), datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), 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("show"); inp.val("02/04/2008").datepicker("option", {showButtonPanel: true}).datepicker("show");
$(".ui-datepicker-current", dp).simulate("click", {}); $(".ui-datepicker-current", dp).simulate("click", {});
$(".ui-datepicker-calendar tbody a:contains(14)", dp).simulate("click", {}); $(".ui-datepicker-calendar tbody a:contains(14)", dp).simulate("click", {});
date.setDate(14); date.setDate(14);
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Mouse click - current"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), date, "Mouse click - current");
inp.val("02/04/2008").datepicker("show"); inp.val("02/04/2008").datepicker("show");
$(".ui-datepicker-prev", dp).simulate("click"); $(".ui-datepicker-prev", dp).simulate("click");
$(".ui-datepicker-calendar tbody a:contains(16)", dp).simulate("click"); $(".ui-datepicker-calendar tbody a:contains(16)", dp).simulate("click");
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), new Date(2008, 1 - 1, 16), datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), new Date(2008, 1 - 1, 16),
"Mouse click - previous"); "Mouse click - previous");
inp.val("02/04/2008").datepicker("show"); inp.val("02/04/2008").datepicker("show");
$(".ui-datepicker-next", dp).simulate("click"); $(".ui-datepicker-next", dp).simulate("click");
$(".ui-datepicker-calendar tbody a:contains(18)", dp).simulate("click"); $(".ui-datepicker-calendar tbody a:contains(18)", dp).simulate("click");
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), new Date(2008, 3 - 1, 18), datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), new Date(2008, 3 - 1, 18),
"Mouse click - next"); "Mouse click - next");
// Previous/next with minimum/maximum // Previous/next with minimum/maximum
inp.datepicker("option", {minDate: new Date(2008, 2 - 1, 2), inp.datepicker("option", {minDate: new Date(2008, 2 - 1, 2),
maxDate: new Date(2008, 2 - 1, 26)}).val("02/04/2008").datepicker("show"); maxDate: new Date(2008, 2 - 1, 26)}).val("02/04/2008").datepicker("show");
$(".ui-datepicker-prev", dp).simulate("click"); $(".ui-datepicker-prev", dp).simulate("click");
$(".ui-datepicker-calendar tbody a:contains(16)", dp).simulate("click"); $(".ui-datepicker-calendar tbody a:contains(16)", dp).simulate("click");
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), new Date(2008, 2 - 1, 16), datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), new Date(2008, 2 - 1, 16),
"Mouse click - previous + min/max"); "Mouse click - previous + min/max");
inp.val("02/04/2008").datepicker("show"); inp.val("02/04/2008").datepicker("show");
$(".ui-datepicker-next", dp).simulate("click"); $(".ui-datepicker-next", dp).simulate("click");
$(".ui-datepicker-calendar tbody a:contains(18)", dp).simulate("click"); $(".ui-datepicker-calendar tbody a:contains(18)", dp).simulate("click");
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), new Date(2008, 2 - 1, 18), datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), new Date(2008, 2 - 1, 18),
"Mouse click - next + min/max"); "Mouse click - next + min/max");
// Inline // Inline
inl = TestHelpers.datepicker.init("#inl"); inl = datepickerTestHelpers.init("#inl");
dp = $(".ui-datepicker-inline", inl); dp = $(".ui-datepicker-inline", inl);
date = new Date(); date = new Date();
inl.datepicker("setDate", date); inl.datepicker("setDate", date);
$(".ui-datepicker-calendar tbody a:contains(10)", dp).simulate("click", {}); $(".ui-datepicker-calendar tbody a:contains(10)", dp).simulate("click", {});
date.setDate(10); date.setDate(10);
TestHelpers.datepicker.equalsDate(inl.datepicker("getDate"), date, "Mouse click inline"); datepickerTestHelpers.equalsDate(inl.datepicker("getDate"), date, "Mouse click inline");
inl.datepicker("option", {showButtonPanel: true}).datepicker("setDate", new Date(2008, 2 - 1, 4)); inl.datepicker("option", {showButtonPanel: true}).datepicker("setDate", new Date(2008, 2 - 1, 4));
$(".ui-datepicker-calendar tbody a:contains(12)", dp).simulate("click", {}); $(".ui-datepicker-calendar tbody a:contains(12)", dp).simulate("click", {});
TestHelpers.datepicker.equalsDate(inl.datepicker("getDate"), new Date(2008, 2 - 1, 12), "Mouse click inline - preset"); datepickerTestHelpers.equalsDate(inl.datepicker("getDate"), new Date(2008, 2 - 1, 12), "Mouse click inline - preset");
inl.datepicker("option", {showButtonPanel: true}); inl.datepicker("option", {showButtonPanel: true});
$(".ui-datepicker-current", dp).simulate("click", {}); $(".ui-datepicker-current", dp).simulate("click", {});
$(".ui-datepicker-calendar tbody a:contains(14)", dp).simulate("click", {}); $(".ui-datepicker-calendar tbody a:contains(14)", dp).simulate("click", {});
date.setDate(14); date.setDate(14);
TestHelpers.datepicker.equalsDate(inl.datepicker("getDate"), date, "Mouse click inline - current"); datepickerTestHelpers.equalsDate(inl.datepicker("getDate"), date, "Mouse click inline - current");
inl.datepicker("setDate", new Date(2008, 2 - 1, 4)); inl.datepicker("setDate", new Date(2008, 2 - 1, 4));
$(".ui-datepicker-prev", dp).simulate("click"); $(".ui-datepicker-prev", dp).simulate("click");
$(".ui-datepicker-calendar tbody a:contains(16)", dp).simulate("click"); $(".ui-datepicker-calendar tbody a:contains(16)", dp).simulate("click");
TestHelpers.datepicker.equalsDate(inl.datepicker("getDate"), new Date(2008, 1 - 1, 16), datepickerTestHelpers.equalsDate(inl.datepicker("getDate"), new Date(2008, 1 - 1, 16),
"Mouse click inline - previous"); "Mouse click inline - previous");
inl.datepicker("setDate", new Date(2008, 2 - 1, 4)); inl.datepicker("setDate", new Date(2008, 2 - 1, 4));
$(".ui-datepicker-next", dp).simulate("click"); $(".ui-datepicker-next", dp).simulate("click");
$(".ui-datepicker-calendar tbody a:contains(18)", dp).simulate("click"); $(".ui-datepicker-calendar tbody a:contains(18)", dp).simulate("click");
TestHelpers.datepicker.equalsDate(inl.datepicker("getDate"), new Date(2008, 3 - 1, 18), datepickerTestHelpers.equalsDate(inl.datepicker("getDate"), new Date(2008, 3 - 1, 18),
"Mouse click inline - next"); "Mouse click inline - next");
}); });
})(jQuery); } );

View File

@ -1,7 +1,8 @@
/* define( [
* datepicker_events.js "jquery",
*/ "./datepicker_test_helpers",
(function($) { "ui/datepicker"
], function( $, datepickerTestHelpers ) {
module("datepicker: events"); module("datepicker: events");
@ -24,13 +25,13 @@ function callback2(year, month, inst) {
test("events", function() { test("events", function() {
expect( 26 ); expect( 26 );
var dateStr, newMonthYear, inp2, var dateStr, newMonthYear, inp2,
inp = TestHelpers.datepicker.init("#inp", {onSelect: callback}), inp = datepickerTestHelpers.init("#inp", {onSelect: callback}),
date = new Date(); date = new Date();
// onSelect // onSelect
inp.val("").datepicker("show"). inp.val("").datepicker("show").
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
equal(selectedThis, inp[0], "Callback selected this"); equal(selectedThis, inp[0], "Callback selected this");
equal(selectedInst, $.data(inp[0], TestHelpers.datepicker.PROP_NAME), "Callback selected inst"); equal(selectedInst, $.data(inp[0], datepickerTestHelpers.PROP_NAME), "Callback selected inst");
equal(selectedDate, $.datepicker.formatDate("mm/dd/yy", date), equal(selectedDate, $.datepicker.formatDate("mm/dd/yy", date),
"Callback selected date"); "Callback selected date");
inp.val("").datepicker("show"). inp.val("").datepicker("show").
@ -59,7 +60,7 @@ test("events", function() {
inp.simulate("keydown", {keyCode: $.ui.keyCode.PAGE_UP}); inp.simulate("keydown", {keyCode: $.ui.keyCode.PAGE_UP});
date.setMonth(date.getMonth() - 1); date.setMonth(date.getMonth() - 1);
equal(selectedThis, inp[0], "Callback change month/year this"); equal(selectedThis, inp[0], "Callback change month/year this");
equal(selectedInst, $.data(inp[0], TestHelpers.datepicker.PROP_NAME), "Callback change month/year inst"); equal(selectedInst, $.data(inp[0], datepickerTestHelpers.PROP_NAME), "Callback change month/year inst");
equal(selectedDate, newMonthYear(date), equal(selectedDate, newMonthYear(date),
"Callback change month/year date - pgup"); "Callback change month/year date - pgup");
inp.simulate("keydown", {keyCode: $.ui.keyCode.PAGE_DOWN}); inp.simulate("keydown", {keyCode: $.ui.keyCode.PAGE_DOWN});
@ -107,7 +108,7 @@ test("events", function() {
val("").datepicker("show"). val("").datepicker("show").
simulate("keydown", {keyCode: $.ui.keyCode.ESCAPE}); simulate("keydown", {keyCode: $.ui.keyCode.ESCAPE});
equal(selectedThis, inp[0], "Callback close this"); equal(selectedThis, inp[0], "Callback close this");
equal(selectedInst, $.data(inp[0], TestHelpers.datepicker.PROP_NAME), "Callback close inst"); equal(selectedInst, $.data(inp[0], datepickerTestHelpers.PROP_NAME), "Callback close inst");
equal(selectedDate, "", "Callback close date - esc"); equal(selectedDate, "", "Callback close date - esc");
inp.val("").datepicker("show"). inp.val("").datepicker("show").
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
@ -120,7 +121,7 @@ test("events", function() {
simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.END}); simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.END});
equal(selectedDate, "", "Callback close date - ctrl+end"); equal(selectedDate, "", "Callback close date - ctrl+end");
inp2 = TestHelpers.datepicker.init("#inp2"); inp2 = datepickerTestHelpers.init("#inp2");
inp2.datepicker().datepicker("option", {onClose: callback}).datepicker("show"); inp2.datepicker().datepicker("option", {onClose: callback}).datepicker("show");
inp.datepicker("show"); inp.datepicker("show");
equal(selectedThis, inp2[0], "Callback close this"); equal(selectedThis, inp2[0], "Callback close this");
@ -128,7 +129,7 @@ test("events", function() {
test("beforeShowDay-getDate", function() { test("beforeShowDay-getDate", function() {
expect( 3 ); expect( 3 );
var inp = TestHelpers.datepicker.init("#inp", {beforeShowDay: function() { inp.datepicker("getDate"); return [true, ""]; }}), var inp = datepickerTestHelpers.init("#inp", {beforeShowDay: function() { inp.datepicker("getDate"); return [true, ""]; }}),
dp = $("#ui-datepicker-div"); dp = $("#ui-datepicker-div");
inp.val("01/01/2010").datepicker("show"); inp.val("01/01/2010").datepicker("show");
// contains non-breaking space // contains non-breaking space
@ -150,4 +151,4 @@ test("beforeShowDay-getDate", function() {
inp.datepicker("hide"); inp.datepicker("hide");
}); });
})(jQuery); } );

View File

@ -1,72 +1,73 @@
/* define( [
* datepicker_methods.js "jquery",
*/ "./datepicker_test_helpers",
(function($) { "ui/datepicker"
], function( $, datepickerTestHelpers ) {
module("datepicker: methods"); module("datepicker: methods");
test("destroy", function() { test("destroy", function() {
expect( 33 ); expect( 33 );
var inl, var inl,
inp = TestHelpers.datepicker.init("#inp"); inp = datepickerTestHelpers.init("#inp");
ok(inp.is(".hasDatepicker"), "Default - marker class set"); ok(inp.is(".hasDatepicker"), "Default - marker class set");
ok($.data(inp[0], TestHelpers.datepicker.PROP_NAME), "Default - instance present"); ok($.data(inp[0], datepickerTestHelpers.PROP_NAME), "Default - instance present");
ok(inp.next().is("#alt"), "Default - button absent"); ok(inp.next().is("#alt"), "Default - button absent");
inp.datepicker("destroy"); inp.datepicker("destroy");
inp = $("#inp"); inp = $("#inp");
ok(!inp.is(".hasDatepicker"), "Default - marker class cleared"); ok(!inp.is(".hasDatepicker"), "Default - marker class cleared");
ok(!$.data(inp[0], TestHelpers.datepicker.PROP_NAME), "Default - instance absent"); ok(!$.data(inp[0], datepickerTestHelpers.PROP_NAME), "Default - instance absent");
ok(inp.next().is("#alt"), "Default - button absent"); ok(inp.next().is("#alt"), "Default - button absent");
// With button // With button
inp= TestHelpers.datepicker.init("#inp", {showOn: "both"}); inp= datepickerTestHelpers.init("#inp", {showOn: "both"});
ok(inp.is(".hasDatepicker"), "Button - marker class set"); ok(inp.is(".hasDatepicker"), "Button - marker class set");
ok($.data(inp[0], TestHelpers.datepicker.PROP_NAME), "Button - instance present"); ok($.data(inp[0], datepickerTestHelpers.PROP_NAME), "Button - instance present");
ok(inp.next().text() === "...", "Button - button added"); ok(inp.next().text() === "...", "Button - button added");
inp.datepicker("destroy"); inp.datepicker("destroy");
inp = $("#inp"); inp = $("#inp");
ok(!inp.is(".hasDatepicker"), "Button - marker class cleared"); ok(!inp.is(".hasDatepicker"), "Button - marker class cleared");
ok(!$.data(inp[0], TestHelpers.datepicker.PROP_NAME), "Button - instance absent"); ok(!$.data(inp[0], datepickerTestHelpers.PROP_NAME), "Button - instance absent");
ok(inp.next().is("#alt"), "Button - button removed"); ok(inp.next().is("#alt"), "Button - button removed");
// With append text // With append text
inp = TestHelpers.datepicker.init("#inp", {appendText: "Testing"}); inp = datepickerTestHelpers.init("#inp", {appendText: "Testing"});
ok(inp.is(".hasDatepicker"), "Append - marker class set"); ok(inp.is(".hasDatepicker"), "Append - marker class set");
ok($.data(inp[0], TestHelpers.datepicker.PROP_NAME), "Append - instance present"); ok($.data(inp[0], datepickerTestHelpers.PROP_NAME), "Append - instance present");
ok(inp.next().text() === "Testing", "Append - append text added"); ok(inp.next().text() === "Testing", "Append - append text added");
inp.datepicker("destroy"); inp.datepicker("destroy");
inp = $("#inp"); inp = $("#inp");
ok(!inp.is(".hasDatepicker"), "Append - marker class cleared"); ok(!inp.is(".hasDatepicker"), "Append - marker class cleared");
ok(!$.data(inp[0], TestHelpers.datepicker.PROP_NAME), "Append - instance absent"); ok(!$.data(inp[0], datepickerTestHelpers.PROP_NAME), "Append - instance absent");
ok(inp.next().is("#alt"), "Append - append text removed"); ok(inp.next().is("#alt"), "Append - append text removed");
// With both // With both
inp= TestHelpers.datepicker.init("#inp", {showOn: "both", buttonImageOnly: true, inp= datepickerTestHelpers.init("#inp", {showOn: "both", buttonImageOnly: true,
buttonImage: "images/calendar.gif", appendText: "Testing"}); buttonImage: "images/calendar.gif", appendText: "Testing"});
ok(inp.is(".hasDatepicker"), "Both - marker class set"); ok(inp.is(".hasDatepicker"), "Both - marker class set");
ok($.data(inp[0], TestHelpers.datepicker.PROP_NAME), "Both - instance present"); ok($.data(inp[0], datepickerTestHelpers.PROP_NAME), "Both - instance present");
ok(inp.next()[0].nodeName.toLowerCase() === "img", "Both - button added"); ok(inp.next()[0].nodeName.toLowerCase() === "img", "Both - button added");
ok(inp.next().next().text() === "Testing", "Both - append text added"); ok(inp.next().next().text() === "Testing", "Both - append text added");
inp.datepicker("destroy"); inp.datepicker("destroy");
inp = $("#inp"); inp = $("#inp");
ok(!inp.is(".hasDatepicker"), "Both - marker class cleared"); ok(!inp.is(".hasDatepicker"), "Both - marker class cleared");
ok(!$.data(inp[0], TestHelpers.datepicker.PROP_NAME), "Both - instance absent"); ok(!$.data(inp[0], datepickerTestHelpers.PROP_NAME), "Both - instance absent");
ok(inp.next().is("#alt"), "Both - button and append text absent"); ok(inp.next().is("#alt"), "Both - button and append text absent");
// Inline // Inline
inl = TestHelpers.datepicker.init("#inl"); inl = datepickerTestHelpers.init("#inl");
ok(inl.is(".hasDatepicker"), "Inline - marker class set"); ok(inl.is(".hasDatepicker"), "Inline - marker class set");
ok(inl.html() !== "", "Inline - datepicker present"); ok(inl.html() !== "", "Inline - datepicker present");
ok($.data(inl[0], TestHelpers.datepicker.PROP_NAME), "Inline - instance present"); ok($.data(inl[0], datepickerTestHelpers.PROP_NAME), "Inline - instance present");
ok(inl.next().length === 0 || inl.next().is("p"), "Inline - button absent"); ok(inl.next().length === 0 || inl.next().is("p"), "Inline - button absent");
inl.datepicker("destroy"); inl.datepicker("destroy");
inl = $("#inl"); inl = $("#inl");
ok(!inl.is(".hasDatepicker"), "Inline - marker class cleared"); ok(!inl.is(".hasDatepicker"), "Inline - marker class cleared");
ok(inl.html() === "", "Inline - datepicker absent"); ok(inl.html() === "", "Inline - datepicker absent");
ok(!$.data(inl[0], TestHelpers.datepicker.PROP_NAME), "Inline - instance absent"); ok(!$.data(inl[0], datepickerTestHelpers.PROP_NAME), "Inline - instance absent");
ok(inl.next().length === 0 || inl.next().is("p"), "Inline - button absent"); ok(inl.next().length === 0 || inl.next().is("p"), "Inline - button absent");
}); });
test("enableDisable", function() { test("enableDisable", function() {
expect( 33 ); expect( 33 );
var inl, dp, var inl, dp,
inp = TestHelpers.datepicker.init("#inp"); inp = datepickerTestHelpers.init("#inp");
ok(!inp.datepicker("isDisabled"), "Enable/disable - initially marked as enabled"); ok(!inp.datepicker("isDisabled"), "Enable/disable - initially marked as enabled");
ok(!inp[0].disabled, "Enable/disable - field initially enabled"); ok(!inp[0].disabled, "Enable/disable - field initially enabled");
inp.datepicker("disable"); inp.datepicker("disable");
@ -77,7 +78,7 @@ test("enableDisable", function() {
ok(!inp[0].disabled, "Enable/disable - field now enabled"); ok(!inp[0].disabled, "Enable/disable - field now enabled");
inp.datepicker("destroy"); inp.datepicker("destroy");
// With a button // With a button
inp = TestHelpers.datepicker.init("#inp", {showOn: "button"}); inp = datepickerTestHelpers.init("#inp", {showOn: "button"});
ok(!inp.datepicker("isDisabled"), "Enable/disable button - initially marked as enabled"); ok(!inp.datepicker("isDisabled"), "Enable/disable button - initially marked as enabled");
ok(!inp[0].disabled, "Enable/disable button - field initially enabled"); ok(!inp[0].disabled, "Enable/disable button - field initially enabled");
ok(!inp.next("button")[0].disabled, "Enable/disable button - button initially enabled"); ok(!inp.next("button")[0].disabled, "Enable/disable button - button initially enabled");
@ -91,7 +92,7 @@ test("enableDisable", function() {
ok(!inp.next("button")[0].disabled, "Enable/disable button - button now enabled"); ok(!inp.next("button")[0].disabled, "Enable/disable button - button now enabled");
inp.datepicker("destroy"); inp.datepicker("destroy");
// With an image button // With an image button
inp = TestHelpers.datepicker.init("#inp", {showOn: "button", buttonImageOnly: true, inp = datepickerTestHelpers.init("#inp", {showOn: "button", buttonImageOnly: true,
buttonImage: "images/calendar.gif"}); buttonImage: "images/calendar.gif"});
ok(!inp.datepicker("isDisabled"), "Enable/disable image - initially marked as enabled"); ok(!inp.datepicker("isDisabled"), "Enable/disable image - initially marked as enabled");
ok(!inp[0].disabled, "Enable/disable image - field initially enabled"); ok(!inp[0].disabled, "Enable/disable image - field initially enabled");
@ -106,7 +107,7 @@ test("enableDisable", function() {
ok(parseFloat(inp.next("img").css("opacity")) === 1, "Enable/disable image - image now enabled"); ok(parseFloat(inp.next("img").css("opacity")) === 1, "Enable/disable image - image now enabled");
inp.datepicker("destroy"); inp.datepicker("destroy");
// Inline // Inline
inl = TestHelpers.datepicker.init("#inl", {changeYear: true}); inl = datepickerTestHelpers.init("#inl", {changeYear: true});
dp = $(".ui-datepicker-inline", inl); dp = $(".ui-datepicker-inline", inl);
ok(!inl.datepicker("isDisabled"), "Enable/disable inline - initially marked as enabled"); ok(!inl.datepicker("isDisabled"), "Enable/disable inline - initially marked as enabled");
ok(!dp.children().is(".ui-state-disabled"), "Enable/disable inline - not visually disabled initially"); ok(!dp.children().is(".ui-state-disabled"), "Enable/disable inline - not visually disabled initially");
@ -122,4 +123,4 @@ test("enableDisable", function() {
inl.datepicker("destroy"); inl.datepicker("destroy");
}); });
})(jQuery); } );

View File

@ -1,14 +1,17 @@
/* define( [
* datepicker_options.js "jquery",
*/ "./datepicker_test_helpers",
"ui/datepicker",
(function($) { "ui/i18n/datepicker-fr",
"ui/i18n/datepicker-he",
"ui/i18n/datepicker-zh-CN"
], function( $, datepickerTestHelpers ) {
module("datepicker: options"); module("datepicker: options");
test("setDefaults", function() { test("setDefaults", function() {
expect( 3 ); expect( 3 );
TestHelpers.datepicker.init("#inp"); datepickerTestHelpers.init("#inp");
equal($.datepicker._defaults.showOn, "focus", "Initial showOn"); equal($.datepicker._defaults.showOn, "focus", "Initial showOn");
$.datepicker.setDefaults({showOn: "button"}); $.datepicker.setDefaults({showOn: "button"});
equal($.datepicker._defaults.showOn, "button", "Change default showOn"); equal($.datepicker._defaults.showOn, "button", "Change default showOn");
@ -18,8 +21,8 @@ test("setDefaults", function() {
test("option", function() { test("option", function() {
expect( 17 ); expect( 17 );
var inp = TestHelpers.datepicker.init("#inp"), var inp = datepickerTestHelpers.init("#inp"),
inst = $.data(inp[0], TestHelpers.datepicker.PROP_NAME); inst = $.data(inp[0], datepickerTestHelpers.PROP_NAME);
// Set option // Set option
equal(inst.settings.showOn, null, "Initial setting showOn"); equal(inst.settings.showOn, null, "Initial setting showOn");
equal($.datepicker._get(inst, "showOn"), "focus", "Initial instance showOn"); equal($.datepicker._get(inst, "showOn"), "focus", "Initial instance showOn");
@ -37,7 +40,7 @@ test("option", function() {
equal($.datepicker._get(inst, "showOn"), "focus", "Restore instance showOn"); equal($.datepicker._get(inst, "showOn"), "focus", "Restore instance showOn");
equal($.datepicker._defaults.showOn, "focus", "Retain default showOn"); equal($.datepicker._defaults.showOn, "focus", "Retain default showOn");
// Get option // Get option
inp = TestHelpers.datepicker.init("#inp"); inp = datepickerTestHelpers.init("#inp");
equal(inp.datepicker("option", "showOn"), "focus", "Initial setting showOn"); equal(inp.datepicker("option", "showOn"), "focus", "Initial setting showOn");
inp.datepicker("option", "showOn", "button"); inp.datepicker("option", "showOn", "button");
equal(inp.datepicker("option", "showOn"), "button", "Change instance showOn"); equal(inp.datepicker("option", "showOn"), "button", "Change instance showOn");
@ -50,7 +53,7 @@ test("option", function() {
test( "disabled", function() { test( "disabled", function() {
expect(8); expect(8);
var inp = TestHelpers.datepicker.init("#inp"); var inp = datepickerTestHelpers.init("#inp");
ok(!inp.datepicker("isDisabled"), "Initially marked as enabled"); ok(!inp.datepicker("isDisabled"), "Initially marked as enabled");
ok(!inp[0].disabled, "Field initially enabled"); ok(!inp[0].disabled, "Field initially enabled");
inp.datepicker("option", "disabled", true); inp.datepicker("option", "disabled", true);
@ -61,15 +64,15 @@ test( "disabled", function() {
ok(!inp[0].disabled, "Field now enabled"); ok(!inp[0].disabled, "Field now enabled");
inp.datepicker("destroy"); inp.datepicker("destroy");
inp = TestHelpers.datepicker.init("#inp", { disabled: true }); inp = datepickerTestHelpers.init("#inp", { disabled: true });
ok(inp.datepicker("isDisabled"), "Initially marked as disabled"); ok(inp.datepicker("isDisabled"), "Initially marked as disabled");
ok(inp[0].disabled, "Field initially disabled"); ok(inp[0].disabled, "Field initially disabled");
}); });
test("change", function() { test("change", function() {
expect( 12 ); expect( 12 );
var inp = TestHelpers.datepicker.init("#inp"), var inp = datepickerTestHelpers.init("#inp"),
inst = $.data(inp[0], TestHelpers.datepicker.PROP_NAME); inst = $.data(inp[0], datepickerTestHelpers.PROP_NAME);
equal(inst.settings.showOn, null, "Initial setting showOn"); equal(inst.settings.showOn, null, "Initial setting showOn");
equal($.datepicker._get(inst, "showOn"), "focus", "Initial instance showOn"); equal($.datepicker._get(inst, "showOn"), "focus", "Initial instance showOn");
equal($.datepicker._defaults.showOn, "focus", "Initial default showOn"); equal($.datepicker._defaults.showOn, "focus", "Initial default showOn");
@ -104,7 +107,7 @@ test("change", function() {
expect( isOldIE ? 25 : 29 ); expect( isOldIE ? 25 : 29 );
function step0() { function step0() {
var inp = TestHelpers.datepicker.initNewInput(), var inp = datepickerTestHelpers.initNewInput(),
dp = $( "#ui-datepicker-div" ); dp = $( "#ui-datepicker-div" );
button = inp.siblings( "button" ); button = inp.siblings( "button" );
@ -112,7 +115,7 @@ test("change", function() {
image = inp.siblings( "img" ); image = inp.siblings( "img" );
ok( image.length === 0, "Focus - image absent" ); ok( image.length === 0, "Focus - image absent" );
TestHelpers.datepicker.onFocus( inp, function() { datepickerTestHelpers.onFocus( inp, function() {
ok( dp.is( ":visible" ), "Focus - rendered on focus" ); ok( dp.is( ":visible" ), "Focus - rendered on focus" );
inp.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } ); inp.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
ok( !dp.is( ":visible" ), "Focus - hidden on exit" ); ok( !dp.is( ":visible" ), "Focus - hidden on exit" );
@ -122,10 +125,10 @@ test("change", function() {
function step1() { function step1() {
var inp = TestHelpers.datepicker.initNewInput(), var inp = datepickerTestHelpers.initNewInput(),
dp = $( "#ui-datepicker-div" ); dp = $( "#ui-datepicker-div" );
TestHelpers.datepicker.onFocus( inp, function() { datepickerTestHelpers.onFocus( inp, function() {
ok( dp.is( ":visible" ), "Focus - rendered on focus" ); ok( dp.is( ":visible" ), "Focus - rendered on focus" );
body.simulate( "mousedown", {} ); body.simulate( "mousedown", {} );
ok( !dp.is( ":visible" ), "Focus - hidden on external click" ); ok( !dp.is( ":visible" ), "Focus - hidden on external click" );
@ -136,7 +139,7 @@ test("change", function() {
} }
function step2() { function step2() {
var inp = TestHelpers.datepicker.initNewInput({ var inp = datepickerTestHelpers.initNewInput({
showOn: "button", showOn: "button",
buttonText: "Popup" buttonText: "Popup"
}), }),
@ -149,7 +152,7 @@ test("change", function() {
ok( image.length === 0, "Button - image absent" ); ok( image.length === 0, "Button - image absent" );
equal( button.text(), "Popup", "Button - button text" ); equal( button.text(), "Popup", "Button - button text" );
TestHelpers.datepicker.onFocus( inp, function() { datepickerTestHelpers.onFocus( inp, function() {
ok( !dp.is( ":visible" ), "Button - not rendered on focus" ); ok( !dp.is( ":visible" ), "Button - not rendered on focus" );
button.click(); button.click();
ok( dp.is( ":visible" ), "Button - rendered on button click" ); ok( dp.is( ":visible" ), "Button - rendered on button click" );
@ -162,7 +165,7 @@ test("change", function() {
} }
function step3() { function step3() {
var inp = TestHelpers.datepicker.initNewInput({ var inp = datepickerTestHelpers.initNewInput({
showOn: "button", showOn: "button",
buttonImageOnly: true, buttonImageOnly: true,
buttonImage: "images/calendar.gif", buttonImage: "images/calendar.gif",
@ -178,7 +181,7 @@ test("change", function() {
ok( /images\/calendar\.gif$/.test( image.attr( "src" ) ), "Image button - image source" ); ok( /images\/calendar\.gif$/.test( image.attr( "src" ) ), "Image button - image source" );
equal( image.attr( "title" ), "Cal", "Image button - image text" ); equal( image.attr( "title" ), "Cal", "Image button - image text" );
TestHelpers.datepicker.onFocus( inp, function() { datepickerTestHelpers.onFocus( inp, function() {
ok( !dp.is( ":visible" ), "Image button - not rendered on focus" ); ok( !dp.is( ":visible" ), "Image button - not rendered on focus" );
image.click(); image.click();
ok( dp.is( ":visible" ), "Image button - rendered on image click" ); ok( dp.is( ":visible" ), "Image button - rendered on image click" );
@ -191,7 +194,7 @@ test("change", function() {
} }
function step4() { function step4() {
var inp = TestHelpers.datepicker.initNewInput({ var inp = datepickerTestHelpers.initNewInput({
showOn: "both", showOn: "both",
buttonImage: "images/calendar.gif" buttonImage: "images/calendar.gif"
}), }),
@ -207,7 +210,7 @@ test("change", function() {
// TODO: This test occasionally fails to focus in IE8 in BrowserStack // TODO: This test occasionally fails to focus in IE8 in BrowserStack
if ( !isOldIE ) { if ( !isOldIE ) {
TestHelpers.datepicker.onFocus( inp, function() { datepickerTestHelpers.onFocus( inp, function() {
ok( dp.is( ":visible" ), "Both - rendered on focus" ); ok( dp.is( ":visible" ), "Both - rendered on focus" );
body.simulate( "mousedown", {} ); body.simulate( "mousedown", {} );
ok( !dp.is( ":visible" ), "Both - hidden on external click" ); ok( !dp.is( ":visible" ), "Both - hidden on external click" );
@ -230,7 +233,7 @@ test("change", function() {
test("otherMonths", function() { test("otherMonths", function() {
expect( 8 ); expect( 8 );
var inp = TestHelpers.datepicker.init("#inp"), var inp = datepickerTestHelpers.init("#inp"),
pop = $("#ui-datepicker-div"); pop = $("#ui-datepicker-div");
inp.val("06/01/2009").datepicker("show"); inp.val("06/01/2009").datepicker("show");
equal(pop.find("tbody").text(), equal(pop.find("tbody").text(),
@ -258,105 +261,105 @@ test("otherMonths", function() {
test("defaultDate", function() { test("defaultDate", function() {
expect( 16 ); expect( 16 );
var inp = TestHelpers.datepicker.init("#inp"), var inp = datepickerTestHelpers.init("#inp"),
date = new Date(); date = new Date();
inp.val("").datepicker("show"). inp.val("").datepicker("show").
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Default date null"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), date, "Default date null");
// Numeric values // Numeric values
inp.datepicker("option", {defaultDate: -2}). inp.datepicker("option", {defaultDate: -2}).
datepicker("hide").val("").datepicker("show"). datepicker("hide").val("").datepicker("show").
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
date.setDate(date.getDate() - 2); date.setDate(date.getDate() - 2);
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Default date -2"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), date, "Default date -2");
date = new Date(); date = new Date();
inp.datepicker("option", {defaultDate: 3}). inp.datepicker("option", {defaultDate: 3}).
datepicker("hide").val("").datepicker("show"). datepicker("hide").val("").datepicker("show").
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
date.setDate(date.getDate() + 3); date.setDate(date.getDate() + 3);
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Default date 3"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), date, "Default date 3");
date = new Date(); date = new Date();
inp.datepicker("option", {defaultDate: 1 / "a"}). inp.datepicker("option", {defaultDate: 1 / "a"}).
datepicker("hide").val("").datepicker("show"). datepicker("hide").val("").datepicker("show").
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Default date NaN"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), date, "Default date NaN");
// String offset values // String offset values
inp.datepicker("option", {defaultDate: "-1d"}). inp.datepicker("option", {defaultDate: "-1d"}).
datepicker("hide").val("").datepicker("show"). datepicker("hide").val("").datepicker("show").
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
date.setDate(date.getDate() - 1); date.setDate(date.getDate() - 1);
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Default date -1d"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), date, "Default date -1d");
inp.datepicker("option", {defaultDate: "+3D"}). inp.datepicker("option", {defaultDate: "+3D"}).
datepicker("hide").val("").datepicker("show"). datepicker("hide").val("").datepicker("show").
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
date.setDate(date.getDate() + 4); date.setDate(date.getDate() + 4);
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Default date +3D"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), date, "Default date +3D");
inp.datepicker("option", {defaultDate: " -2 w "}). inp.datepicker("option", {defaultDate: " -2 w "}).
datepicker("hide").val("").datepicker("show"). datepicker("hide").val("").datepicker("show").
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
date = new Date(); date = new Date();
date.setDate(date.getDate() - 14); date.setDate(date.getDate() - 14);
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Default date -2 w"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), date, "Default date -2 w");
inp.datepicker("option", {defaultDate: "+1 W"}). inp.datepicker("option", {defaultDate: "+1 W"}).
datepicker("hide").val("").datepicker("show"). datepicker("hide").val("").datepicker("show").
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
date.setDate(date.getDate() + 21); date.setDate(date.getDate() + 21);
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Default date +1 W"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), date, "Default date +1 W");
inp.datepicker("option", {defaultDate: " -1 m "}). inp.datepicker("option", {defaultDate: " -1 m "}).
datepicker("hide").val("").datepicker("show"). datepicker("hide").val("").datepicker("show").
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
date = TestHelpers.datepicker.addMonths(new Date(), -1); date = datepickerTestHelpers.addMonths(new Date(), -1);
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Default date -1 m"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), date, "Default date -1 m");
inp.datepicker("option", {defaultDate: "+2M"}). inp.datepicker("option", {defaultDate: "+2M"}).
datepicker("hide").val("").datepicker("show"). datepicker("hide").val("").datepicker("show").
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
date = TestHelpers.datepicker.addMonths(new Date(), 2); date = datepickerTestHelpers.addMonths(new Date(), 2);
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Default date +2M"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), date, "Default date +2M");
inp.datepicker("option", {defaultDate: "-2y"}). inp.datepicker("option", {defaultDate: "-2y"}).
datepicker("hide").val("").datepicker("show"). datepicker("hide").val("").datepicker("show").
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
date = new Date(); date = new Date();
date.setFullYear(date.getFullYear() - 2); date.setFullYear(date.getFullYear() - 2);
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Default date -2y"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), date, "Default date -2y");
inp.datepicker("option", {defaultDate: "+1 Y "}). inp.datepicker("option", {defaultDate: "+1 Y "}).
datepicker("hide").val("").datepicker("show"). datepicker("hide").val("").datepicker("show").
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
date.setFullYear(date.getFullYear() + 3); date.setFullYear(date.getFullYear() + 3);
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Default date +1 Y"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), date, "Default date +1 Y");
inp.datepicker("option", {defaultDate: "+1M +10d"}). inp.datepicker("option", {defaultDate: "+1M +10d"}).
datepicker("hide").val("").datepicker("show"). datepicker("hide").val("").datepicker("show").
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
date = TestHelpers.datepicker.addMonths(new Date(), 1); date = datepickerTestHelpers.addMonths(new Date(), 1);
date.setDate(date.getDate() + 10); date.setDate(date.getDate() + 10);
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Default date +1M +10d"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), date, "Default date +1M +10d");
// String date values // String date values
inp.datepicker("option", {defaultDate: "07/04/2007"}). inp.datepicker("option", {defaultDate: "07/04/2007"}).
datepicker("hide").val("").datepicker("show"). datepicker("hide").val("").datepicker("show").
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
date = new Date(2007, 7 - 1, 4); date = new Date(2007, 7 - 1, 4);
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Default date 07/04/2007"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), date, "Default date 07/04/2007");
inp.datepicker("option", {dateFormat: "yy-mm-dd", defaultDate: "2007-04-02"}). inp.datepicker("option", {dateFormat: "yy-mm-dd", defaultDate: "2007-04-02"}).
datepicker("hide").val("").datepicker("show"). datepicker("hide").val("").datepicker("show").
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
date = new Date(2007, 4 - 1, 2); date = new Date(2007, 4 - 1, 2);
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Default date 2007-04-02"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), date, "Default date 2007-04-02");
// Date value // Date value
date = new Date(2007, 1 - 1, 26); date = new Date(2007, 1 - 1, 26);
inp.datepicker("option", {dateFormat: "mm/dd/yy", defaultDate: date}). inp.datepicker("option", {dateFormat: "mm/dd/yy", defaultDate: date}).
datepicker("hide").val("").datepicker("show"). datepicker("hide").val("").datepicker("show").
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Default date 01/26/2007"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), date, "Default date 01/26/2007");
}); });
test("miscellaneous", function() { test("miscellaneous", function() {
expect( 19 ); expect( 19 );
var curYear, longNames, shortNames, date, var curYear, longNames, shortNames, date,
dp = $("#ui-datepicker-div"), dp = $("#ui-datepicker-div"),
inp = TestHelpers.datepicker.init("#inp"); inp = datepickerTestHelpers.init("#inp");
// Year range // Year range
function genRange(start, offset) { function genRange(start, offset) {
var i = start, var i = start,
@ -417,7 +420,7 @@ test("miscellaneous", function() {
test("minMax", function() { test("minMax", function() {
expect( 23 ); expect( 23 );
var date, var date,
inp = TestHelpers.datepicker.init("#inp"), inp = datepickerTestHelpers.init("#inp"),
dp = $("#ui-datepicker-div"), dp = $("#ui-datepicker-div"),
lastYear = new Date(2007, 6 - 1, 4), lastYear = new Date(2007, 6 - 1, 4),
nextYear = new Date(2009, 6 - 1, 4), nextYear = new Date(2009, 6 - 1, 4),
@ -426,45 +429,45 @@ test("minMax", function() {
inp.val("06/04/2008").datepicker("show"); inp.val("06/04/2008").datepicker("show");
inp.simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}). inp.simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}).
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), lastYear, datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), lastYear,
"Min/max - null, null - ctrl+pgup"); "Min/max - null, null - ctrl+pgup");
inp.val("06/04/2008").datepicker("show"); inp.val("06/04/2008").datepicker("show");
inp.simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN}). inp.simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN}).
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), nextYear, datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), nextYear,
"Min/max - null, null - ctrl+pgdn"); "Min/max - null, null - ctrl+pgdn");
inp.datepicker("option", {minDate: minDate}). inp.datepicker("option", {minDate: minDate}).
datepicker("hide").val("06/04/2008").datepicker("show"); datepicker("hide").val("06/04/2008").datepicker("show");
inp.simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}). inp.simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}).
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), minDate, datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), minDate,
"Min/max - 02/29/2008, null - ctrl+pgup"); "Min/max - 02/29/2008, null - ctrl+pgup");
inp.val("06/04/2008").datepicker("show"); inp.val("06/04/2008").datepicker("show");
inp.simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN}). inp.simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN}).
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), nextYear, datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), nextYear,
"Min/max - 02/29/2008, null - ctrl+pgdn"); "Min/max - 02/29/2008, null - ctrl+pgdn");
inp.datepicker("option", {maxDate: maxDate}). inp.datepicker("option", {maxDate: maxDate}).
datepicker("hide").val("06/04/2008").datepicker("show"); datepicker("hide").val("06/04/2008").datepicker("show");
inp.simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}). inp.simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}).
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), minDate, datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), minDate,
"Min/max - 02/29/2008, 12/07/2008 - ctrl+pgup"); "Min/max - 02/29/2008, 12/07/2008 - ctrl+pgup");
inp.val("06/04/2008").datepicker("show"); inp.val("06/04/2008").datepicker("show");
inp.simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN}). inp.simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN}).
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), maxDate, datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), maxDate,
"Min/max - 02/29/2008, 12/07/2008 - ctrl+pgdn"); "Min/max - 02/29/2008, 12/07/2008 - ctrl+pgdn");
inp.datepicker("option", {minDate: null}). inp.datepicker("option", {minDate: null}).
datepicker("hide").val("06/04/2008").datepicker("show"); datepicker("hide").val("06/04/2008").datepicker("show");
inp.simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}). inp.simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}).
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), lastYear, datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), lastYear,
"Min/max - null, 12/07/2008 - ctrl+pgup"); "Min/max - null, 12/07/2008 - ctrl+pgup");
inp.val("06/04/2008").datepicker("show"); inp.val("06/04/2008").datepicker("show");
inp.simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN}). inp.simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN}).
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), maxDate, datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), maxDate,
"Min/max - null, 12/07/2008 - ctrl+pgdn"); "Min/max - null, 12/07/2008 - ctrl+pgdn");
// Relative dates // Relative dates
date = new Date(); date = new Date();
@ -473,31 +476,31 @@ test("minMax", function() {
datepicker("hide").val("").datepicker("show"); datepicker("hide").val("").datepicker("show");
inp.simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}). inp.simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}).
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), date,
"Min/max - -1w, +1 M +10 D - ctrl+pgup"); "Min/max - -1w, +1 M +10 D - ctrl+pgup");
date = TestHelpers.datepicker.addMonths(new Date(), 1); date = datepickerTestHelpers.addMonths(new Date(), 1);
date.setDate(date.getDate() + 10); date.setDate(date.getDate() + 10);
inp.val("").datepicker("show"); inp.val("").datepicker("show");
inp.simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN}). inp.simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN}).
simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); simulate("keydown", {keyCode: $.ui.keyCode.ENTER});
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), date,
"Min/max - -1w, +1 M +10 D - ctrl+pgdn"); "Min/max - -1w, +1 M +10 D - ctrl+pgdn");
// With existing date // With existing date
inp = TestHelpers.datepicker.init("#inp"); inp = datepickerTestHelpers.init("#inp");
inp.val("06/04/2008").datepicker("option", {minDate: minDate}); inp.val("06/04/2008").datepicker("option", {minDate: minDate});
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), new Date(2008, 6 - 1, 4), "Min/max - setDate > min"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), new Date(2008, 6 - 1, 4), "Min/max - setDate > min");
inp.datepicker("option", {minDate: null}).val("01/04/2008").datepicker("option", {minDate: minDate}); inp.datepicker("option", {minDate: null}).val("01/04/2008").datepicker("option", {minDate: minDate});
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), minDate, "Min/max - setDate < min"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), minDate, "Min/max - setDate < min");
inp.datepicker("option", {minDate: null}).val("06/04/2008").datepicker("option", {maxDate: maxDate}); inp.datepicker("option", {minDate: null}).val("06/04/2008").datepicker("option", {maxDate: maxDate});
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), new Date(2008, 6 - 1, 4), "Min/max - setDate < max"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), new Date(2008, 6 - 1, 4), "Min/max - setDate < max");
inp.datepicker("option", {maxDate: null}).val("01/04/2009").datepicker("option", {maxDate: maxDate}); inp.datepicker("option", {maxDate: null}).val("01/04/2009").datepicker("option", {maxDate: maxDate});
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), maxDate, "Min/max - setDate > max"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), maxDate, "Min/max - setDate > max");
inp.datepicker("option", {maxDate: null}).val("01/04/2008").datepicker("option", {minDate: minDate, maxDate: maxDate}); inp.datepicker("option", {maxDate: null}).val("01/04/2008").datepicker("option", {minDate: minDate, maxDate: maxDate});
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), minDate, "Min/max - setDate < min"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), minDate, "Min/max - setDate < min");
inp.datepicker("option", {maxDate: null}).val("06/04/2008").datepicker("option", {minDate: minDate, maxDate: maxDate}); inp.datepicker("option", {maxDate: null}).val("06/04/2008").datepicker("option", {minDate: minDate, maxDate: maxDate});
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), new Date(2008, 6 - 1, 4), "Min/max - setDate > min, < max"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), new Date(2008, 6 - 1, 4), "Min/max - setDate > min, < max");
inp.datepicker("option", {maxDate: null}).val("01/04/2009").datepicker("option", {minDate: minDate, maxDate: maxDate}); inp.datepicker("option", {maxDate: null}).val("01/04/2009").datepicker("option", {minDate: minDate, maxDate: maxDate});
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), maxDate, "Min/max - setDate > max"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), maxDate, "Min/max - setDate > max");
inp.datepicker("option", {yearRange: "-0:+1"}).val("01/01/" + new Date().getFullYear()); inp.datepicker("option", {yearRange: "-0:+1"}).val("01/01/" + new Date().getFullYear());
ok(dp.find(".ui-datepicker-prev").hasClass("ui-state-disabled"), "Year Range Test - previous button disabled at 1/1/minYear"); ok(dp.find(".ui-datepicker-prev").hasClass("ui-state-disabled"), "Year Range Test - previous button disabled at 1/1/minYear");
@ -524,50 +527,50 @@ test("minMax", function() {
test("setDate", function() { test("setDate", function() {
expect( 24 ); expect( 24 );
var inl, alt, minDate, maxDate, dateAndTimeToSet, dateAndTimeClone, var inl, alt, minDate, maxDate, dateAndTimeToSet, dateAndTimeClone,
inp = TestHelpers.datepicker.init("#inp"), inp = datepickerTestHelpers.init("#inp"),
date1 = new Date(2008, 6 - 1, 4), date1 = new Date(2008, 6 - 1, 4),
date2 = new Date(); date2 = new Date();
ok(inp.datepicker("getDate") == null, "Set date - default"); ok(inp.datepicker("getDate") == null, "Set date - default");
inp.datepicker("setDate", date1); inp.datepicker("setDate", date1);
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date1, "Set date - 2008-06-04"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), date1, "Set date - 2008-06-04");
date1 = new Date(); date1 = new Date();
date1.setDate(date1.getDate() + 7); date1.setDate(date1.getDate() + 7);
inp.datepicker("setDate", +7); inp.datepicker("setDate", +7);
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date1, "Set date - +7"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), date1, "Set date - +7");
date2.setFullYear(date2.getFullYear() + 2); date2.setFullYear(date2.getFullYear() + 2);
inp.datepicker("setDate", "+2y"); inp.datepicker("setDate", "+2y");
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date2, "Set date - +2y"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), date2, "Set date - +2y");
inp.datepicker("setDate", date1, date2); inp.datepicker("setDate", date1, date2);
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date1, "Set date - two dates"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), date1, "Set date - two dates");
inp.datepicker("setDate"); inp.datepicker("setDate");
ok(inp.datepicker("getDate") == null, "Set date - null"); ok(inp.datepicker("getDate") == null, "Set date - null");
// Relative to current date // Relative to current date
date1 = new Date(); date1 = new Date();
date1.setDate(date1.getDate() + 7); date1.setDate(date1.getDate() + 7);
inp.datepicker("setDate", "c +7"); inp.datepicker("setDate", "c +7");
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date1, "Set date - c +7"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), date1, "Set date - c +7");
date1.setDate(date1.getDate() + 7); date1.setDate(date1.getDate() + 7);
inp.datepicker("setDate", "c+7"); inp.datepicker("setDate", "c+7");
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date1, "Set date - c+7"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), date1, "Set date - c+7");
date1.setDate(date1.getDate() - 21); date1.setDate(date1.getDate() - 21);
inp.datepicker("setDate", "c -3 w"); inp.datepicker("setDate", "c -3 w");
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date1, "Set date - c -3 w"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), date1, "Set date - c -3 w");
// Inline // Inline
inl = TestHelpers.datepicker.init("#inl"); inl = datepickerTestHelpers.init("#inl");
date1 = new Date(2008, 6 - 1, 4); date1 = new Date(2008, 6 - 1, 4);
date2 = new Date(); date2 = new Date();
TestHelpers.datepicker.equalsDate(inl.datepicker("getDate"), date2, "Set date inline - default"); datepickerTestHelpers.equalsDate(inl.datepicker("getDate"), date2, "Set date inline - default");
inl.datepicker("setDate", date1); inl.datepicker("setDate", date1);
TestHelpers.datepicker.equalsDate(inl.datepicker("getDate"), date1, "Set date inline - 2008-06-04"); datepickerTestHelpers.equalsDate(inl.datepicker("getDate"), date1, "Set date inline - 2008-06-04");
date1 = new Date(); date1 = new Date();
date1.setDate(date1.getDate() + 7); date1.setDate(date1.getDate() + 7);
inl.datepicker("setDate", +7); inl.datepicker("setDate", +7);
TestHelpers.datepicker.equalsDate(inl.datepicker("getDate"), date1, "Set date inline - +7"); datepickerTestHelpers.equalsDate(inl.datepicker("getDate"), date1, "Set date inline - +7");
date2.setFullYear(date2.getFullYear() + 2); date2.setFullYear(date2.getFullYear() + 2);
inl.datepicker("setDate", "+2y"); inl.datepicker("setDate", "+2y");
TestHelpers.datepicker.equalsDate(inl.datepicker("getDate"), date2, "Set date inline - +2y"); datepickerTestHelpers.equalsDate(inl.datepicker("getDate"), date2, "Set date inline - +2y");
inl.datepicker("setDate", date1, date2); inl.datepicker("setDate", date1, date2);
TestHelpers.datepicker.equalsDate(inl.datepicker("getDate"), date1, "Set date inline - two dates"); datepickerTestHelpers.equalsDate(inl.datepicker("getDate"), date1, "Set date inline - two dates");
inl.datepicker("setDate"); inl.datepicker("setDate");
ok(inl.datepicker("getDate") == null, "Set date inline - null"); ok(inl.datepicker("getDate") == null, "Set date inline - null");
// Alternate field // Alternate field
@ -578,23 +581,23 @@ test("setDate", function() {
equal(inp.val(), "06/04/2008", "Set date alternate - 06/04/2008"); equal(inp.val(), "06/04/2008", "Set date alternate - 06/04/2008");
equal(alt.val(), "2008-06-04", "Set date alternate - 2008-06-04"); equal(alt.val(), "2008-06-04", "Set date alternate - 2008-06-04");
// With minimum/maximum // With minimum/maximum
inp = TestHelpers.datepicker.init("#inp"); inp = datepickerTestHelpers.init("#inp");
date1 = new Date(2008, 1 - 1, 4); date1 = new Date(2008, 1 - 1, 4);
date2 = new Date(2008, 6 - 1, 4); date2 = new Date(2008, 6 - 1, 4);
minDate = new Date(2008, 2 - 1, 29); minDate = new Date(2008, 2 - 1, 29);
maxDate = new Date(2008, 3 - 1, 28); maxDate = new Date(2008, 3 - 1, 28);
inp.val("").datepicker("option", {minDate: minDate}).datepicker("setDate", date2); inp.val("").datepicker("option", {minDate: minDate}).datepicker("setDate", date2);
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date2, "Set date min/max - setDate > min"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), date2, "Set date min/max - setDate > min");
inp.datepicker("setDate", date1); inp.datepicker("setDate", date1);
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), minDate, "Set date min/max - setDate < min"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), minDate, "Set date min/max - setDate < min");
inp.val("").datepicker("option", {maxDate: maxDate, minDate: null}).datepicker("setDate", date1); inp.val("").datepicker("option", {maxDate: maxDate, minDate: null}).datepicker("setDate", date1);
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date1, "Set date min/max - setDate < max"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), date1, "Set date min/max - setDate < max");
inp.datepicker("setDate", date2); inp.datepicker("setDate", date2);
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), maxDate, "Set date min/max - setDate > max"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), maxDate, "Set date min/max - setDate > max");
inp.val("").datepicker("option", {minDate: minDate}).datepicker("setDate", date1); inp.val("").datepicker("option", {minDate: minDate}).datepicker("setDate", date1);
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), minDate, "Set date min/max - setDate < min"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), minDate, "Set date min/max - setDate < min");
inp.datepicker("setDate", date2); inp.datepicker("setDate", date2);
TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), maxDate, "Set date min/max - setDate > max"); datepickerTestHelpers.equalsDate(inp.datepicker("getDate"), maxDate, "Set date min/max - setDate > max");
dateAndTimeToSet = new Date(2008, 3 - 1, 28, 1, 11, 0); dateAndTimeToSet = new Date(2008, 3 - 1, 28, 1, 11, 0);
dateAndTimeClone = new Date(2008, 3 - 1, 28, 1, 11, 0); dateAndTimeClone = new Date(2008, 3 - 1, 28, 1, 11, 0);
inp.datepicker("setDate", dateAndTimeToSet); inp.datepicker("setDate", dateAndTimeToSet);
@ -603,7 +606,7 @@ test("setDate", function() {
test("altField", function() { test("altField", function() {
expect( 10 ); expect( 10 );
var inp = TestHelpers.datepicker.init("#inp"), var inp = datepickerTestHelpers.init("#inp"),
alt = $("#alt"); alt = $("#alt");
// No alternate field set // No alternate field set
alt.val(""); alt.val("");
@ -642,7 +645,7 @@ test("altField", function() {
test("autoSize", function() { test("autoSize", function() {
expect( 15 ); expect( 15 );
var inp = TestHelpers.datepicker.init("#inp"); var inp = datepickerTestHelpers.init("#inp");
equal(inp.prop("size"), 20, "Auto size - default"); equal(inp.prop("size"), 20, "Auto size - default");
inp.datepicker("option", "autoSize", true); inp.datepicker("option", "autoSize", true);
equal(inp.prop("size"), 10, "Auto size - mm/dd/yy"); equal(inp.prop("size"), 10, "Auto size - mm/dd/yy");
@ -680,7 +683,7 @@ test("autoSize", function() {
test("daylightSaving", function() { test("daylightSaving", function() {
expect( 25 ); expect( 25 );
var inp = TestHelpers.datepicker.init("#inp"), var inp = datepickerTestHelpers.init("#inp"),
dp = $("#ui-datepicker-div"); dp = $("#ui-datepicker-div");
ok(true, "Daylight saving - " + new Date()); ok(true, "Daylight saving - " + new Date());
// Australia, Sydney - AM change, southern hemisphere // Australia, Sydney - AM change, southern hemisphere
@ -786,7 +789,7 @@ test("callbacks", function() {
expect( 13 ); expect( 13 );
// Before show // Before show
var dp, day20, day21, var dp, day20, day21,
inp = TestHelpers.datepicker.init("#inp", {beforeShow: beforeAll}), inp = datepickerTestHelpers.init("#inp", {beforeShow: beforeAll}),
inst = $.data(inp[0], "datepicker"); inst = $.data(inp[0], "datepicker");
equal($.datepicker._get(inst, "currentText"), "Today", "Before show - initial"); equal($.datepicker._get(inst, "currentText"), "Today", "Before show - initial");
inp.val("02/04/2008").datepicker("show"); inp.val("02/04/2008").datepicker("show");
@ -796,7 +799,7 @@ test("callbacks", function() {
deepEqual(beforeShowInst, inst, "Before show - inst OK"); deepEqual(beforeShowInst, inst, "Before show - inst OK");
inp.datepicker("hide").datepicker("destroy"); inp.datepicker("hide").datepicker("destroy");
// Before show day // Before show day
inp = TestHelpers.datepicker.init("#inp", {beforeShowDay: beforeDay}); inp = datepickerTestHelpers.init("#inp", {beforeShowDay: beforeDay});
dp = $("#ui-datepicker-div"); dp = $("#ui-datepicker-div");
inp.val("02/04/2008").datepicker("show"); inp.val("02/04/2008").datepicker("show");
ok(beforeShowDayThis.id === inp[0].id, "Before show day - this OK"); ok(beforeShowDayThis.id === inp[0].id, "Before show day - this OK");
@ -815,7 +818,7 @@ test("callbacks", function() {
test("beforeShowDay - tooltips with quotes", function() { test("beforeShowDay - tooltips with quotes", function() {
expect( 1 ); expect( 1 );
var inp, dp; var inp, dp;
inp = TestHelpers.datepicker.init("#inp", { inp = datepickerTestHelpers.init("#inp", {
beforeShowDay: function() { beforeShowDay: function() {
return [ true, "", "'" ]; return [ true, "", "'" ];
} }
@ -830,7 +833,7 @@ test("beforeShowDay - tooltips with quotes", function() {
test("localisation", function() { test("localisation", function() {
expect( 24 ); expect( 24 );
var dp, month, day, date, var dp, month, day, date,
inp = TestHelpers.datepicker.init("#inp", $.datepicker.regional.fr); inp = datepickerTestHelpers.init("#inp", $.datepicker.regional.fr);
inp.datepicker("option", {dateFormat: "DD, d MM yy", showButtonPanel:true, changeMonth:true, changeYear:true}).val("").datepicker("show"); inp.datepicker("option", {dateFormat: "DD, d MM yy", showButtonPanel:true, changeMonth:true, changeYear:true}).val("").datepicker("show");
dp = $("#ui-datepicker-div"); dp = $("#ui-datepicker-div");
equal($(".ui-datepicker-close", dp).text(), "Fermer", "Localisation - close"); equal($(".ui-datepicker-close", dp).text(), "Fermer", "Localisation - close");
@ -897,72 +900,72 @@ test("iso8601Week", function() {
test("parseDate", function() { test("parseDate", function() {
expect( 26 ); expect( 26 );
TestHelpers.datepicker.init("#inp"); datepickerTestHelpers.init("#inp");
var currentYear, gmtDate, fr, settings, zh; var currentYear, gmtDate, fr, settings, zh;
ok($.datepicker.parseDate("d m y", "") == null, "Parse date empty"); ok($.datepicker.parseDate("d m y", "") == null, "Parse date empty");
TestHelpers.datepicker.equalsDate($.datepicker.parseDate("d m y", "3 2 01"), datepickerTestHelpers.equalsDate($.datepicker.parseDate("d m y", "3 2 01"),
new Date(2001, 2 - 1, 3), "Parse date d m y"); new Date(2001, 2 - 1, 3), "Parse date d m y");
TestHelpers.datepicker.equalsDate($.datepicker.parseDate("dd mm yy", "03 02 2001"), datepickerTestHelpers.equalsDate($.datepicker.parseDate("dd mm yy", "03 02 2001"),
new Date(2001, 2 - 1, 3), "Parse date dd mm yy"); new Date(2001, 2 - 1, 3), "Parse date dd mm yy");
TestHelpers.datepicker.equalsDate($.datepicker.parseDate("d m y", "13 12 01"), datepickerTestHelpers.equalsDate($.datepicker.parseDate("d m y", "13 12 01"),
new Date(2001, 12 - 1, 13), "Parse date d m y"); new Date(2001, 12 - 1, 13), "Parse date d m y");
TestHelpers.datepicker.equalsDate($.datepicker.parseDate("dd mm yy", "13 12 2001"), datepickerTestHelpers.equalsDate($.datepicker.parseDate("dd mm yy", "13 12 2001"),
new Date(2001, 12 - 1, 13), "Parse date dd mm yy"); new Date(2001, 12 - 1, 13), "Parse date dd mm yy");
TestHelpers.datepicker.equalsDate($.datepicker.parseDate("y-o", "01-34"), datepickerTestHelpers.equalsDate($.datepicker.parseDate("y-o", "01-34"),
new Date(2001, 2 - 1, 3), "Parse date y-o"); new Date(2001, 2 - 1, 3), "Parse date y-o");
TestHelpers.datepicker.equalsDate($.datepicker.parseDate("yy-oo", "2001-347"), datepickerTestHelpers.equalsDate($.datepicker.parseDate("yy-oo", "2001-347"),
new Date(2001, 12 - 1, 13), "Parse date yy-oo"); new Date(2001, 12 - 1, 13), "Parse date yy-oo");
TestHelpers.datepicker.equalsDate($.datepicker.parseDate("oo yy", "348 2004"), datepickerTestHelpers.equalsDate($.datepicker.parseDate("oo yy", "348 2004"),
new Date(2004, 12 - 1, 13), "Parse date oo yy"); new Date(2004, 12 - 1, 13), "Parse date oo yy");
TestHelpers.datepicker.equalsDate($.datepicker.parseDate("D d M y", "Sat 3 Feb 01"), datepickerTestHelpers.equalsDate($.datepicker.parseDate("D d M y", "Sat 3 Feb 01"),
new Date(2001, 2 - 1, 3), "Parse date D d M y"); new Date(2001, 2 - 1, 3), "Parse date D d M y");
TestHelpers.datepicker.equalsDate($.datepicker.parseDate("d MM DD yy", "3 February Saturday 2001"), datepickerTestHelpers.equalsDate($.datepicker.parseDate("d MM DD yy", "3 February Saturday 2001"),
new Date(2001, 2 - 1, 3), "Parse date dd MM DD yy"); new Date(2001, 2 - 1, 3), "Parse date dd MM DD yy");
TestHelpers.datepicker.equalsDate($.datepicker.parseDate("DD, MM d, yy", "Saturday, February 3, 2001"), datepickerTestHelpers.equalsDate($.datepicker.parseDate("DD, MM d, yy", "Saturday, February 3, 2001"),
new Date(2001, 2 - 1, 3), "Parse date DD, MM d, yy"); new Date(2001, 2 - 1, 3), "Parse date DD, MM d, yy");
TestHelpers.datepicker.equalsDate($.datepicker.parseDate("'day' d 'of' MM (''DD''), yy", datepickerTestHelpers.equalsDate($.datepicker.parseDate("'day' d 'of' MM (''DD''), yy",
"day 3 of February ('Saturday'), 2001"), new Date(2001, 2 - 1, 3), "day 3 of February ('Saturday'), 2001"), new Date(2001, 2 - 1, 3),
"Parse date 'day' d 'of' MM (''DD''), yy"); "Parse date 'day' d 'of' MM (''DD''), yy");
currentYear = new Date().getFullYear(); currentYear = new Date().getFullYear();
TestHelpers.datepicker.equalsDate($.datepicker.parseDate("y-m-d", (currentYear - 2000) + "-02-03"), datepickerTestHelpers.equalsDate($.datepicker.parseDate("y-m-d", (currentYear - 2000) + "-02-03"),
new Date(currentYear, 2 - 1, 3), "Parse date y-m-d - default cutuff"); new Date(currentYear, 2 - 1, 3), "Parse date y-m-d - default cutuff");
TestHelpers.datepicker.equalsDate($.datepicker.parseDate("y-m-d", (currentYear - 2000 + 10) + "-02-03"), datepickerTestHelpers.equalsDate($.datepicker.parseDate("y-m-d", (currentYear - 2000 + 10) + "-02-03"),
new Date(currentYear+10, 2 - 1, 3), "Parse date y-m-d - default cutuff"); new Date(currentYear+10, 2 - 1, 3), "Parse date y-m-d - default cutuff");
TestHelpers.datepicker.equalsDate($.datepicker.parseDate("y-m-d", (currentYear - 2000 + 11) + "-02-03"), datepickerTestHelpers.equalsDate($.datepicker.parseDate("y-m-d", (currentYear - 2000 + 11) + "-02-03"),
new Date(currentYear-89, 2 - 1, 3), "Parse date y-m-d - default cutuff"); new Date(currentYear-89, 2 - 1, 3), "Parse date y-m-d - default cutuff");
TestHelpers.datepicker.equalsDate($.datepicker.parseDate("y-m-d", "80-02-03", {shortYearCutoff: 80}), datepickerTestHelpers.equalsDate($.datepicker.parseDate("y-m-d", "80-02-03", {shortYearCutoff: 80}),
new Date(2080, 2 - 1, 3), "Parse date y-m-d - cutoff 80"); new Date(2080, 2 - 1, 3), "Parse date y-m-d - cutoff 80");
TestHelpers.datepicker.equalsDate($.datepicker.parseDate("y-m-d", "81-02-03", {shortYearCutoff: 80}), datepickerTestHelpers.equalsDate($.datepicker.parseDate("y-m-d", "81-02-03", {shortYearCutoff: 80}),
new Date(1981, 2 - 1, 3), "Parse date y-m-d - cutoff 80"); new Date(1981, 2 - 1, 3), "Parse date y-m-d - cutoff 80");
TestHelpers.datepicker.equalsDate($.datepicker.parseDate("y-m-d", (currentYear - 2000 + 60) + "-02-03", {shortYearCutoff: "+60"}), datepickerTestHelpers.equalsDate($.datepicker.parseDate("y-m-d", (currentYear - 2000 + 60) + "-02-03", {shortYearCutoff: "+60"}),
new Date(currentYear + 60, 2 - 1, 3), "Parse date y-m-d - cutoff +60"); new Date(currentYear + 60, 2 - 1, 3), "Parse date y-m-d - cutoff +60");
TestHelpers.datepicker.equalsDate($.datepicker.parseDate("y-m-d", (currentYear - 2000 + 61) + "-02-03", {shortYearCutoff: "+60"}), datepickerTestHelpers.equalsDate($.datepicker.parseDate("y-m-d", (currentYear - 2000 + 61) + "-02-03", {shortYearCutoff: "+60"}),
new Date(currentYear - 39, 2 - 1, 3), "Parse date y-m-d - cutoff +60"); new Date(currentYear - 39, 2 - 1, 3), "Parse date y-m-d - cutoff +60");
gmtDate = new Date(2001, 2 - 1, 3); gmtDate = new Date(2001, 2 - 1, 3);
gmtDate.setMinutes(gmtDate.getMinutes() - gmtDate.getTimezoneOffset()); gmtDate.setMinutes(gmtDate.getMinutes() - gmtDate.getTimezoneOffset());
TestHelpers.datepicker.equalsDate($.datepicker.parseDate("@", "981158400000"), gmtDate, "Parse date @"); datepickerTestHelpers.equalsDate($.datepicker.parseDate("@", "981158400000"), gmtDate, "Parse date @");
TestHelpers.datepicker.equalsDate($.datepicker.parseDate("!", "631167552000000000"), gmtDate, "Parse date !"); datepickerTestHelpers.equalsDate($.datepicker.parseDate("!", "631167552000000000"), gmtDate, "Parse date !");
fr = $.datepicker.regional.fr; fr = $.datepicker.regional.fr;
settings = {dayNamesShort: fr.dayNamesShort, dayNames: fr.dayNames, settings = {dayNamesShort: fr.dayNamesShort, dayNames: fr.dayNames,
monthNamesShort: fr.monthNamesShort, monthNames: fr.monthNames}; monthNamesShort: fr.monthNamesShort, monthNames: fr.monthNames};
TestHelpers.datepicker.equalsDate($.datepicker.parseDate("D d M y", "Lun. 9 avr. 01", settings), datepickerTestHelpers.equalsDate($.datepicker.parseDate("D d M y", "Lun. 9 avr. 01", settings),
new Date(2001, 4 - 1, 9), "Parse date D M y with settings"); new Date(2001, 4 - 1, 9), "Parse date D M y with settings");
TestHelpers.datepicker.equalsDate($.datepicker.parseDate("d MM DD yy", "9 Avril Lundi 2001", settings), datepickerTestHelpers.equalsDate($.datepicker.parseDate("d MM DD yy", "9 Avril Lundi 2001", settings),
new Date(2001, 4 - 1, 9), "Parse date d MM DD yy with settings"); new Date(2001, 4 - 1, 9), "Parse date d MM DD yy with settings");
TestHelpers.datepicker.equalsDate($.datepicker.parseDate("DD, MM d, yy", "Lundi, Avril 9, 2001", settings), datepickerTestHelpers.equalsDate($.datepicker.parseDate("DD, MM d, yy", "Lundi, Avril 9, 2001", settings),
new Date(2001, 4 - 1, 9), "Parse date DD, MM d, yy with settings"); new Date(2001, 4 - 1, 9), "Parse date DD, MM d, yy with settings");
TestHelpers.datepicker.equalsDate($.datepicker.parseDate("'jour' d 'de' MM (''DD''), yy", "jour 9 de Avril ('Lundi'), 2001", settings), datepickerTestHelpers.equalsDate($.datepicker.parseDate("'jour' d 'de' MM (''DD''), yy", "jour 9 de Avril ('Lundi'), 2001", settings),
new Date(2001, 4 - 1, 9), "Parse date 'jour' d 'de' MM (''DD''), yy with settings"); new Date(2001, 4 - 1, 9), "Parse date 'jour' d 'de' MM (''DD''), yy with settings");
zh = $.datepicker.regional["zh-CN"]; zh = $.datepicker.regional["zh-CN"];
TestHelpers.datepicker.equalsDate($.datepicker.parseDate("yy M d", "2011 十一月 22", zh), datepickerTestHelpers.equalsDate($.datepicker.parseDate("yy M d", "2011 十一月 22", zh),
new Date(2011, 11 - 1, 22), "Parse date yy M d with zh-CN"); new Date(2011, 11 - 1, 22), "Parse date yy M d with zh-CN");
}); });
test("parseDateErrors", function() { test("parseDateErrors", function() {
expect( 18 ); expect( 18 );
TestHelpers.datepicker.init("#inp"); datepickerTestHelpers.init("#inp");
var fr, settings; var fr, settings;
function expectError(expr, value, error) { function expectError(expr, value, error) {
try { try {
@ -1037,7 +1040,7 @@ test("Ticket #7244: date parser does not fail when too many numbers are passed i
test("formatDate", function() { test("formatDate", function() {
expect( 16 ); expect( 16 );
TestHelpers.datepicker.init("#inp"); datepickerTestHelpers.init("#inp");
var gmtDate, fr, settings; var gmtDate, fr, settings;
equal($.datepicker.formatDate("d m y", new Date(2001, 2 - 1, 3)), equal($.datepicker.formatDate("d m y", new Date(2001, 2 - 1, 3)),
"3 2 01", "Format date d m y"); "3 2 01", "Format date d m y");
@ -1090,7 +1093,7 @@ test( "Ticket 7602: Stop datepicker from appearing with beforeShow event handler
var inp, dp; var inp, dp;
inp = TestHelpers.datepicker.init( "#inp", { inp = datepickerTestHelpers.init( "#inp", {
beforeShow: function() { beforeShow: function() {
} }
}); });
@ -1099,7 +1102,7 @@ test( "Ticket 7602: Stop datepicker from appearing with beforeShow event handler
equal( dp.css( "display" ), "block", "beforeShow returns nothing" ); equal( dp.css( "display" ), "block", "beforeShow returns nothing" );
inp.datepicker( "hide" ).datepicker( "destroy" ); inp.datepicker( "hide" ).datepicker( "destroy" );
inp = TestHelpers.datepicker.init( "#inp", { inp = datepickerTestHelpers.init( "#inp", {
beforeShow: function() { beforeShow: function() {
return true; return true;
} }
@ -1110,7 +1113,7 @@ test( "Ticket 7602: Stop datepicker from appearing with beforeShow event handler
inp.datepicker( "hide" ); inp.datepicker( "hide" );
inp.datepicker( "destroy" ); inp.datepicker( "destroy" );
inp = TestHelpers.datepicker.init( "#inp", { inp = datepickerTestHelpers.init( "#inp", {
beforeShow: function() { beforeShow: function() {
return false; return false;
} }
@ -1121,4 +1124,4 @@ test( "Ticket 7602: Stop datepicker from appearing with beforeShow event handler
inp.datepicker( "destroy" ); inp.datepicker( "destroy" );
}); });
})(jQuery); } );

View File

@ -1,4 +1,9 @@
TestHelpers.datepicker = { define( [
"lib/helper",
"ui/datepicker"
], function( testHelpers ) {
var datepickerTestHelpers = {
addMonths: function(date, offset) { addMonths: function(date, offset) {
var maxDay = 32 - new Date(date.getFullYear(), date.getMonth() + offset, 32).getDate(); var maxDay = 32 - new Date(date.getFullYear(), date.getMonth() + offset, 32).getDate();
date.setDate(Math.min(date.getDate(), maxDay)); date.setDate(Math.min(date.getDate(), maxDay));
@ -20,8 +25,12 @@ TestHelpers.datepicker = {
}, },
initNewInput: function( options ) { initNewInput: function( options ) {
var id = $( "<input>" ).appendTo( "#qunit-fixture" ); var id = $( "<input>" ).appendTo( "#qunit-fixture" );
return TestHelpers.datepicker.init( id, options ); return datepickerTestHelpers.init( id, options );
}, },
onFocus: TestHelpers.onFocus, onFocus: testHelpers.onFocus,
PROP_NAME: "datepicker" PROP_NAME: "datepicker"
}; };
return datepickerTestHelpers;
} );