From: Felix Nagel Date: Wed, 23 Apr 2014 15:49:03 +0000 (+0200) Subject: Datepicker: Fix code style issues X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=cfea8df90a78109fd0a332376ea1d2065782c33b;p=jquery-ui.git Datepicker: Fix code style issues --- diff --git a/demos/datepicker/show-week.html b/demos/datepicker/show-week.html index c7faf1020..321698373 100644 --- a/demos/datepicker/show-week.html +++ b/demos/datepicker/show-week.html @@ -28,7 +28,7 @@

The datepicker can show the week of the year. The calculation follows - Unicode CLDR specification. + Unicode CLDR specification. This means that some days from one year may be placed into weeks 'belonging' to another year.

diff --git a/external/date.js b/external/date.js index 101afb175..e7c17a58d 100644 --- a/external/date.js +++ b/external/date.js @@ -126,7 +126,7 @@ $.date.prototype = { var day = ( dow + weekdaysRev[ Globalize.locale().supplemental.weekData.firstDay() ] ) % 7; result.push({ shortname: Globalize.locale().main([ "dates/calendars/gregorian/days/format/abbreviated", weekdays[ day ] ]), - fullname: Globalize.locale().main([ "dates/calendars/gregorian/days/format/wide", weekdays[ day ] ]), + fullname: Globalize.locale().main([ "dates/calendars/gregorian/days/format/wide", weekdays[ day ] ]) }); } return result; diff --git a/tests/unit/datepicker/datepicker_core.js b/tests/unit/datepicker/datepicker_core.js index 377c4c201..189f03d93 100644 --- a/tests/unit/datepicker/datepicker_core.js +++ b/tests/unit/datepicker/datepicker_core.js @@ -40,7 +40,7 @@ asyncTest( "baseStructure", function() { ok( header.children( ":eq(1)" ).is( ".ui-datepicker-next" ) && header.children( ":eq(1)" ).html() !== "", "Structure - next link" ); title = header.children( ":last" ).children( ":first" ); - ok( title.is( "div.ui-datepicker-title" ) && title.html() !== "","Structure - title division" ); + ok( title.is( "div.ui-datepicker-title" ) && title.html() !== "", "Structure - title division" ); equal( title.children().length, 2, "Structure - title child count" ); ok( title.children( ":first" ).is( "span.ui-datepicker-month" ) && title.children( ":first" ).text() !== "", "Structure - month text" ); ok( title.children( ":last" ).is( "span.ui-datepicker-year" ) && title.children( ":last" ).text() !== "", "Structure - year text" ); @@ -95,7 +95,7 @@ asyncTest( "baseStructure", function() { function step3() { // Multi-month 2 - inp = TestHelpers.datepicker.initNewInput({ numberOfMonths: 2 }); + inp = TestHelpers.datepicker.initNewInput({ numberOfMonths: 2 } ); dp = inp.datepicker( "widget" ).find( ".ui-datepicker" ); inp.focus(); setTimeout(function() { @@ -121,7 +121,7 @@ asyncTest( "baseStructure", function() { function step4() { // Multi-month 3 - inp = TestHelpers.datepicker.initNewInput({ numberOfMonths: 3 }); + inp = TestHelpers.datepicker.initNewInput({ numberOfMonths: 3 } ); dp = inp.datepicker( "widget" ).find( ".ui-datepicker" ); inp.focus(); setTimeout(function() { @@ -135,7 +135,7 @@ asyncTest( "baseStructure", function() { function step5() { // Multi-month [2, 2] - inp = TestHelpers.datepicker.initNewInput({ numberOfMonths: [ 2, 2 ] }); + inp = TestHelpers.datepicker.initNewInput({ numberOfMonths: [ 2, 2 ] } ); dp = inp.datepicker( "widget" ).find( ".ui-datepicker" ); inp.focus(); setTimeout(function() { @@ -224,39 +224,39 @@ test( "Keyboard handling", function() { date = new Date(); input.datepicker( "open" ) - .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER }); + .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), date, "Keystroke enter" ); // Enter = Select today's date by default input.val( "1/1/14" ).datepicker( "open" ) - .simulate("keydown", { keyCode: $.ui.keyCode.ENTER }); + .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), new Date( 2014, 0, 1 ), "Keystroke enter - preset" ); // Control + Home = Change the calendar to the current month input.val( "1/1/14" ).datepicker( "open" ) - .simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.HOME }) - .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER }); + .simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.HOME } ) + .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), date, "Keystroke ctrl+home" ); // Control + End = Close the calendar and clear the input input.val( "1/1/14" ).datepicker( "open" ) - .simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.END }); + .simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.END } ); equal( input.val(), "", "Keystroke ctrl+end" ); input.val( "" ).datepicker( "open" ); ok( instance.isOpen, "datepicker is open before escape" ); - input.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE }); + input.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } ); ok( !instance.isOpen, "escape closes the datepicker" ); input.val( "1/1/14" ).datepicker( "open" ) - .simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE }); + .simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } ); TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), new Date( 2014, 0, 1 ), "Keystroke esc - preset" ); input.val( "1/1/14" ).datepicker( "open" ) - .simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP }) - .simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE }); + .simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP } ) + .simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } ); TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), new Date( 2014, 0, 1 ), "Keystroke esc - abandoned" ); @@ -279,38 +279,38 @@ asyncTest( "keyboard handling", function() { picker = input.datepicker( "widget" ); ok( !picker.is( ":visible" ), "datepicker closed" ); input.val( "" ) - .simulate( "keydown", { keyCode: $.ui.keyCode.DOWN }); + .simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); setTimeout(function() { ok( picker.is( ":visible" ), "Keystroke down opens datepicker" ); input.datepicker( "destroy" ); step2(); }); - }; + } function step2() { input.datepicker(); - picker = input.datepicker( "widget" ) + picker = input.datepicker( "widget" ); ok( !picker.is( ":visible" ), "datepicker closed" ); input.val( "" ) - .simulate( "keydown", { keyCode: $.ui.keyCode.UP }); + .simulate( "keydown", { keyCode: $.ui.keyCode.UP } ); setTimeout(function() { ok( picker.is( ":visible" ), "Keystroke up opens datepicker" ); input.datepicker( "destroy" ); step3(); }); - }; + } function step3() { input.datepicker() .val( "1/1/14" ) - .simulate( "keydown", { keyCode: $.ui.keyCode.DOWN }); + .simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); setTimeout(function() { $( ":focus" ) - .simulate( "keydown", { keyCode: $.ui.keyCode.LEFT }) - .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER }); + .simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ) + .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); date = new Date( 2013, 12 - 1, 31 ); TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), date, "Keystroke left to switch to previous day" ); @@ -318,17 +318,17 @@ asyncTest( "keyboard handling", function() { input.datepicker( "destroy" ); step4(); }, 100 ); - }; + } function step4() { input.datepicker() .val( "1/1/14" ) - .simulate( "keydown", { keyCode: $.ui.keyCode.DOWN }); + .simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); setTimeout(function() { $( ":focus" ) - .simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT }) - .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER }); + .simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } ) + .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); date = new Date( 2014, 1 - 1, 2 ); TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), date, "Keystroke right to switch to next day" ); @@ -336,17 +336,17 @@ asyncTest( "keyboard handling", function() { input.datepicker( "destroy" ); step5(); }, 100 ); - }; + } function step5() { input.datepicker() .val( "1/1/14" ) - .simulate( "keydown", { keyCode: $.ui.keyCode.DOWN }); + .simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); setTimeout(function() { $( ":focus" ) - .simulate( "keydown", { keyCode: $.ui.keyCode.UP }) - .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER }); + .simulate( "keydown", { keyCode: $.ui.keyCode.UP } ) + .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); date = new Date( 2013, 12 - 1, 25 ); TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), date, "Keystroke up to move to the previous week" ); @@ -354,17 +354,17 @@ asyncTest( "keyboard handling", function() { input.datepicker( "destroy" ); step6(); }, 100 ); - }; + } function step6() { input.datepicker() .val( "1/1/14" ) - .simulate( "keydown", { keyCode: $.ui.keyCode.DOWN }); + .simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); setTimeout(function() { $( ":focus" ) - .simulate( "keydown", { keyCode: $.ui.keyCode.DOWN }) - .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER }); + .simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ) + .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); date = new Date( 2014, 1 - 1, 8 ); TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), date, "Keystroke down to move to the next week" ); @@ -372,17 +372,17 @@ asyncTest( "keyboard handling", function() { input.datepicker( "destroy" ); step7(); }, 100 ); - }; + } function step7() { input.datepicker() .val( "1/1/14" ) - .simulate( "keydown", { keyCode: $.ui.keyCode.DOWN }); + .simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); setTimeout(function() { $( ":focus" ) - .simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP }) - .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER }); + .simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ) + .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); date = new Date( 2013, 12 - 1, 1 ); TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), date, "Keystroke Page Up moves date to previous month" ); @@ -390,17 +390,17 @@ asyncTest( "keyboard handling", function() { input.datepicker( "destroy" ); step8(); }, 100 ); - }; + } function step8() { input.datepicker() .val( "1/1/14" ) - .simulate( "keydown", { keyCode: $.ui.keyCode.DOWN }); + .simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); setTimeout(function() { $( ":focus" ) - .simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP, altKey: true }) - .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER }); + .simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP, altKey: true } ) + .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); date = new Date( 2013, 1 - 1, 1 ); TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), date, "Keystroke Page Up + Ctrl moves date to previous year" ); @@ -408,17 +408,17 @@ asyncTest( "keyboard handling", function() { input.datepicker( "destroy" ); step9(); }, 100 ); - }; + } function step9() { input.datepicker() .val( "1/1/14" ) - .simulate( "keydown", { keyCode: $.ui.keyCode.DOWN }); + .simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); setTimeout(function() { $( ":focus" ) - .simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN }) - .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER }); + .simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ) + .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); date = new Date( 2014, 2 - 1, 1 ); TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), date, "Keystroke Page Down moves date to next month" ); @@ -426,17 +426,17 @@ asyncTest( "keyboard handling", function() { input.datepicker( "destroy" ); step10(); }, 100 ); - }; + } function step10() { input.datepicker() .val( "1/1/14" ) - .simulate( "keydown", { keyCode: $.ui.keyCode.DOWN }); + .simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); setTimeout(function() { $( ":focus" ) - .simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN, altKey: true }) - .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER }); + .simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN, altKey: true } ) + .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); date = new Date( 2015, 1 - 1, 1 ); TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), date, "Keystroke Page Down + Ctrl moves date to next year" ); @@ -444,18 +444,18 @@ asyncTest( "keyboard handling", function() { input.datepicker( "destroy" ); step11(); }, 100 ); - }; + } // Check for moving to short months function step11() { input.datepicker() .val( "3/31/14" ) - .simulate( "keydown", { keyCode: $.ui.keyCode.DOWN }); + .simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); setTimeout(function() { $( ":focus" ) - .simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP }) - .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER }); + .simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ) + .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); date = new Date( 2014, 2 - 1, 28 ); TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), date, "Keystroke Page Up and short months" ); @@ -463,17 +463,17 @@ asyncTest( "keyboard handling", function() { input.datepicker( "destroy" ); step12(); }, 100 ); - }; + } function step12() { input.datepicker() .val( "1/30/16" ) - .simulate( "keydown", { keyCode: $.ui.keyCode.DOWN }); + .simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); setTimeout(function() { $( ":focus" ) - .simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN }) - .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER }); + .simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ) + .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); date = new Date( 2016, 2 - 1, 29 ); TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), date, "Keystroke Page Down and leap years" ); @@ -481,23 +481,23 @@ asyncTest( "keyboard handling", function() { input.datepicker( "destroy" ); start(); }, 100 ); - }; + } step1(); }); /* // TODO: Re-add tests if we implement a stepMonths option - input.datepicker( "option", { stepMonths: 2, gotoCurrent: false }) + input.datepicker( "option", { stepMonths: 2, gotoCurrent: false } ) .datepicker( "close" ).val( "02/04/2008" ).datepicker( "open" ) - .late( "keydown", { keyCode: $.ui.keyCode.PAGE_UP }) - .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER }); + .late( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ) + .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), new Date( 2007, 12 - 1, 4 ), "Keystroke pgup step 2" ); input.val( "02/04/2008" ).datepicker( "open" ) - .simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN }) - .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER }); + .simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ) + .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), new Date( 2008, 4 - 1, 4 ), "Keystroke pgdn step 2" ); */ @@ -516,8 +516,8 @@ test( "mouse", function() { input.val( "2/4/08" ).datepicker( "open" ); $( ".ui-datepicker-calendar tbody a:contains(12)", picker ).simulate( "mousedown", {} ); - TestHelpers.datepicker.equalsDate( input.datepicker("valueAsDate"), new Date( 2008, 2 - 1, 12 ), - "Mouse click - preset") ; + TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), new Date( 2008, 2 - 1, 12 ), + "Mouse click - preset" ) ; input.val( "" ).datepicker( "open" ); $( "button.ui-datepicker-close", picker ).simulate( "click", {} ); @@ -547,15 +547,15 @@ test( "mouse", function() { "Mouse click - previous" ); input.val( "2/4/08" ).datepicker( "open" ); - $(".ui-datepicker-next", picker ).simulate( "click" ); - $(".ui-datepicker-calendar tbody a:contains(18)", picker ).simulate( "mousedown" ); - TestHelpers.datepicker.equalsDate( input.datepicker("valueAsDate"), new Date( 2008, 3 - 1, 18 ), + $( ".ui-datepicker-next", picker ).simulate( "click" ); + $( ".ui-datepicker-calendar tbody a:contains(18)", picker ).simulate( "mousedown" ); + TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), new Date( 2008, 3 - 1, 18 ), "Mouse click - next" ); /* // TODO: Re-add when min and max options are introduced. // Previous/next with minimum/maximum - input.datepicker("option", { + input.datepicker( "option", { minDate: new Date( 2008, 2 - 1, 2 ), maxDate: new Date( 2008, 2 - 1, 26 ) }).val( "2/4/08" ).datepicker( "open" ); @@ -580,13 +580,13 @@ test( "mouse", function() { date.setDate( 10 ); TestHelpers.datepicker.equalsDate( inline.datepicker( "valueAsDate" ), date, "Mouse click inline" ); - inline.datepicker( "option", { showButtonPanel: true }) + inline.datepicker( "option", { showButtonPanel: true } ) .datepicker( "valueAsDate", new Date( 2008, 2 - 1, 4 )); $( ".ui-datepicker-calendar tbody a:contains(12)", picker ).simulate( "mousedown", {} ); TestHelpers.datepicker.equalsDate( inline.datepicker( "valueAsDate" ), new Date( 2008, 2 - 1, 12 ), "Mouse click inline - preset" ); - inline.datepicker("option", { showButtonPanel: true }); + inline.datepicker( "option", { showButtonPanel: true } ); $( ".ui-datepicker-current", picker ).simulate( "click", {} ); $( ".ui-datepicker-calendar tbody a:contains(14)", picker ).simulate( "mousedown", {} ); date.setDate( 14 ); diff --git a/tests/unit/datepicker/datepicker_events.js b/tests/unit/datepicker/datepicker_events.js index 63e2b0e9c..9ee254e53 100644 --- a/tests/unit/datepicker/datepicker_events.js +++ b/tests/unit/datepicker/datepicker_events.js @@ -1,3 +1,10 @@ +// The implement of events is completely changing therefore these tests are no longer directly +// relevant. Leaving them around commented out so we can ensure the functionality is replicated. +// For example: +// TODO: In the old implementation the Enter key select's today's date when the has +// focus and is empty. Do we want to replicate this behavior in the rewrite? +/* + (function( $ ) { module( "datepicker: events" ); @@ -18,12 +25,6 @@ test( "select", function() { expect( 0 ); }); -// The implement of events is completely changing therefore these tests are no longer directly -// relevant. Leaving them around commented out so we can ensure the functionality is replicated. -// For example: -// TODO: In the old implementation the Enter key select's today's date when the has -// focus and is empty. Do we want to replicate this behavior in the rewrite? -/* var selectedThis = null, selectedDate = null, selectedInst = null; @@ -40,110 +41,110 @@ function callback2(year, month, inst) { selectedInst = inst; } -test("events", function() { +test( "events", function() { expect( 26 ); var dateStr, newMonthYear, inp2, - inp = TestHelpers.datepicker.init("#inp", {onSelect: callback}), + inp = TestHelpers.datepicker.init( "#inp", {onSelect: callback}), date = new Date(); // onSelect - inp.val("").datepicker("show"). - simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); - equal(selectedThis, inp[0], "Callback selected this"); - equal(selectedInst, $.data(inp[0], TestHelpers.datepicker.PROP_NAME), "Callback selected inst"); - equal(selectedDate, $.datepicker.formatDate("mm/dd/yy", date), - "Callback selected date"); - inp.val("").datepicker("show"). - simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.DOWN}). - simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); + inp.val( "" ).datepicker( "show" ). + simulate( "keydown", {keyCode: $.ui.keyCode.ENTER}); + equal(selectedThis, inp[0], "Callback selected this" ); + equal(selectedInst, $.data(inp[0], TestHelpers.datepicker.PROP_NAME), "Callback selected inst" ); + equal(selectedDate, $.datepicker.formatDate( "mm/dd/yy", date), + "Callback selected date" ); + inp.val( "" ).datepicker( "show" ). + simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.DOWN}). + simulate( "keydown", {keyCode: $.ui.keyCode.ENTER}); date.setDate(date.getDate() + 7); - equal(selectedDate, $.datepicker.formatDate("mm/dd/yy", date), - "Callback selected date - ctrl+down"); - inp.val("").datepicker("show"). - simulate("keydown", {keyCode: $.ui.keyCode.ESCAPE}); - equal(selectedDate, $.datepicker.formatDate("mm/dd/yy", date), - "Callback selected date - esc"); + equal(selectedDate, $.datepicker.formatDate( "mm/dd/yy", date), + "Callback selected date - ctrl+down" ); + inp.val( "" ).datepicker( "show" ). + simulate( "keydown", {keyCode: $.ui.keyCode.ESCAPE}); + equal(selectedDate, $.datepicker.formatDate( "mm/dd/yy", date), + "Callback selected date - esc" ); dateStr = "02/04/2008"; - inp.val(dateStr).datepicker("show"). - simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); + inp.val(dateStr).datepicker( "show" ). + simulate( "keydown", {keyCode: $.ui.keyCode.ENTER}); equal(dateStr, selectedDate, - "onSelect is called after enter keydown"); + "onSelect is called after enter keydown" ); // onChangeMonthYear - inp.datepicker("option", {onChangeMonthYear: callback2, onSelect: null}). - val("").datepicker("show"); + inp.datepicker( "option", {onChangeMonthYear: callback2, onSelect: null}). + val( "" ).datepicker( "show" ); newMonthYear = function(date) { return date.getFullYear() + "/" + (date.getMonth() + 1); }; date = new Date(); date.setDate(1); - inp.simulate("keydown", {keyCode: $.ui.keyCode.PAGE_UP}); + inp.simulate( "keydown", {keyCode: $.ui.keyCode.PAGE_UP}); date.setMonth(date.getMonth() - 1); - equal(selectedThis, inp[0], "Callback change month/year this"); - equal(selectedInst, $.data(inp[0], TestHelpers.datepicker.PROP_NAME), "Callback change month/year inst"); + equal(selectedThis, inp[0], "Callback change month/year this" ); + equal(selectedInst, $.data(inp[0], TestHelpers.datepicker.PROP_NAME), "Callback change month/year inst" ); equal(selectedDate, newMonthYear(date), - "Callback change month/year date - pgup"); - inp.simulate("keydown", {keyCode: $.ui.keyCode.PAGE_DOWN}); + "Callback change month/year date - pgup" ); + inp.simulate( "keydown", {keyCode: $.ui.keyCode.PAGE_DOWN}); date.setMonth(date.getMonth() + 1); equal(selectedDate, newMonthYear(date), - "Callback change month/year date - pgdn"); - inp.simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}); + "Callback change month/year date - pgdn" ); + inp.simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}); date.setFullYear(date.getFullYear() - 1); equal(selectedDate, newMonthYear(date), - "Callback change month/year date - ctrl+pgup"); - inp.simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.HOME}); + "Callback change month/year date - ctrl+pgup" ); + inp.simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.HOME}); date.setFullYear(date.getFullYear() + 1); equal(selectedDate, newMonthYear(date), - "Callback change month/year date - ctrl+home"); - inp.simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN}); + "Callback change month/year date - ctrl+home" ); + inp.simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN}); date.setFullYear(date.getFullYear() + 1); equal(selectedDate, newMonthYear(date), - "Callback change month/year date - ctrl+pgdn"); - inp.datepicker("setDate", new Date(2007, 1 - 1, 26)); - equal(selectedDate, "2007/1", "Callback change month/year date - setDate"); + "Callback change month/year date - ctrl+pgdn" ); + inp.datepicker( "setDate", new Date(2007, 1 - 1, 26)); + equal(selectedDate, "2007/1", "Callback change month/year date - setDate" ); selectedDate = null; - inp.datepicker("setDate", new Date(2007, 1 - 1, 12)); - ok(selectedDate == null, "Callback change month/year date - setDate no change"); + inp.datepicker( "setDate", new Date(2007, 1 - 1, 12)); + ok(selectedDate == null, "Callback change month/year date - setDate no change" ); // onChangeMonthYear step by 2 - inp.datepicker("option", {stepMonths: 2}). - datepicker("hide").val("").datepicker("show"). - simulate("keydown", {keyCode: $.ui.keyCode.PAGE_UP}); + inp.datepicker( "option", {stepMonths: 2}). + datepicker( "hide" ).val( "" ).datepicker( "show" ). + simulate( "keydown", {keyCode: $.ui.keyCode.PAGE_UP}); date.setMonth(date.getMonth() - 14); equal(selectedDate, newMonthYear(date), - "Callback change month/year by 2 date - pgup"); - inp.simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}); + "Callback change month/year by 2 date - pgup" ); + inp.simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}); date.setMonth(date.getMonth() - 12); equal(selectedDate, newMonthYear(date), - "Callback change month/year by 2 date - ctrl+pgup"); - inp.simulate("keydown", {keyCode: $.ui.keyCode.PAGE_DOWN}); + "Callback change month/year by 2 date - ctrl+pgup" ); + inp.simulate( "keydown", {keyCode: $.ui.keyCode.PAGE_DOWN}); date.setMonth(date.getMonth() + 2); equal(selectedDate, newMonthYear(date), - "Callback change month/year by 2 date - pgdn"); - inp.simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN}); + "Callback change month/year by 2 date - pgdn" ); + inp.simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN}); date.setMonth(date.getMonth() + 12); equal(selectedDate, newMonthYear(date), - "Callback change month/year by 2 date - ctrl+pgdn"); + "Callback change month/year by 2 date - ctrl+pgdn" ); // onClose - inp.datepicker("option", {onClose: callback, onChangeMonthYear: null, stepMonths: 1}). - val("").datepicker("show"). - simulate("keydown", {keyCode: $.ui.keyCode.ESCAPE}); - equal(selectedThis, inp[0], "Callback close this"); - equal(selectedInst, $.data(inp[0], TestHelpers.datepicker.PROP_NAME), "Callback close inst"); - equal(selectedDate, "", "Callback close date - esc"); - inp.val("").datepicker("show"). - simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); - equal(selectedDate, $.datepicker.formatDate("mm/dd/yy", new Date()), - "Callback close date - enter"); - inp.val("02/04/2008").datepicker("show"). - simulate("keydown", {keyCode: $.ui.keyCode.ESCAPE}); - equal(selectedDate, "02/04/2008", "Callback close date - preset"); - inp.val("02/04/2008").datepicker("show"). - simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.END}); - equal(selectedDate, "", "Callback close date - ctrl+end"); + inp.datepicker( "option", {onClose: callback, onChangeMonthYear: null, stepMonths: 1}). + val( "" ).datepicker( "show" ). + simulate( "keydown", {keyCode: $.ui.keyCode.ESCAPE}); + equal(selectedThis, inp[0], "Callback close this" ); + equal(selectedInst, $.data(inp[0], TestHelpers.datepicker.PROP_NAME), "Callback close inst" ); + equal(selectedDate, "", "Callback close date - esc" ); + inp.val( "" ).datepicker( "show" ). + simulate( "keydown", {keyCode: $.ui.keyCode.ENTER}); + equal(selectedDate, $.datepicker.formatDate( "mm/dd/yy", new Date()), + "Callback close date - enter" ); + inp.val( "02/04/2008" ).datepicker( "show" ). + simulate( "keydown", {keyCode: $.ui.keyCode.ESCAPE}); + equal(selectedDate, "02/04/2008", "Callback close date - preset" ); + inp.val( "02/04/2008" ).datepicker( "show" ). + simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.END}); + equal(selectedDate, "", "Callback close date - ctrl+end" ); - inp2 = TestHelpers.datepicker.init("#inp2"); - inp2.datepicker().datepicker("option", {onClose: callback}).datepicker("show"); - inp.datepicker("show"); - equal(selectedThis, inp2[0], "Callback close this"); + inp2 = TestHelpers.datepicker.init( "#inp2" ); + inp2.datepicker().datepicker( "option", {onClose: callback}).datepicker( "show" ); + inp.datepicker( "show" ); + equal(selectedThis, inp2[0], "Callback close this" ); }); -*/ })( jQuery ); + */ diff --git a/tests/unit/datepicker/datepicker_methods.js b/tests/unit/datepicker/datepicker_methods.js index 281a81c8d..7efea1069 100644 --- a/tests/unit/datepicker/datepicker_methods.js +++ b/tests/unit/datepicker/datepicker_methods.js @@ -51,7 +51,7 @@ test( "enable / disable", function() { test( "widget", function() { expect( 1 ); var actual = $( "#datepicker" ).datepicker().datepicker( "widget" ); - deepEqual( $("body > .ui-front" )[ 0 ], actual[ 0 ] ); + deepEqual( $( "body > .ui-front" )[ 0 ], actual[ 0 ] ); actual.remove(); }); diff --git a/tests/unit/datepicker/datepicker_options.js b/tests/unit/datepicker/datepicker_options.js index e541b7e70..17cc79f9a 100644 --- a/tests/unit/datepicker/datepicker_options.js +++ b/tests/unit/datepicker/datepicker_options.js @@ -44,7 +44,7 @@ test( "dateFormat", function() { expect( 2 ); var input = $( "#datepicker" ).val( "1/1/14" ).datepicker(), picker = input.datepicker( "widget" ), - firstDayLink = picker.find( "td[id]:first a" ); + firstDayLink = picker.find( "td[id]:first a" ); input.datepicker( "open" ); firstDayLink.trigger( "mousedown" ); @@ -60,7 +60,7 @@ test( "eachDay", function() { expect( 5 ); var timestamp, input = $( "#datepicker" ).datepicker(), - picker = input.datepicker( "widget" ); + picker = input.datepicker( "widget" ), firstCell = picker.find( "td[id]:first" ); equal( firstCell.find( "a" ).length, 1, "days are selectable by default" ); @@ -155,85 +155,85 @@ test( "showWeek", function() { }); /* -test("setDefaults", function() { +test( "setDefaults", function() { expect( 3 ); - TestHelpers.datepicker.init("#inp"); - equal($.datepicker._defaults.showOn, "focus", "Initial showOn"); + TestHelpers.datepicker.init( "#inp" ); + equal($.datepicker._defaults.showOn, "focus", "Initial showOn" ); $.datepicker.setDefaults({showOn: "button"}); - equal($.datepicker._defaults.showOn, "button", "Change default showOn"); + equal($.datepicker._defaults.showOn, "button", "Change default showOn" ); $.datepicker.setDefaults({showOn: "focus"}); - equal($.datepicker._defaults.showOn, "focus", "Restore showOn"); + equal($.datepicker._defaults.showOn, "focus", "Restore showOn" ); }); -test("option", function() { +test( "option", function() { expect( 17 ); - var inp = TestHelpers.datepicker.init("#inp"), + var inp = TestHelpers.datepicker.init( "#inp" ), inst = $.data(inp[0], TestHelpers.datepicker.PROP_NAME); // Set option - equal(inst.settings.showOn, null, "Initial setting showOn"); - equal($.datepicker._get(inst, "showOn"), "focus", "Initial instance showOn"); - equal($.datepicker._defaults.showOn, "focus", "Initial default showOn"); - inp.datepicker("option", "showOn", "button"); - equal(inst.settings.showOn, "button", "Change setting showOn"); - equal($.datepicker._get(inst, "showOn"), "button", "Change instance showOn"); - equal($.datepicker._defaults.showOn, "focus", "Retain default showOn"); - inp.datepicker("option", {showOn: "both"}); - equal(inst.settings.showOn, "both", "Change setting showOn"); - equal($.datepicker._get(inst, "showOn"), "both", "Change instance showOn"); - equal($.datepicker._defaults.showOn, "focus", "Retain default showOn"); - inp.datepicker("option", "showOn", undefined); - equal(inst.settings.showOn, null, "Clear setting showOn"); - equal($.datepicker._get(inst, "showOn"), "focus", "Restore instance showOn"); - equal($.datepicker._defaults.showOn, "focus", "Retain default showOn"); + equal(inst.settings.showOn, null, "Initial setting showOn" ); + equal($.datepicker._get(inst, "showOn" ), "focus", "Initial instance showOn" ); + equal($.datepicker._defaults.showOn, "focus", "Initial default showOn" ); + inp.datepicker( "option", "showOn", "button" ); + equal(inst.settings.showOn, "button", "Change setting showOn" ); + equal($.datepicker._get(inst, "showOn" ), "button", "Change instance showOn" ); + equal($.datepicker._defaults.showOn, "focus", "Retain default showOn" ); + inp.datepicker( "option", {showOn: "both"}); + equal(inst.settings.showOn, "both", "Change setting showOn" ); + equal($.datepicker._get(inst, "showOn" ), "both", "Change instance showOn" ); + equal($.datepicker._defaults.showOn, "focus", "Retain default showOn" ); + inp.datepicker( "option", "showOn", undefined); + equal(inst.settings.showOn, null, "Clear setting showOn" ); + equal($.datepicker._get(inst, "showOn" ), "focus", "Restore instance showOn" ); + equal($.datepicker._defaults.showOn, "focus", "Retain default showOn" ); // Get option - inp = TestHelpers.datepicker.init("#inp"); - equal(inp.datepicker("option", "showOn"), "focus", "Initial setting showOn"); - inp.datepicker("option", "showOn", "button"); - equal(inp.datepicker("option", "showOn"), "button", "Change instance showOn"); - inp.datepicker("option", "showOn", undefined); - equal(inp.datepicker("option", "showOn"), "focus", "Reset instance showOn"); - deepEqual(inp.datepicker("option", "all"), {showAnim: ""}, "Get instance settings"); - deepEqual(inp.datepicker("option", "defaults"), $.datepicker._defaults, - "Get default settings"); + inp = TestHelpers.datepicker.init( "#inp" ); + equal(inp.datepicker( "option", "showOn" ), "focus", "Initial setting showOn" ); + inp.datepicker( "option", "showOn", "button" ); + equal(inp.datepicker( "option", "showOn" ), "button", "Change instance showOn" ); + inp.datepicker( "option", "showOn", undefined); + equal(inp.datepicker( "option", "showOn" ), "focus", "Reset instance showOn" ); + deepEqual(inp.datepicker( "option", "all" ), {showAnim: ""}, "Get instance settings" ); + deepEqual(inp.datepicker( "option", "defaults" ), $.datepicker._defaults, + "Get default settings" ); }); test( "disabled", function() { expect(8); - var inp = TestHelpers.datepicker.init("#inp"); - ok(!inp.datepicker("isDisabled"), "Initially marked as enabled"); - ok(!inp[0].disabled, "Field initially enabled"); - inp.datepicker("option", "disabled", true); - ok(inp.datepicker("isDisabled"), "Marked as disabled"); - ok(inp[0].disabled, "Field now disabled"); - inp.datepicker("option", "disabled", false); - ok(!inp.datepicker("isDisabled"), "Marked as enabled"); - ok(!inp[0].disabled, "Field now enabled"); - inp.datepicker("destroy"); - - inp = TestHelpers.datepicker.init("#inp", { disabled: true }); - ok(inp.datepicker("isDisabled"), "Initially marked as disabled"); - ok(inp[0].disabled, "Field initially disabled"); + var inp = TestHelpers.datepicker.init( "#inp" ); + ok(!inp.datepicker( "isDisabled" ), "Initially marked as enabled" ); + ok(!inp[0].disabled, "Field initially enabled" ); + inp.datepicker( "option", "disabled", true); + ok(inp.datepicker( "isDisabled" ), "Marked as disabled" ); + ok(inp[0].disabled, "Field now disabled" ); + inp.datepicker( "option", "disabled", false); + ok(!inp.datepicker( "isDisabled" ), "Marked as enabled" ); + ok(!inp[0].disabled, "Field now enabled" ); + inp.datepicker( "destroy" ); + + inp = TestHelpers.datepicker.init( "#inp", { disabled: true }); + ok(inp.datepicker( "isDisabled" ), "Initially marked as disabled" ); + ok(inp[0].disabled, "Field initially disabled" ); }); -test("change", function() { +test( "change", function() { expect( 12 ); - var inp = TestHelpers.datepicker.init("#inp"), + var inp = TestHelpers.datepicker.init( "#inp" ), inst = $.data(inp[0], TestHelpers.datepicker.PROP_NAME); - equal(inst.settings.showOn, null, "Initial setting showOn"); - equal($.datepicker._get(inst, "showOn"), "focus", "Initial instance showOn"); - equal($.datepicker._defaults.showOn, "focus", "Initial default showOn"); - inp.datepicker("change", "showOn", "button"); - equal(inst.settings.showOn, "button", "Change setting showOn"); - equal($.datepicker._get(inst, "showOn"), "button", "Change instance showOn"); - equal($.datepicker._defaults.showOn, "focus", "Retain default showOn"); - inp.datepicker("change", {showOn: "both"}); - equal(inst.settings.showOn, "both", "Change setting showOn"); - equal($.datepicker._get(inst, "showOn"), "both", "Change instance showOn"); - equal($.datepicker._defaults.showOn, "focus", "Retain default showOn"); - inp.datepicker("change", "showOn", undefined); - equal(inst.settings.showOn, null, "Clear setting showOn"); - equal($.datepicker._get(inst, "showOn"), "focus", "Restore instance showOn"); - equal($.datepicker._defaults.showOn, "focus", "Retain default showOn"); + equal(inst.settings.showOn, null, "Initial setting showOn" ); + equal($.datepicker._get(inst, "showOn" ), "focus", "Initial instance showOn" ); + equal($.datepicker._defaults.showOn, "focus", "Initial default showOn" ); + inp.datepicker( "change", "showOn", "button" ); + equal(inst.settings.showOn, "button", "Change setting showOn" ); + equal($.datepicker._get(inst, "showOn" ), "button", "Change instance showOn" ); + equal($.datepicker._defaults.showOn, "focus", "Retain default showOn" ); + inp.datepicker( "change", {showOn: "both"}); + equal(inst.settings.showOn, "both", "Change setting showOn" ); + equal($.datepicker._get(inst, "showOn" ), "both", "Change instance showOn" ); + equal($.datepicker._defaults.showOn, "focus", "Retain default showOn" ); + inp.datepicker( "change", "showOn", undefined); + equal(inst.settings.showOn, null, "Clear setting showOn" ); + equal($.datepicker._get(inst, "showOn" ), "focus", "Restore instance showOn" ); + equal($.datepicker._defaults.showOn, "focus", "Retain default showOn" ); }); (function() { @@ -377,135 +377,135 @@ test("change", function() { }); })(); -test("otherMonths", function() { +test( "otherMonths", function() { expect( 8 ); - var inp = TestHelpers.datepicker.init("#inp"), - pop = $("#ui-datepicker-div"); - inp.val("06/01/2009").datepicker("show"); - equal(pop.find("tbody").text(), + var inp = TestHelpers.datepicker.init( "#inp" ), + pop = $( "#ui-datepicker-div" ); + inp.val( "06/01/2009" ).datepicker( "show" ); + equal(pop.find( "tbody" ).text(), // support: IE <9, jQuery <1.8 // In IE7/8 with jQuery <1.8, encoded spaces behave in strange ways $( "\u00a0123456789101112131415161718192021222324252627282930\u00a0\u00a0\u00a0\u00a0" ).text(), - "Other months - none"); - ok(pop.find("td:last *").length === 0, "Other months - no content"); - inp.datepicker("hide").datepicker("option", "showOtherMonths", true).datepicker("show"); - equal(pop.find("tbody").text(), "311234567891011121314151617181920212223242526272829301234", - "Other months - show"); - ok(pop.find("td:last span").length === 1, "Other months - span content"); - inp.datepicker("hide").datepicker("option", "selectOtherMonths", true).datepicker("show"); - equal(pop.find("tbody").text(), "311234567891011121314151617181920212223242526272829301234", - "Other months - select"); - ok(pop.find("td:last a").length === 1, "Other months - link content"); - inp.datepicker("hide").datepicker("option", "showOtherMonths", false).datepicker("show"); - equal(pop.find("tbody").text(), + "Other months - none" ); + ok(pop.find( "td:last *" ).length === 0, "Other months - no content" ); + inp.datepicker( "hide" ).datepicker( "option", "showOtherMonths", true).datepicker( "show" ); + equal(pop.find( "tbody" ).text(), "311234567891011121314151617181920212223242526272829301234", + "Other months - show" ); + ok(pop.find( "td:last span" ).length === 1, "Other months - span content" ); + inp.datepicker( "hide" ).datepicker( "option", "selectOtherMonths", true).datepicker( "show" ); + equal(pop.find( "tbody" ).text(), "311234567891011121314151617181920212223242526272829301234", + "Other months - select" ); + ok(pop.find( "td:last a" ).length === 1, "Other months - link content" ); + inp.datepicker( "hide" ).datepicker( "option", "showOtherMonths", false).datepicker( "show" ); + equal(pop.find( "tbody" ).text(), // support: IE <9, jQuery <1.8 // In IE7/8 with jQuery <1.8, encoded spaces behave in strange ways $( "\u00a0123456789101112131415161718192021222324252627282930\u00a0\u00a0\u00a0\u00a0" ).text(), - "Other months - none"); - ok(pop.find("td:last *").length === 0, "Other months - no content"); + "Other months - none" ); + ok(pop.find( "td:last *" ).length === 0, "Other months - no content" ); }); -test("defaultDate", function() { +test( "defaultDate", function() { expect( 16 ); - var inp = TestHelpers.datepicker.init("#inp"), + var inp = TestHelpers.datepicker.init( "#inp" ), date = new Date(); - inp.val("").datepicker("show"). - simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Default date null"); + inp.val( "" ).datepicker( "show" ). + simulate( "keydown", {keyCode: $.ui.keyCode.ENTER}); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), date, "Default date null" ); // Numeric values - inp.datepicker("option", {defaultDate: -2}). - datepicker("hide").val("").datepicker("show"). - simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); + inp.datepicker( "option", {defaultDate: -2}). + datepicker( "hide" ).val( "" ).datepicker( "show" ). + simulate( "keydown", {keyCode: $.ui.keyCode.ENTER}); date.setDate(date.getDate() - 2); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Default date -2"); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), date, "Default date -2" ); date = new Date(); - inp.datepicker("option", {defaultDate: 3}). - datepicker("hide").val("").datepicker("show"). - simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); + inp.datepicker( "option", {defaultDate: 3}). + datepicker( "hide" ).val( "" ).datepicker( "show" ). + simulate( "keydown", {keyCode: $.ui.keyCode.ENTER}); date.setDate(date.getDate() + 3); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Default date 3"); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), date, "Default date 3" ); date = new Date(); - inp.datepicker("option", {defaultDate: 1 / "a"}). - datepicker("hide").val("").datepicker("show"). - simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Default date NaN"); + inp.datepicker( "option", {defaultDate: 1 / "a"}). + datepicker( "hide" ).val( "" ).datepicker( "show" ). + simulate( "keydown", {keyCode: $.ui.keyCode.ENTER}); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), date, "Default date NaN" ); // String offset values - inp.datepicker("option", {defaultDate: "-1d"}). - datepicker("hide").val("").datepicker("show"). - simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); + inp.datepicker( "option", {defaultDate: "-1d"}). + datepicker( "hide" ).val( "" ).datepicker( "show" ). + simulate( "keydown", {keyCode: $.ui.keyCode.ENTER}); date.setDate(date.getDate() - 1); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Default date -1d"); - inp.datepicker("option", {defaultDate: "+3D"}). - datepicker("hide").val("").datepicker("show"). - simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), date, "Default date -1d" ); + inp.datepicker( "option", {defaultDate: "+3D"}). + datepicker( "hide" ).val( "" ).datepicker( "show" ). + simulate( "keydown", {keyCode: $.ui.keyCode.ENTER}); date.setDate(date.getDate() + 4); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Default date +3D"); - inp.datepicker("option", {defaultDate: " -2 w "}). - datepicker("hide").val("").datepicker("show"). - simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), date, "Default date +3D" ); + inp.datepicker( "option", {defaultDate: " -2 w "}). + datepicker( "hide" ).val( "" ).datepicker( "show" ). + simulate( "keydown", {keyCode: $.ui.keyCode.ENTER}); date = new Date(); date.setDate(date.getDate() - 14); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Default date -2 w"); - inp.datepicker("option", {defaultDate: "+1 W"}). - datepicker("hide").val("").datepicker("show"). - simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), date, "Default date -2 w" ); + inp.datepicker( "option", {defaultDate: "+1 W"}). + datepicker( "hide" ).val( "" ).datepicker( "show" ). + simulate( "keydown", {keyCode: $.ui.keyCode.ENTER}); date.setDate(date.getDate() + 21); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Default date +1 W"); - inp.datepicker("option", {defaultDate: " -1 m "}). - datepicker("hide").val("").datepicker("show"). - simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), date, "Default date +1 W" ); + inp.datepicker( "option", {defaultDate: " -1 m "}). + datepicker( "hide" ).val( "" ).datepicker( "show" ). + simulate( "keydown", {keyCode: $.ui.keyCode.ENTER}); date = TestHelpers.datepicker.addMonths(new Date(), -1); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Default date -1 m"); - inp.datepicker("option", {defaultDate: "+2M"}). - datepicker("hide").val("").datepicker("show"). - simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), date, "Default date -1 m" ); + inp.datepicker( "option", {defaultDate: "+2M"}). + datepicker( "hide" ).val( "" ).datepicker( "show" ). + simulate( "keydown", {keyCode: $.ui.keyCode.ENTER}); date = TestHelpers.datepicker.addMonths(new Date(), 2); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Default date +2M"); - inp.datepicker("option", {defaultDate: "-2y"}). - datepicker("hide").val("").datepicker("show"). - simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), date, "Default date +2M" ); + inp.datepicker( "option", {defaultDate: "-2y"}). + datepicker( "hide" ).val( "" ).datepicker( "show" ). + simulate( "keydown", {keyCode: $.ui.keyCode.ENTER}); date = new Date(); date.setFullYear(date.getFullYear() - 2); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Default date -2y"); - inp.datepicker("option", {defaultDate: "+1 Y "}). - datepicker("hide").val("").datepicker("show"). - simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), date, "Default date -2y" ); + inp.datepicker( "option", {defaultDate: "+1 Y "}). + datepicker( "hide" ).val( "" ).datepicker( "show" ). + simulate( "keydown", {keyCode: $.ui.keyCode.ENTER}); date.setFullYear(date.getFullYear() + 3); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Default date +1 Y"); - inp.datepicker("option", {defaultDate: "+1M +10d"}). - datepicker("hide").val("").datepicker("show"). - simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), date, "Default date +1 Y" ); + inp.datepicker( "option", {defaultDate: "+1M +10d"}). + datepicker( "hide" ).val( "" ).datepicker( "show" ). + simulate( "keydown", {keyCode: $.ui.keyCode.ENTER}); date = TestHelpers.datepicker.addMonths(new Date(), 1); date.setDate(date.getDate() + 10); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Default date +1M +10d"); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), date, "Default date +1M +10d" ); // String date values - inp.datepicker("option", {defaultDate: "07/04/2007"}). - datepicker("hide").val("").datepicker("show"). - simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); + inp.datepicker( "option", {defaultDate: "07/04/2007"}). + datepicker( "hide" ).val( "" ).datepicker( "show" ). + simulate( "keydown", {keyCode: $.ui.keyCode.ENTER}); date = new Date(2007, 7 - 1, 4); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Default date 07/04/2007"); - inp.datepicker("option", {dateFormat: "yy-mm-dd", defaultDate: "2007-04-02"}). - datepicker("hide").val("").datepicker("show"). - simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), date, "Default date 07/04/2007" ); + inp.datepicker( "option", {dateFormat: "yy-mm-dd", defaultDate: "2007-04-02"}). + datepicker( "hide" ).val( "" ).datepicker( "show" ). + simulate( "keydown", {keyCode: $.ui.keyCode.ENTER}); date = new Date(2007, 4 - 1, 2); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Default date 2007-04-02"); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), date, "Default date 2007-04-02" ); // Date value date = new Date(2007, 1 - 1, 26); - inp.datepicker("option", {dateFormat: "mm/dd/yy", defaultDate: date}). - datepicker("hide").val("").datepicker("show"). - simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, "Default date 01/26/2007"); + inp.datepicker( "option", {dateFormat: "mm/dd/yy", defaultDate: date}). + datepicker( "hide" ).val( "" ).datepicker( "show" ). + simulate( "keydown", {keyCode: $.ui.keyCode.ENTER}); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), date, "Default date 01/26/2007" ); }); -test("miscellaneous", function() { +test( "miscellaneous", function() { expect( 19 ); var curYear, longNames, shortNames, date, - dp = $("#ui-datepicker-div"), - inp = TestHelpers.datepicker.init("#inp"); + dp = $( "#ui-datepicker-div" ), + inp = TestHelpers.datepicker.init( "#inp" ); // Year range function genRange(start, offset) { var i = start, @@ -516,398 +516,398 @@ test("miscellaneous", function() { return range; } curYear = new Date().getFullYear(); - inp.val("02/04/2008").datepicker("show"); - equal(dp.find(".ui-datepicker-year").text(), "2008", "Year range - read-only default"); - inp.datepicker("hide").datepicker("option", {changeYear: true}).datepicker("show"); - equal(dp.find(".ui-datepicker-year").text(), genRange(2008 - 10, 21), "Year range - changeable default"); - inp.datepicker("hide").datepicker("option", {yearRange: "c-6:c+2", changeYear: true}).datepicker("show"); - equal(dp.find(".ui-datepicker-year").text(), genRange(2008 - 6, 9), "Year range - c-6:c+2"); - inp.datepicker("hide").datepicker("option", {yearRange: "2000:2010", changeYear: true}).datepicker("show"); - equal(dp.find(".ui-datepicker-year").text(), genRange(2000, 11), "Year range - 2000:2010"); - inp.datepicker("hide").datepicker("option", {yearRange: "-5:+3", changeYear: true}).datepicker("show"); - equal(dp.find(".ui-datepicker-year").text(), genRange(curYear - 5, 9), "Year range - -5:+3"); - inp.datepicker("hide").datepicker("option", {yearRange: "2000:-5", changeYear: true}).datepicker("show"); - equal(dp.find(".ui-datepicker-year").text(), genRange(2000, curYear - 2004), "Year range - 2000:-5"); - inp.datepicker("hide").datepicker("option", {yearRange: "", changeYear: true}).datepicker("show"); - equal(dp.find(".ui-datepicker-year").text(), genRange(curYear, 1), "Year range - -6:+2"); + inp.val( "02/04/2008" ).datepicker( "show" ); + equal(dp.find( ".ui-datepicker-year" ).text(), "2008", "Year range - read-only default" ); + inp.datepicker( "hide" ).datepicker( "option", {changeYear: true}).datepicker( "show" ); + equal(dp.find( ".ui-datepicker-year" ).text(), genRange(2008 - 10, 21), "Year range - changeable default" ); + inp.datepicker( "hide" ).datepicker( "option", {yearRange: "c-6:c+2", changeYear: true}).datepicker( "show" ); + equal(dp.find( ".ui-datepicker-year" ).text(), genRange(2008 - 6, 9), "Year range - c-6:c+2" ); + inp.datepicker( "hide" ).datepicker( "option", {yearRange: "2000:2010", changeYear: true}).datepicker( "show" ); + equal(dp.find( ".ui-datepicker-year" ).text(), genRange(2000, 11), "Year range - 2000:2010" ); + inp.datepicker( "hide" ).datepicker( "option", {yearRange: "-5:+3", changeYear: true}).datepicker( "show" ); + equal(dp.find( ".ui-datepicker-year" ).text(), genRange(curYear - 5, 9), "Year range - -5:+3" ); + inp.datepicker( "hide" ).datepicker( "option", {yearRange: "2000:-5", changeYear: true}).datepicker( "show" ); + equal(dp.find( ".ui-datepicker-year" ).text(), genRange(2000, curYear - 2004), "Year range - 2000:-5" ); + inp.datepicker( "hide" ).datepicker( "option", {yearRange: "", changeYear: true}).datepicker( "show" ); + equal(dp.find( ".ui-datepicker-year" ).text(), genRange(curYear, 1), "Year range - -6:+2" ); // Navigation as date format - inp.datepicker("option", {showButtonPanel: true}); - equal(dp.find(".ui-datepicker-prev").text(), "Prev", "Navigation prev - default"); - equal(dp.find(".ui-datepicker-current").text(), "Today", "Navigation current - default"); - equal(dp.find(".ui-datepicker-next").text(), "Next", "Navigation next - default"); - inp.datepicker("hide").datepicker("option", {navigationAsDateFormat: true, prevText: "< M", currentText: "MM", nextText: "M >"}). - val("02/04/2008").datepicker("show"); + inp.datepicker( "option", {showButtonPanel: true}); + equal(dp.find( ".ui-datepicker-prev" ).text(), "Prev", "Navigation prev - default" ); + equal(dp.find( ".ui-datepicker-current" ).text(), "Today", "Navigation current - default" ); + equal(dp.find( ".ui-datepicker-next" ).text(), "Next", "Navigation next - default" ); + inp.datepicker( "hide" ).datepicker( "option", {navigationAsDateFormat: true, prevText: "< M", currentText: "MM", nextText: "M >"}). + val( "02/04/2008" ).datepicker( "show" ); longNames = $.datepicker.regional[""].monthNames; shortNames = $.datepicker.regional[""].monthNamesShort; date = new Date(); - equal(dp.find(".ui-datepicker-prev").text(), "< " + shortNames[0], "Navigation prev - as date format"); - equal(dp.find(".ui-datepicker-current").text(), - longNames[date.getMonth()], "Navigation current - as date format"); - equal(dp.find(".ui-datepicker-next").text(), - shortNames[2] + " >", "Navigation next - as date format"); - inp.simulate("keydown", {keyCode: $.ui.keyCode.PAGE_DOWN}); - equal(dp.find(".ui-datepicker-prev").text(), - "< " + shortNames[1], "Navigation prev - as date format + pgdn"); - equal(dp.find(".ui-datepicker-current").text(), - longNames[date.getMonth()], "Navigation current - as date format + pgdn"); - equal(dp.find(".ui-datepicker-next").text(), - shortNames[3] + " >", "Navigation next - as date format + pgdn"); - inp.datepicker("hide").datepicker("option", {gotoCurrent: true}). - val("02/04/2008").datepicker("show"); - equal(dp.find(".ui-datepicker-prev").text(), - "< " + shortNames[0], "Navigation prev - as date format + goto current"); - equal(dp.find(".ui-datepicker-current").text(), - longNames[1], "Navigation current - as date format + goto current"); - equal(dp.find(".ui-datepicker-next").text(), - shortNames[2] + " >", "Navigation next - as date format + goto current"); + equal(dp.find( ".ui-datepicker-prev" ).text(), "< " + shortNames[0], "Navigation prev - as date format" ); + equal(dp.find( ".ui-datepicker-current" ).text(), + longNames[date.getMonth()], "Navigation current - as date format" ); + equal(dp.find( ".ui-datepicker-next" ).text(), + shortNames[2] + " >", "Navigation next - as date format" ); + inp.simulate( "keydown", {keyCode: $.ui.keyCode.PAGE_DOWN}); + equal(dp.find( ".ui-datepicker-prev" ).text(), + "< " + shortNames[1], "Navigation prev - as date format + pgdn" ); + equal(dp.find( ".ui-datepicker-current" ).text(), + longNames[date.getMonth()], "Navigation current - as date format + pgdn" ); + equal(dp.find( ".ui-datepicker-next" ).text(), + shortNames[3] + " >", "Navigation next - as date format + pgdn" ); + inp.datepicker( "hide" ).datepicker( "option", {gotoCurrent: true}). + val( "02/04/2008" ).datepicker( "show" ); + equal(dp.find( ".ui-datepicker-prev" ).text(), + "< " + shortNames[0], "Navigation prev - as date format + goto current" ); + equal(dp.find( ".ui-datepicker-current" ).text(), + longNames[1], "Navigation current - as date format + goto current" ); + equal(dp.find( ".ui-datepicker-next" ).text(), + shortNames[2] + " >", "Navigation next - as date format + goto current" ); }); -test("minMax", function() { +test( "minMax", function() { expect( 23 ); var date, - inp = TestHelpers.datepicker.init("#inp"), - dp = $("#ui-datepicker-div"), + inp = TestHelpers.datepicker.init( "#inp" ), + dp = $( "#ui-datepicker-div" ), lastYear = new Date(2007, 6 - 1, 4), nextYear = new Date(2009, 6 - 1, 4), minDate = new Date(2008, 2 - 1, 29), maxDate = new Date(2008, 12 - 1, 7); - inp.val("06/04/2008").datepicker("show"); - inp.simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}). - simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), lastYear, - "Min/max - null, null - ctrl+pgup"); - inp.val("06/04/2008").datepicker("show"); - inp.simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN}). - simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), nextYear, - "Min/max - null, null - ctrl+pgdn"); - inp.datepicker("option", {minDate: minDate}). - datepicker("hide").val("06/04/2008").datepicker("show"); - inp.simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}). - simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), minDate, - "Min/max - 02/29/2008, null - ctrl+pgup"); - inp.val("06/04/2008").datepicker("show"); - inp.simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN}). - simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), nextYear, - "Min/max - 02/29/2008, null - ctrl+pgdn"); - inp.datepicker("option", {maxDate: maxDate}). - datepicker("hide").val("06/04/2008").datepicker("show"); - inp.simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}). - simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), minDate, - "Min/max - 02/29/2008, 12/07/2008 - ctrl+pgup"); - inp.val("06/04/2008").datepicker("show"); - inp.simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN}). - simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), maxDate, - "Min/max - 02/29/2008, 12/07/2008 - ctrl+pgdn"); - inp.datepicker("option", {minDate: null}). - datepicker("hide").val("06/04/2008").datepicker("show"); - inp.simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}). - simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), lastYear, - "Min/max - null, 12/07/2008 - ctrl+pgup"); - inp.val("06/04/2008").datepicker("show"); - inp.simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN}). - simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), maxDate, - "Min/max - null, 12/07/2008 - ctrl+pgdn"); + inp.val( "06/04/2008" ).datepicker( "show" ); + inp.simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}). + simulate( "keydown", {keyCode: $.ui.keyCode.ENTER}); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), lastYear, + "Min/max - null, null - ctrl+pgup" ); + inp.val( "06/04/2008" ).datepicker( "show" ); + inp.simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN}). + simulate( "keydown", {keyCode: $.ui.keyCode.ENTER}); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), nextYear, + "Min/max - null, null - ctrl+pgdn" ); + inp.datepicker( "option", {minDate: minDate}). + datepicker( "hide" ).val( "06/04/2008" ).datepicker( "show" ); + inp.simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}). + simulate( "keydown", {keyCode: $.ui.keyCode.ENTER}); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), minDate, + "Min/max - 02/29/2008, null - ctrl+pgup" ); + inp.val( "06/04/2008" ).datepicker( "show" ); + inp.simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN}). + simulate( "keydown", {keyCode: $.ui.keyCode.ENTER}); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), nextYear, + "Min/max - 02/29/2008, null - ctrl+pgdn" ); + inp.datepicker( "option", {maxDate: maxDate}). + datepicker( "hide" ).val( "06/04/2008" ).datepicker( "show" ); + inp.simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}). + simulate( "keydown", {keyCode: $.ui.keyCode.ENTER}); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), minDate, + "Min/max - 02/29/2008, 12/07/2008 - ctrl+pgup" ); + inp.val( "06/04/2008" ).datepicker( "show" ); + inp.simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN}). + simulate( "keydown", {keyCode: $.ui.keyCode.ENTER}); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), maxDate, + "Min/max - 02/29/2008, 12/07/2008 - ctrl+pgdn" ); + inp.datepicker( "option", {minDate: null}). + datepicker( "hide" ).val( "06/04/2008" ).datepicker( "show" ); + inp.simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}). + simulate( "keydown", {keyCode: $.ui.keyCode.ENTER}); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), lastYear, + "Min/max - null, 12/07/2008 - ctrl+pgup" ); + inp.val( "06/04/2008" ).datepicker( "show" ); + inp.simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN}). + simulate( "keydown", {keyCode: $.ui.keyCode.ENTER}); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), maxDate, + "Min/max - null, 12/07/2008 - ctrl+pgdn" ); // Relative dates date = new Date(); date.setDate(date.getDate() - 7); - inp.datepicker("option", {minDate: "-1w", maxDate: "+1 M +10 D "}). - datepicker("hide").val("").datepicker("show"); - inp.simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}). - simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, - "Min/max - -1w, +1 M +10 D - ctrl+pgup"); + inp.datepicker( "option", {minDate: "-1w", maxDate: "+1 M +10 D "}). + datepicker( "hide" ).val( "" ).datepicker( "show" ); + inp.simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}). + simulate( "keydown", {keyCode: $.ui.keyCode.ENTER}); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), date, + "Min/max - -1w, +1 M +10 D - ctrl+pgup" ); date = TestHelpers.datepicker.addMonths(new Date(), 1); date.setDate(date.getDate() + 10); - inp.val("").datepicker("show"); - inp.simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN}). - simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date, - "Min/max - -1w, +1 M +10 D - ctrl+pgdn"); + inp.val( "" ).datepicker( "show" ); + inp.simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN}). + simulate( "keydown", {keyCode: $.ui.keyCode.ENTER}); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), date, + "Min/max - -1w, +1 M +10 D - ctrl+pgdn" ); // With existing date - inp = TestHelpers.datepicker.init("#inp"); - 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"); - inp.datepicker("option", {minDate: null}).val("01/04/2008").datepicker("option", {minDate: minDate}); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), minDate, "Min/max - setDate < min"); - 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"); - inp.datepicker("option", {maxDate: null}).val("01/04/2009").datepicker("option", {maxDate: maxDate}); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), maxDate, "Min/max - setDate > max"); - 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"); - 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"); - 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"); - - 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"); - inp.datepicker("setDate", "12/30/" + new Date().getFullYear()); - ok(dp.find(".ui-datepicker-next").hasClass("ui-state-disabled"), "Year Range Test - next button disabled at 12/30/maxYear"); - - inp.datepicker("option", { + inp = TestHelpers.datepicker.init( "#inp" ); + 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" ); + inp.datepicker( "option", {minDate: null}).val( "01/04/2008" ).datepicker( "option", {minDate: minDate}); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), minDate, "Min/max - setDate < min" ); + 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" ); + inp.datepicker( "option", {maxDate: null}).val( "01/04/2009" ).datepicker( "option", {maxDate: maxDate}); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), maxDate, "Min/max - setDate > max" ); + 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" ); + 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" ); + 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" ); + + 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" ); + inp.datepicker( "setDate", "12/30/" + new Date().getFullYear()); + ok(dp.find( ".ui-datepicker-next" ).hasClass( "ui-state-disabled" ), "Year Range Test - next button disabled at 12/30/maxYear" ); + + inp.datepicker( "option", { minDate: new Date(1900, 0, 1), maxDate: "-7Y", yearRange: "1900:-7" }).val( "" ); - ok(dp.find(".ui-datepicker-next").hasClass("ui-state-disabled"), "Year Range Test - relative - next button disabled"); - ok(!dp.find(".ui-datepicker-prev").hasClass("ui-state-disabled"), "Year Range Test - relative - prev button enabled"); + ok(dp.find( ".ui-datepicker-next" ).hasClass( "ui-state-disabled" ), "Year Range Test - relative - next button disabled" ); + ok(!dp.find( ".ui-datepicker-prev" ).hasClass( "ui-state-disabled" ), "Year Range Test - relative - prev button enabled" ); - inp.datepicker("option", { + inp.datepicker( "option", { minDate: new Date(1900, 0, 1), maxDate: "1/25/2007", yearRange: "1900:2007" }).val( "" ); - ok(dp.find(".ui-datepicker-next").hasClass("ui-state-disabled"), "Year Range Test - absolute - next button disabled"); - ok(!dp.find(".ui-datepicker-prev").hasClass("ui-state-disabled"), "Year Range Test - absolute - prev button enabled"); + ok(dp.find( ".ui-datepicker-next" ).hasClass( "ui-state-disabled" ), "Year Range Test - absolute - next button disabled" ); + ok(!dp.find( ".ui-datepicker-prev" ).hasClass( "ui-state-disabled" ), "Year Range Test - absolute - prev button enabled" ); }); -test("setDate", function() { +test( "setDate", function() { expect( 24 ); var inl, alt, minDate, maxDate, dateAndTimeToSet, dateAndTimeClone, - inp = TestHelpers.datepicker.init("#inp"), + inp = TestHelpers.datepicker.init( "#inp" ), date1 = new Date(2008, 6 - 1, 4), date2 = new Date(); - ok(inp.datepicker("getDate") == null, "Set date - default"); - inp.datepicker("setDate", date1); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date1, "Set date - 2008-06-04"); + ok(inp.datepicker( "getDate" ) == null, "Set date - default" ); + inp.datepicker( "setDate", date1); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), date1, "Set date - 2008-06-04" ); date1 = new Date(); date1.setDate(date1.getDate() + 7); - inp.datepicker("setDate", +7); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date1, "Set date - +7"); + inp.datepicker( "setDate", +7); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), date1, "Set date - +7" ); date2.setFullYear(date2.getFullYear() + 2); - inp.datepicker("setDate", "+2y"); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date2, "Set date - +2y"); - inp.datepicker("setDate", date1, date2); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date1, "Set date - two dates"); - inp.datepicker("setDate"); - ok(inp.datepicker("getDate") == null, "Set date - null"); + inp.datepicker( "setDate", "+2y" ); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), date2, "Set date - +2y" ); + inp.datepicker( "setDate", date1, date2); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), date1, "Set date - two dates" ); + inp.datepicker( "setDate" ); + ok(inp.datepicker( "getDate" ) == null, "Set date - null" ); // Relative to current date date1 = new Date(); date1.setDate(date1.getDate() + 7); - inp.datepicker("setDate", "c +7"); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date1, "Set date - c +7"); + inp.datepicker( "setDate", "c +7" ); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), date1, "Set date - c +7" ); date1.setDate(date1.getDate() + 7); - inp.datepicker("setDate", "c+7"); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date1, "Set date - c+7"); + inp.datepicker( "setDate", "c+7" ); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), date1, "Set date - c+7" ); date1.setDate(date1.getDate() - 21); - inp.datepicker("setDate", "c -3 w"); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date1, "Set date - c -3 w"); + inp.datepicker( "setDate", "c -3 w" ); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), date1, "Set date - c -3 w" ); // Inline - inl = TestHelpers.datepicker.init("#inl"); + inl = TestHelpers.datepicker.init( "#inl" ); date1 = new Date(2008, 6 - 1, 4); date2 = new Date(); - TestHelpers.datepicker.equalsDate(inl.datepicker("getDate"), date2, "Set date inline - default"); - inl.datepicker("setDate", date1); - TestHelpers.datepicker.equalsDate(inl.datepicker("getDate"), date1, "Set date inline - 2008-06-04"); + TestHelpers.datepicker.equalsDate(inl.datepicker( "getDate" ), date2, "Set date inline - default" ); + inl.datepicker( "setDate", date1); + TestHelpers.datepicker.equalsDate(inl.datepicker( "getDate" ), date1, "Set date inline - 2008-06-04" ); date1 = new Date(); date1.setDate(date1.getDate() + 7); - inl.datepicker("setDate", +7); - TestHelpers.datepicker.equalsDate(inl.datepicker("getDate"), date1, "Set date inline - +7"); + inl.datepicker( "setDate", +7); + TestHelpers.datepicker.equalsDate(inl.datepicker( "getDate" ), date1, "Set date inline - +7" ); date2.setFullYear(date2.getFullYear() + 2); - inl.datepicker("setDate", "+2y"); - TestHelpers.datepicker.equalsDate(inl.datepicker("getDate"), date2, "Set date inline - +2y"); - inl.datepicker("setDate", date1, date2); - TestHelpers.datepicker.equalsDate(inl.datepicker("getDate"), date1, "Set date inline - two dates"); - inl.datepicker("setDate"); - ok(inl.datepicker("getDate") == null, "Set date inline - null"); + inl.datepicker( "setDate", "+2y" ); + TestHelpers.datepicker.equalsDate(inl.datepicker( "getDate" ), date2, "Set date inline - +2y" ); + inl.datepicker( "setDate", date1, date2); + TestHelpers.datepicker.equalsDate(inl.datepicker( "getDate" ), date1, "Set date inline - two dates" ); + inl.datepicker( "setDate" ); + ok(inl.datepicker( "getDate" ) == null, "Set date inline - null" ); // Alternate field - alt = $("#alt"); - inp.datepicker("option", {altField: "#alt", altFormat: "yy-mm-dd"}); + alt = $( "#alt" ); + inp.datepicker( "option", {altField: "#alt", altFormat: "yy-mm-dd"}); date1 = new Date(2008, 6 - 1, 4); - inp.datepicker("setDate", date1); - equal(inp.val(), "06/04/2008", "Set date alternate - 06/04/2008"); - equal(alt.val(), "2008-06-04", "Set date alternate - 2008-06-04"); + inp.datepicker( "setDate", date1); + equal(inp.val(), "06/04/2008", "Set date alternate - 06/04/2008" ); + equal(alt.val(), "2008-06-04", "Set date alternate - 2008-06-04" ); // With minimum/maximum - inp = TestHelpers.datepicker.init("#inp"); + inp = TestHelpers.datepicker.init( "#inp" ); date1 = new Date(2008, 1 - 1, 4); date2 = new Date(2008, 6 - 1, 4); minDate = new Date(2008, 2 - 1, 29); maxDate = new Date(2008, 3 - 1, 28); - inp.val("").datepicker("option", {minDate: minDate}).datepicker("setDate", date2); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date2, "Set date min/max - setDate > min"); - inp.datepicker("setDate", date1); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), minDate, "Set date min/max - setDate < min"); - inp.val("").datepicker("option", {maxDate: maxDate, minDate: null}).datepicker("setDate", date1); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), date1, "Set date min/max - setDate < max"); - inp.datepicker("setDate", date2); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), maxDate, "Set date min/max - setDate > max"); - inp.val("").datepicker("option", {minDate: minDate}).datepicker("setDate", date1); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), minDate, "Set date min/max - setDate < min"); - inp.datepicker("setDate", date2); - TestHelpers.datepicker.equalsDate(inp.datepicker("getDate"), maxDate, "Set date min/max - setDate > max"); + inp.val( "" ).datepicker( "option", {minDate: minDate}).datepicker( "setDate", date2); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), date2, "Set date min/max - setDate > min" ); + inp.datepicker( "setDate", date1); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), minDate, "Set date min/max - setDate < min" ); + inp.val( "" ).datepicker( "option", {maxDate: maxDate, minDate: null}).datepicker( "setDate", date1); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), date1, "Set date min/max - setDate < max" ); + inp.datepicker( "setDate", date2); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), maxDate, "Set date min/max - setDate > max" ); + inp.val( "" ).datepicker( "option", {minDate: minDate}).datepicker( "setDate", date1); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), minDate, "Set date min/max - setDate < min" ); + inp.datepicker( "setDate", date2); + TestHelpers.datepicker.equalsDate(inp.datepicker( "getDate" ), maxDate, "Set date min/max - setDate > max" ); dateAndTimeToSet = new Date(2008, 3 - 1, 28, 1, 11, 0); dateAndTimeClone = new Date(2008, 3 - 1, 28, 1, 11, 0); - inp.datepicker("setDate", dateAndTimeToSet); - equal(dateAndTimeToSet.getTime(), dateAndTimeClone.getTime(), "Date object passed should not be changed by setDate"); + inp.datepicker( "setDate", dateAndTimeToSet); + equal(dateAndTimeToSet.getTime(), dateAndTimeClone.getTime(), "Date object passed should not be changed by setDate" ); }); -test("altField", function() { +test( "altField", function() { expect( 10 ); - var inp = TestHelpers.datepicker.init("#inp"), - alt = $("#alt"); + var inp = TestHelpers.datepicker.init( "#inp" ), + alt = $( "#alt" ); // No alternate field set - alt.val(""); - inp.val("06/04/2008").datepicker("show"); - inp.simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); - equal(inp.val(), "06/04/2008", "Alt field - dp - enter"); - equal(alt.val(), "", "Alt field - alt not set"); + alt.val( "" ); + inp.val( "06/04/2008" ).datepicker( "show" ); + inp.simulate( "keydown", {keyCode: $.ui.keyCode.ENTER}); + equal(inp.val(), "06/04/2008", "Alt field - dp - enter" ); + equal(alt.val(), "", "Alt field - alt not set" ); // Alternate field set - alt.val(""); - inp.datepicker("option", {altField: "#alt", altFormat: "yy-mm-dd"}). - val("06/04/2008").datepicker("show"); - inp.simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); - equal(inp.val(), "06/04/2008", "Alt field - dp - enter"); - equal(alt.val(), "2008-06-04", "Alt field - alt - enter"); + alt.val( "" ); + inp.datepicker( "option", {altField: "#alt", altFormat: "yy-mm-dd"}). + val( "06/04/2008" ).datepicker( "show" ); + inp.simulate( "keydown", {keyCode: $.ui.keyCode.ENTER}); + equal(inp.val(), "06/04/2008", "Alt field - dp - enter" ); + equal(alt.val(), "2008-06-04", "Alt field - alt - enter" ); // Move from initial date - alt.val(""); - inp.val("06/04/2008").datepicker("show"); - inp.simulate("keydown", {keyCode: $.ui.keyCode.PAGE_DOWN}). - simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); - equal(inp.val(), "07/04/2008", "Alt field - dp - pgdn"); - equal(alt.val(), "2008-07-04", "Alt field - alt - pgdn"); + alt.val( "" ); + inp.val( "06/04/2008" ).datepicker( "show" ); + inp.simulate( "keydown", {keyCode: $.ui.keyCode.PAGE_DOWN}). + simulate( "keydown", {keyCode: $.ui.keyCode.ENTER}); + equal(inp.val(), "07/04/2008", "Alt field - dp - pgdn" ); + equal(alt.val(), "2008-07-04", "Alt field - alt - pgdn" ); // Alternate field set - closed - alt.val(""); - inp.val("06/04/2008").datepicker("show"); - inp.simulate("keydown", {keyCode: $.ui.keyCode.PAGE_DOWN}). - simulate("keydown", {keyCode: $.ui.keyCode.ESCAPE}); - equal(inp.val(), "06/04/2008", "Alt field - dp - pgdn/esc"); - equal(alt.val(), "", "Alt field - alt - pgdn/esc"); + alt.val( "" ); + inp.val( "06/04/2008" ).datepicker( "show" ); + inp.simulate( "keydown", {keyCode: $.ui.keyCode.PAGE_DOWN}). + simulate( "keydown", {keyCode: $.ui.keyCode.ESCAPE}); + equal(inp.val(), "06/04/2008", "Alt field - dp - pgdn/esc" ); + equal(alt.val(), "", "Alt field - alt - pgdn/esc" ); // Clear date and alternate - alt.val(""); - inp.val("06/04/2008").datepicker("show"); - inp.simulate("keydown", {ctrlKey: true, keyCode: $.ui.keyCode.END}); - equal(inp.val(), "", "Alt field - dp - ctrl+end"); - equal(alt.val(), "", "Alt field - alt - ctrl+end"); + alt.val( "" ); + inp.val( "06/04/2008" ).datepicker( "show" ); + inp.simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.END}); + equal(inp.val(), "", "Alt field - dp - ctrl+end" ); + equal(alt.val(), "", "Alt field - alt - ctrl+end" ); }); -test("autoSize", function() { +test( "autoSize", function() { expect( 15 ); - var inp = TestHelpers.datepicker.init("#inp"); - equal(inp.prop("size"), 20, "Auto size - default"); - inp.datepicker("option", "autoSize", true); - equal(inp.prop("size"), 10, "Auto size - mm/dd/yy"); - inp.datepicker("option", "dateFormat", "m/d/yy"); - equal(inp.prop("size"), 10, "Auto size - m/d/yy"); - inp.datepicker("option", "dateFormat", "D M d yy"); - equal(inp.prop("size"), 15, "Auto size - D M d yy"); - inp.datepicker("option", "dateFormat", "DD, MM dd, yy"); - equal(inp.prop("size"), 29, "Auto size - DD, MM dd, yy"); + var inp = TestHelpers.datepicker.init( "#inp" ); + equal(inp.prop( "size" ), 20, "Auto size - default" ); + inp.datepicker( "option", "autoSize", true); + equal(inp.prop( "size" ), 10, "Auto size - mm/dd/yy" ); + inp.datepicker( "option", "dateFormat", "m/d/yy" ); + equal(inp.prop( "size" ), 10, "Auto size - m/d/yy" ); + inp.datepicker( "option", "dateFormat", "D M d yy" ); + equal(inp.prop( "size" ), 15, "Auto size - D M d yy" ); + inp.datepicker( "option", "dateFormat", "DD, MM dd, yy" ); + equal(inp.prop( "size" ), 29, "Auto size - DD, MM dd, yy" ); // French - inp.datepicker("option", $.extend({autoSize: false}, $.datepicker.regional.fr)); - equal(inp.prop("size"), 29, "Auto size - fr - default"); - inp.datepicker("option", "autoSize", true); - equal(inp.prop("size"), 10, "Auto size - fr - dd/mm/yy"); - inp.datepicker("option", "dateFormat", "m/d/yy"); - equal(inp.prop("size"), 10, "Auto size - fr - m/d/yy"); - inp.datepicker("option", "dateFormat", "D M d yy"); - equal(inp.prop("size"), 18, "Auto size - fr - D M d yy"); - inp.datepicker("option", "dateFormat", "DD, MM dd, yy"); - equal(inp.prop("size"), 28, "Auto size - fr - DD, MM dd, yy"); + inp.datepicker( "option", $.extend({autoSize: false}, $.datepicker.regional.fr)); + equal(inp.prop( "size" ), 29, "Auto size - fr - default" ); + inp.datepicker( "option", "autoSize", true); + equal(inp.prop( "size" ), 10, "Auto size - fr - dd/mm/yy" ); + inp.datepicker( "option", "dateFormat", "m/d/yy" ); + equal(inp.prop( "size" ), 10, "Auto size - fr - m/d/yy" ); + inp.datepicker( "option", "dateFormat", "D M d yy" ); + equal(inp.prop( "size" ), 18, "Auto size - fr - D M d yy" ); + inp.datepicker( "option", "dateFormat", "DD, MM dd, yy" ); + equal(inp.prop( "size" ), 28, "Auto size - fr - DD, MM dd, yy" ); // Hebrew - inp.datepicker("option", $.extend({autoSize: false}, $.datepicker.regional.he)); - equal(inp.prop("size"), 28, "Auto size - he - default"); - inp.datepicker("option", "autoSize", true); - equal(inp.prop("size"), 10, "Auto size - he - dd/mm/yy"); - inp.datepicker("option", "dateFormat", "m/d/yy"); - equal(inp.prop("size"), 10, "Auto size - he - m/d/yy"); - inp.datepicker("option", "dateFormat", "D M d yy"); - equal(inp.prop("size"), 16, "Auto size - he - D M d yy"); - inp.datepicker("option", "dateFormat", "DD, MM dd, yy"); - equal(inp.prop("size"), 23, "Auto size - he - DD, MM dd, yy"); + inp.datepicker( "option", $.extend({autoSize: false}, $.datepicker.regional.he)); + equal(inp.prop( "size" ), 28, "Auto size - he - default" ); + inp.datepicker( "option", "autoSize", true); + equal(inp.prop( "size" ), 10, "Auto size - he - dd/mm/yy" ); + inp.datepicker( "option", "dateFormat", "m/d/yy" ); + equal(inp.prop( "size" ), 10, "Auto size - he - m/d/yy" ); + inp.datepicker( "option", "dateFormat", "D M d yy" ); + equal(inp.prop( "size" ), 16, "Auto size - he - D M d yy" ); + inp.datepicker( "option", "dateFormat", "DD, MM dd, yy" ); + equal(inp.prop( "size" ), 23, "Auto size - he - DD, MM dd, yy" ); }); -test("daylightSaving", function() { +test( "daylightSaving", function() { expect( 25 ); - var inp = TestHelpers.datepicker.init("#inp"), - dp = $("#ui-datepicker-div"); + var inp = TestHelpers.datepicker.init( "#inp" ), + dp = $( "#ui-datepicker-div" ); ok(true, "Daylight saving - " + new Date()); // Australia, Sydney - AM change, southern hemisphere - inp.val("04/01/2008").datepicker("show"); - $(".ui-datepicker-calendar td:eq(6) a", dp).simulate("click"); - equal(inp.val(), "04/05/2008", "Daylight saving - Australia 04/05/2008"); - inp.val("04/01/2008").datepicker("show"); - $(".ui-datepicker-calendar td:eq(7) a", dp).simulate("click"); - equal(inp.val(), "04/06/2008", "Daylight saving - Australia 04/06/2008"); - inp.val("04/01/2008").datepicker("show"); - $(".ui-datepicker-calendar td:eq(8) a", dp).simulate("click"); - equal(inp.val(), "04/07/2008", "Daylight saving - Australia 04/07/2008"); - inp.val("10/01/2008").datepicker("show"); - $(".ui-datepicker-calendar td:eq(6) a", dp).simulate("click"); - equal(inp.val(), "10/04/2008", "Daylight saving - Australia 10/04/2008"); - inp.val("10/01/2008").datepicker("show"); - $(".ui-datepicker-calendar td:eq(7) a", dp).simulate("click"); - equal(inp.val(), "10/05/2008", "Daylight saving - Australia 10/05/2008"); - inp.val("10/01/2008").datepicker("show"); - $(".ui-datepicker-calendar td:eq(8) a", dp).simulate("click"); - equal(inp.val(), "10/06/2008", "Daylight saving - Australia 10/06/2008"); + inp.val( "04/01/2008" ).datepicker( "show" ); + $( ".ui-datepicker-calendar td:eq(6) a", dp).simulate( "click" ); + equal(inp.val(), "04/05/2008", "Daylight saving - Australia 04/05/2008" ); + inp.val( "04/01/2008" ).datepicker( "show" ); + $( ".ui-datepicker-calendar td:eq(7) a", dp).simulate( "click" ); + equal(inp.val(), "04/06/2008", "Daylight saving - Australia 04/06/2008" ); + inp.val( "04/01/2008" ).datepicker( "show" ); + $( ".ui-datepicker-calendar td:eq(8) a", dp).simulate( "click" ); + equal(inp.val(), "04/07/2008", "Daylight saving - Australia 04/07/2008" ); + inp.val( "10/01/2008" ).datepicker( "show" ); + $( ".ui-datepicker-calendar td:eq(6) a", dp).simulate( "click" ); + equal(inp.val(), "10/04/2008", "Daylight saving - Australia 10/04/2008" ); + inp.val( "10/01/2008" ).datepicker( "show" ); + $( ".ui-datepicker-calendar td:eq(7) a", dp).simulate( "click" ); + equal(inp.val(), "10/05/2008", "Daylight saving - Australia 10/05/2008" ); + inp.val( "10/01/2008" ).datepicker( "show" ); + $( ".ui-datepicker-calendar td:eq(8) a", dp).simulate( "click" ); + equal(inp.val(), "10/06/2008", "Daylight saving - Australia 10/06/2008" ); // Brasil, Brasilia - midnight change, southern hemisphere - inp.val("02/01/2008").datepicker("show"); - $(".ui-datepicker-calendar td:eq(20) a", dp).simulate("click"); - equal(inp.val(), "02/16/2008", "Daylight saving - Brasil 02/16/2008"); - inp.val("02/01/2008").datepicker("show"); - $(".ui-datepicker-calendar td:eq(21) a", dp).simulate("click"); - equal(inp.val(), "02/17/2008", "Daylight saving - Brasil 02/17/2008"); - inp.val("02/01/2008").datepicker("show"); - $(".ui-datepicker-calendar td:eq(22) a", dp).simulate("click"); - equal(inp.val(), "02/18/2008", "Daylight saving - Brasil 02/18/2008"); - inp.val("10/01/2008").datepicker("show"); - $(".ui-datepicker-calendar td:eq(13) a", dp).simulate("click"); - equal(inp.val(), "10/11/2008", "Daylight saving - Brasil 10/11/2008"); - inp.val("10/01/2008").datepicker("show"); - $(".ui-datepicker-calendar td:eq(14) a", dp).simulate("click"); - equal(inp.val(), "10/12/2008", "Daylight saving - Brasil 10/12/2008"); - inp.val("10/01/2008").datepicker("show"); - $(".ui-datepicker-calendar td:eq(15) a", dp).simulate("click"); - equal(inp.val(), "10/13/2008", "Daylight saving - Brasil 10/13/2008"); + inp.val( "02/01/2008" ).datepicker( "show" ); + $( ".ui-datepicker-calendar td:eq(20) a", dp).simulate( "click" ); + equal(inp.val(), "02/16/2008", "Daylight saving - Brasil 02/16/2008" ); + inp.val( "02/01/2008" ).datepicker( "show" ); + $( ".ui-datepicker-calendar td:eq(21) a", dp).simulate( "click" ); + equal(inp.val(), "02/17/2008", "Daylight saving - Brasil 02/17/2008" ); + inp.val( "02/01/2008" ).datepicker( "show" ); + $( ".ui-datepicker-calendar td:eq(22) a", dp).simulate( "click" ); + equal(inp.val(), "02/18/2008", "Daylight saving - Brasil 02/18/2008" ); + inp.val( "10/01/2008" ).datepicker( "show" ); + $( ".ui-datepicker-calendar td:eq(13) a", dp).simulate( "click" ); + equal(inp.val(), "10/11/2008", "Daylight saving - Brasil 10/11/2008" ); + inp.val( "10/01/2008" ).datepicker( "show" ); + $( ".ui-datepicker-calendar td:eq(14) a", dp).simulate( "click" ); + equal(inp.val(), "10/12/2008", "Daylight saving - Brasil 10/12/2008" ); + inp.val( "10/01/2008" ).datepicker( "show" ); + $( ".ui-datepicker-calendar td:eq(15) a", dp).simulate( "click" ); + equal(inp.val(), "10/13/2008", "Daylight saving - Brasil 10/13/2008" ); // Lebanon, Beirut - midnight change, northern hemisphere - inp.val("03/01/2008").datepicker("show"); - $(".ui-datepicker-calendar td:eq(34) a", dp).simulate("click"); - equal(inp.val(), "03/29/2008", "Daylight saving - Lebanon 03/29/2008"); - inp.val("03/01/2008").datepicker("show"); - $(".ui-datepicker-calendar td:eq(35) a", dp).simulate("click"); - equal(inp.val(), "03/30/2008", "Daylight saving - Lebanon 03/30/2008"); - inp.val("03/01/2008").datepicker("show"); - $(".ui-datepicker-calendar td:eq(36) a", dp).simulate("click"); - equal(inp.val(), "03/31/2008", "Daylight saving - Lebanon 03/31/2008"); - inp.val("10/01/2008").datepicker("show"); - $(".ui-datepicker-calendar td:eq(27) a", dp).simulate("click"); - equal(inp.val(), "10/25/2008", "Daylight saving - Lebanon 10/25/2008"); - inp.val("10/01/2008").datepicker("show"); - $(".ui-datepicker-calendar td:eq(28) a", dp).simulate("click"); - equal(inp.val(), "10/26/2008", "Daylight saving - Lebanon 10/26/2008"); - inp.val("10/01/2008").datepicker("show"); - $(".ui-datepicker-calendar td:eq(29) a", dp).simulate("click"); - equal(inp.val(), "10/27/2008", "Daylight saving - Lebanon 10/27/2008"); + inp.val( "03/01/2008" ).datepicker( "show" ); + $( ".ui-datepicker-calendar td:eq(34) a", dp).simulate( "click" ); + equal(inp.val(), "03/29/2008", "Daylight saving - Lebanon 03/29/2008" ); + inp.val( "03/01/2008" ).datepicker( "show" ); + $( ".ui-datepicker-calendar td:eq(35) a", dp).simulate( "click" ); + equal(inp.val(), "03/30/2008", "Daylight saving - Lebanon 03/30/2008" ); + inp.val( "03/01/2008" ).datepicker( "show" ); + $( ".ui-datepicker-calendar td:eq(36) a", dp).simulate( "click" ); + equal(inp.val(), "03/31/2008", "Daylight saving - Lebanon 03/31/2008" ); + inp.val( "10/01/2008" ).datepicker( "show" ); + $( ".ui-datepicker-calendar td:eq(27) a", dp).simulate( "click" ); + equal(inp.val(), "10/25/2008", "Daylight saving - Lebanon 10/25/2008" ); + inp.val( "10/01/2008" ).datepicker( "show" ); + $( ".ui-datepicker-calendar td:eq(28) a", dp).simulate( "click" ); + equal(inp.val(), "10/26/2008", "Daylight saving - Lebanon 10/26/2008" ); + inp.val( "10/01/2008" ).datepicker( "show" ); + $( ".ui-datepicker-calendar td:eq(29) a", dp).simulate( "click" ); + equal(inp.val(), "10/27/2008", "Daylight saving - Lebanon 10/27/2008" ); // US, Eastern - AM change, northern hemisphere - inp.val("03/01/2008").datepicker("show"); - $(".ui-datepicker-calendar td:eq(13) a", dp).simulate("click"); - equal(inp.val(), "03/08/2008", "Daylight saving - US 03/08/2008"); - inp.val("03/01/2008").datepicker("show"); - $(".ui-datepicker-calendar td:eq(14) a", dp).simulate("click"); - equal(inp.val(), "03/09/2008", "Daylight saving - US 03/09/2008"); - inp.val("03/01/2008").datepicker("show"); - $(".ui-datepicker-calendar td:eq(15) a", dp).simulate("click"); - equal(inp.val(), "03/10/2008", "Daylight saving - US 03/10/2008"); - inp.val("11/01/2008").datepicker("show"); - $(".ui-datepicker-calendar td:eq(6) a", dp).simulate("click"); - equal(inp.val(), "11/01/2008", "Daylight saving - US 11/01/2008"); - inp.val("11/01/2008").datepicker("show"); - $(".ui-datepicker-calendar td:eq(7) a", dp).simulate("click"); - equal(inp.val(), "11/02/2008", "Daylight saving - US 11/02/2008"); - inp.val("11/01/2008").datepicker("show"); - $(".ui-datepicker-calendar td:eq(8) a", dp).simulate("click"); - equal(inp.val(), "11/03/2008", "Daylight saving - US 11/03/2008"); + inp.val( "03/01/2008" ).datepicker( "show" ); + $( ".ui-datepicker-calendar td:eq(13) a", dp).simulate( "click" ); + equal(inp.val(), "03/08/2008", "Daylight saving - US 03/08/2008" ); + inp.val( "03/01/2008" ).datepicker( "show" ); + $( ".ui-datepicker-calendar td:eq(14) a", dp).simulate( "click" ); + equal(inp.val(), "03/09/2008", "Daylight saving - US 03/09/2008" ); + inp.val( "03/01/2008" ).datepicker( "show" ); + $( ".ui-datepicker-calendar td:eq(15) a", dp).simulate( "click" ); + equal(inp.val(), "03/10/2008", "Daylight saving - US 03/10/2008" ); + inp.val( "11/01/2008" ).datepicker( "show" ); + $( ".ui-datepicker-calendar td:eq(6) a", dp).simulate( "click" ); + equal(inp.val(), "11/01/2008", "Daylight saving - US 11/01/2008" ); + inp.val( "11/01/2008" ).datepicker( "show" ); + $( ".ui-datepicker-calendar td:eq(7) a", dp).simulate( "click" ); + equal(inp.val(), "11/02/2008", "Daylight saving - US 11/02/2008" ); + inp.val( "11/01/2008" ).datepicker( "show" ); + $( ".ui-datepicker-calendar td:eq(8) a", dp).simulate( "click" ); + equal(inp.val(), "11/03/2008", "Daylight saving - US 11/03/2008" ); }); var beforeShowThis = null, @@ -927,86 +927,86 @@ function beforeDay(date) { beforeShowDayThis = this; beforeShowDayOK &= (date > new Date(2008, 1 - 1, 26) && date < new Date(2008, 3 - 1, 6)); - return [(date.getDate() % 2 === 0), (date.getDate() % 10 === 0 ? "day10" : ""), - (date.getDate() % 3 === 0 ? "Divisble by 3" : "")]; + return [(date.getDate() % 2 === 0), (date.getDate() % 10 === 0 ? "day10" : "" ), + (date.getDate() % 3 === 0 ? "Divisble by 3" : "" )]; } -test("callbacks", function() { +test( "callbacks", function() { expect( 13 ); // Before show var dp, day20, day21, - inp = TestHelpers.datepicker.init("#inp", {beforeShow: beforeAll}), - inst = $.data(inp[0], "datepicker"); - equal($.datepicker._get(inst, "currentText"), "Today", "Before show - initial"); - inp.val("02/04/2008").datepicker("show"); - equal($.datepicker._get(inst, "currentText"), "Current", "Before show - changed"); - ok(beforeShowThis.id === inp[0].id, "Before show - this OK"); - ok(beforeShowInput.id === inp[0].id, "Before show - input OK"); - deepEqual(beforeShowInst, inst, "Before show - inst OK"); - inp.datepicker("hide").datepicker("destroy"); + inp = TestHelpers.datepicker.init( "#inp", {beforeShow: beforeAll}), + inst = $.data(inp[0], "datepicker" ); + equal($.datepicker._get(inst, "currentText" ), "Today", "Before show - initial" ); + inp.val( "02/04/2008" ).datepicker( "show" ); + equal($.datepicker._get(inst, "currentText" ), "Current", "Before show - changed" ); + ok(beforeShowThis.id === inp[0].id, "Before show - this OK" ); + ok(beforeShowInput.id === inp[0].id, "Before show - input OK" ); + deepEqual(beforeShowInst, inst, "Before show - inst OK" ); + inp.datepicker( "hide" ).datepicker( "destroy" ); // Before show day - inp = TestHelpers.datepicker.init("#inp", {beforeShowDay: beforeDay}); - dp = $("#ui-datepicker-div"); - inp.val("02/04/2008").datepicker("show"); - ok(beforeShowDayThis.id === inp[0].id, "Before show day - this OK"); - ok(beforeShowDayOK, "Before show day - dates OK"); - day20 = dp.find(".ui-datepicker-calendar td:contains('20')"); - day21 = dp.find(".ui-datepicker-calendar td:contains('21')"); - ok(!day20.is(".ui-datepicker-unselectable"), "Before show day - unselectable 20"); - ok(day21.is(".ui-datepicker-unselectable"), "Before show day - unselectable 21"); - ok(day20.is(".day10"), "Before show day - CSS 20"); - ok(!day21.is(".day10"), "Before show day - CSS 21"); - ok(!day20.attr("title"), "Before show day - title 20"); - ok(day21.attr("title") === "Divisble by 3", "Before show day - title 21"); - inp.datepicker("hide").datepicker("destroy"); + inp = TestHelpers.datepicker.init( "#inp", {beforeShowDay: beforeDay}); + dp = $( "#ui-datepicker-div" ); + inp.val( "02/04/2008" ).datepicker( "show" ); + ok(beforeShowDayThis.id === inp[0].id, "Before show day - this OK" ); + ok(beforeShowDayOK, "Before show day - dates OK" ); + day20 = dp.find( ".ui-datepicker-calendar td:contains('20')" ); + day21 = dp.find( ".ui-datepicker-calendar td:contains('21')" ); + ok(!day20.is( ".ui-datepicker-unselectable" ), "Before show day - unselectable 20" ); + ok(day21.is( ".ui-datepicker-unselectable" ), "Before show day - unselectable 21" ); + ok(day20.is( ".day10" ), "Before show day - CSS 20" ); + ok(!day21.is( ".day10" ), "Before show day - CSS 21" ); + ok(!day20.attr( "title" ), "Before show day - title 20" ); + ok(day21.attr( "title" ) === "Divisble by 3", "Before show day - title 21" ); + inp.datepicker( "hide" ).datepicker( "destroy" ); }); -test("beforeShowDay - tooltips with quotes", function() { +test( "beforeShowDay - tooltips with quotes", function() { expect( 1 ); var inp, dp; - inp = TestHelpers.datepicker.init("#inp", { + inp = TestHelpers.datepicker.init( "#inp", { beforeShowDay: function() { return [ true, "", "'" ]; } }); - dp = $("#ui-datepicker-div"); + dp = $( "#ui-datepicker-div" ); - inp.datepicker("show"); - equal( dp.find( ".ui-datepicker-calendar td:contains('9')").attr( "title" ), "'" ); - inp.datepicker("hide").datepicker("destroy"); + inp.datepicker( "show" ); + equal( dp.find( ".ui-datepicker-calendar td:contains('9')" ).attr( "title" ), "'" ); + inp.datepicker( "hide" ).datepicker( "destroy" ); }); -test("localisation", function() { +test( "localisation", function() { expect( 24 ); var dp, month, day, date, - inp = TestHelpers.datepicker.init("#inp", $.datepicker.regional.fr); - inp.datepicker("option", {dateFormat: "DD, d MM yy", showButtonPanel:true, changeMonth:true, changeYear:true}).val("").datepicker("show"); - dp = $("#ui-datepicker-div"); - equal($(".ui-datepicker-close", dp).text(), "Fermer", "Localisation - close"); - $(".ui-datepicker-close", dp).simulate("mouseover"); - equal($(".ui-datepicker-prev", dp).text(), "Précédent", "Localisation - previous"); - equal($(".ui-datepicker-current", dp).text(), "Aujourd'hui", "Localisation - current"); - equal($(".ui-datepicker-next", dp).text(), "Suivant", "Localisation - next"); + inp = TestHelpers.datepicker.init( "#inp", $.datepicker.regional.fr); + inp.datepicker( "option", {dateFormat: "DD, d MM yy", showButtonPanel:true, changeMonth:true, changeYear:true}).val( "" ).datepicker( "show" ); + dp = $( "#ui-datepicker-div" ); + equal($( ".ui-datepicker-close", dp).text(), "Fermer", "Localisation - close" ); + $( ".ui-datepicker-close", dp).simulate( "mouseover" ); + equal($( ".ui-datepicker-prev", dp).text(), "Précédent", "Localisation - previous" ); + equal($( ".ui-datepicker-current", dp).text(), "Aujourd'hui", "Localisation - current" ); + equal($( ".ui-datepicker-next", dp).text(), "Suivant", "Localisation - next" ); month = 0; - $(".ui-datepicker-month option", dp).each(function() { + $( ".ui-datepicker-month option", dp).each(function() { equal($(this).text(), $.datepicker.regional.fr.monthNamesShort[month], "Localisation - month " + month); month++; }); day = 1; - $(".ui-datepicker-calendar th", dp).each(function() { + $( ".ui-datepicker-calendar th", dp).each(function() { equal($(this).text(), $.datepicker.regional.fr.dayNamesMin[day], "Localisation - day " + day); day = (day + 1) % 7; }); - inp.simulate("keydown", {keyCode: $.ui.keyCode.ENTER}); + inp.simulate( "keydown", {keyCode: $.ui.keyCode.ENTER}); date = new Date(); equal(inp.val(), $.datepicker.regional.fr.dayNames[date.getDay()] + ", " + date.getDate() + " " + $.datepicker.regional.fr.monthNames[date.getMonth()] + - " " + date.getFullYear(), "Localisation - formatting"); + " " + date.getFullYear(), "Localisation - formatting" ); }); -test("noWeekends", function() { +test( "noWeekends", function() { expect( 31 ); var i, date; for (i = 1; i <= 31; i++) { @@ -1016,7 +1016,7 @@ test("noWeekends", function() { } }); -test("iso8601Week", function() { +test( "iso8601Week", function() { expect( 12 ); var date = new Date(2000, 12 - 1, 31); equal($.datepicker.iso8601Week(date), 52, "ISO 8601 week " + date); @@ -1044,69 +1044,69 @@ test("iso8601Week", function() { equal($.datepicker.iso8601Week(date), 1, "ISO 8601 week " + date); }); -test("parseDate", function() { +test( "parseDate", function() { expect( 26 ); - TestHelpers.datepicker.init("#inp"); + TestHelpers.datepicker.init( "#inp" ); var currentYear, gmtDate, fr, settings, zh; - ok($.datepicker.parseDate("d m y", "") == null, "Parse date empty"); - TestHelpers.datepicker.equalsDate($.datepicker.parseDate("d m y", "3 2 01"), - new Date(2001, 2 - 1, 3), "Parse date d m y"); - TestHelpers.datepicker.equalsDate($.datepicker.parseDate("dd mm yy", "03 02 2001"), - new Date(2001, 2 - 1, 3), "Parse date dd mm yy"); - TestHelpers.datepicker.equalsDate($.datepicker.parseDate("d m y", "13 12 01"), - new Date(2001, 12 - 1, 13), "Parse date d m y"); - TestHelpers.datepicker.equalsDate($.datepicker.parseDate("dd mm yy", "13 12 2001"), - new Date(2001, 12 - 1, 13), "Parse date dd mm yy"); - TestHelpers.datepicker.equalsDate($.datepicker.parseDate("y-o", "01-34"), - new Date(2001, 2 - 1, 3), "Parse date y-o"); - TestHelpers.datepicker.equalsDate($.datepicker.parseDate("yy-oo", "2001-347"), - new Date(2001, 12 - 1, 13), "Parse date yy-oo"); - TestHelpers.datepicker.equalsDate($.datepicker.parseDate("oo yy", "348 2004"), - new Date(2004, 12 - 1, 13), "Parse date oo yy"); - TestHelpers.datepicker.equalsDate($.datepicker.parseDate("D d M y", "Sat 3 Feb 01"), - 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"), - 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"), - new Date(2001, 2 - 1, 3), "Parse date DD, MM d, yy"); - TestHelpers.datepicker.equalsDate($.datepicker.parseDate("'day' d 'of' MM (''DD''), yy", - "day 3 of February ('Saturday'), 2001"), new Date(2001, 2 - 1, 3), - "Parse date 'day' d 'of' MM (''DD''), yy"); + ok($.datepicker.parseDate( "d m y", "" ) == null, "Parse date empty" ); + TestHelpers.datepicker.equalsDate($.datepicker.parseDate( "d m y", "3 2 01" ), + new Date(2001, 2 - 1, 3), "Parse date d m y" ); + TestHelpers.datepicker.equalsDate($.datepicker.parseDate( "dd mm yy", "03 02 2001" ), + new Date(2001, 2 - 1, 3), "Parse date dd mm yy" ); + TestHelpers.datepicker.equalsDate($.datepicker.parseDate( "d m y", "13 12 01" ), + new Date(2001, 12 - 1, 13), "Parse date d m y" ); + TestHelpers.datepicker.equalsDate($.datepicker.parseDate( "dd mm yy", "13 12 2001" ), + new Date(2001, 12 - 1, 13), "Parse date dd mm yy" ); + TestHelpers.datepicker.equalsDate($.datepicker.parseDate( "y-o", "01-34" ), + new Date(2001, 2 - 1, 3), "Parse date y-o" ); + TestHelpers.datepicker.equalsDate($.datepicker.parseDate( "yy-oo", "2001-347" ), + new Date(2001, 12 - 1, 13), "Parse date yy-oo" ); + TestHelpers.datepicker.equalsDate($.datepicker.parseDate( "oo yy", "348 2004" ), + new Date(2004, 12 - 1, 13), "Parse date oo yy" ); + TestHelpers.datepicker.equalsDate($.datepicker.parseDate( "D d M y", "Sat 3 Feb 01" ), + 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" ), + 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" ), + new Date(2001, 2 - 1, 3), "Parse date DD, MM d, yy" ); + TestHelpers.datepicker.equalsDate($.datepicker.parseDate( "'day' d 'of' MM (''DD''), yy", + "day 3 of February ('Saturday'), 2001" ), new Date(2001, 2 - 1, 3), + "Parse date 'day' d 'of' MM (''DD''), yy" ); currentYear = new Date().getFullYear(); - TestHelpers.datepicker.equalsDate($.datepicker.parseDate("y-m-d", (currentYear - 2000) + "-02-03"), - 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"), - 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"), - 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}), - 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}), - 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"}), - 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"}), - new Date(currentYear - 39, 2 - 1, 3), "Parse date y-m-d - cutoff +60"); + TestHelpers.datepicker.equalsDate($.datepicker.parseDate( "y-m-d", (currentYear - 2000) + "-02-03" ), + 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" ), + 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" ), + 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}), + 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}), + 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"}), + 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"}), + new Date(currentYear - 39, 2 - 1, 3), "Parse date y-m-d - cutoff +60" ); gmtDate = new Date(2001, 2 - 1, 3); gmtDate.setMinutes(gmtDate.getMinutes() - gmtDate.getTimezoneOffset()); - TestHelpers.datepicker.equalsDate($.datepicker.parseDate("@", "981158400000"), gmtDate, "Parse date @"); - TestHelpers.datepicker.equalsDate($.datepicker.parseDate("!", "631167552000000000"), gmtDate, "Parse date !"); + TestHelpers.datepicker.equalsDate($.datepicker.parseDate( "@", "981158400000" ), gmtDate, "Parse date @" ); + TestHelpers.datepicker.equalsDate($.datepicker.parseDate( "!", "631167552000000000" ), gmtDate, "Parse date !" ); fr = $.datepicker.regional.fr; settings = {dayNamesShort: fr.dayNamesShort, dayNames: fr.dayNames, monthNamesShort: fr.monthNamesShort, monthNames: fr.monthNames}; - TestHelpers.datepicker.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"); - TestHelpers.datepicker.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"); - TestHelpers.datepicker.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"); - TestHelpers.datepicker.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"); + TestHelpers.datepicker.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" ); + TestHelpers.datepicker.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" ); + TestHelpers.datepicker.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" ); + TestHelpers.datepicker.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" ); zh = $.datepicker.regional["zh-CN"]; - TestHelpers.datepicker.equalsDate($.datepicker.parseDate("yy M d", "2011 十一月 22", zh), - new Date(2011, 11 - 1, 22), "Parse date yy M d with zh-CN"); + TestHelpers.datepicker.equalsDate($.datepicker.parseDate( "yy M d", "2011 十一月 22", zh), + new Date(2011, 11 - 1, 22), "Parse date yy M d with zh-CN" ); }); test("parseDateErrors", function() { @@ -1158,80 +1158,80 @@ test("parseDateErrors", function() { fr = $.datepicker.regional.fr; settings = {dayNamesShort: fr.dayNamesShort, dayNames: fr.dayNames, monthNamesShort: fr.monthNamesShort, monthNames: fr.monthNames}; - expectError(function() { $.datepicker.parseDate("D d M y", "Mon 9 Avr 01", settings); }, - "Mon 9 Avr 01 - D d M y", "Unknown name at position 0"); - expectError(function() { $.datepicker.parseDate("D d M y", "Lun. 9 Apr 01", settings); }, - "Lun. 9 Apr 01 - D d M y", "Unknown name at position 7"); + expectError(function() { $.datepicker.parseDate( "D d M y", "Mon 9 Avr 01", settings); }, + "Mon 9 Avr 01 - D d M y", "Unknown name at position 0" ); + expectError(function() { $.datepicker.parseDate( "D d M y", "Lun. 9 Apr 01", settings); }, + "Lun. 9 Apr 01 - D d M y", "Unknown name at position 7" ); }); -test("Ticket #7244: date parser does not fail when too many numbers are passed into the date function", function() { +test( "Ticket #7244: date parser does not fail when too many numbers are passed into the date function", function() { expect( 4 ); var date; try{ - date = $.datepicker.parseDate("dd/mm/yy", "18/04/19881"); - ok(false, "Did not properly detect an invalid date"); + date = $.datepicker.parseDate( "dd/mm/yy", "18/04/19881" ); + ok(false, "Did not properly detect an invalid date" ); }catch(e){ - ok("invalid date detected"); + ok( "invalid date detected" ); } try { - date = $.datepicker.parseDate("dd/mm/yy", "18/04/1988 @ 2:43 pm"); + date = $.datepicker.parseDate( "dd/mm/yy", "18/04/1988 @ 2:43 pm" ); equal(date.getDate(), 18); equal(date.getMonth(), 3); equal(date.getFullYear(), 1988); } catch(e) { - ok(false, "Did not properly parse date with extra text separated by whitespace"); + ok(false, "Did not properly parse date with extra text separated by whitespace" ); } }); -test("formatDate", function() { +test( "formatDate", function() { expect( 16 ); - TestHelpers.datepicker.init("#inp"); + TestHelpers.datepicker.init( "#inp" ); var gmtDate, fr, settings; - equal($.datepicker.formatDate("d m y", new Date(2001, 2 - 1, 3)), - "3 2 01", "Format date d m y"); - equal($.datepicker.formatDate("dd mm yy", new Date(2001, 2 - 1, 3)), - "03 02 2001", "Format date dd mm yy"); - equal($.datepicker.formatDate("d m y", new Date(2001, 12 - 1, 13)), - "13 12 01", "Format date d m y"); - equal($.datepicker.formatDate("dd mm yy", new Date(2001, 12 - 1, 13)), - "13 12 2001", "Format date dd mm yy"); - equal($.datepicker.formatDate("yy-o", new Date(2001, 2 - 1, 3)), - "2001-34", "Format date yy-o"); - equal($.datepicker.formatDate("yy-oo", new Date(2001, 2 - 1, 3)), - "2001-034", "Format date yy-oo"); - equal($.datepicker.formatDate("D M y", new Date(2001, 2 - 1, 3)), - "Sat Feb 01", "Format date D M y"); - equal($.datepicker.formatDate("DD MM yy", new Date(2001, 2 - 1, 3)), - "Saturday February 2001", "Format date DD MM yy"); - equal($.datepicker.formatDate("DD, MM d, yy", new Date(2001, 2 - 1, 3)), - "Saturday, February 3, 2001", "Format date DD, MM d, yy"); - equal($.datepicker.formatDate("'day' d 'of' MM (''DD''), yy", + equal($.datepicker.formatDate( "d m y", new Date(2001, 2 - 1, 3)), + "3 2 01", "Format date d m y" ); + equal($.datepicker.formatDate( "dd mm yy", new Date(2001, 2 - 1, 3)), + "03 02 2001", "Format date dd mm yy" ); + equal($.datepicker.formatDate( "d m y", new Date(2001, 12 - 1, 13)), + "13 12 01", "Format date d m y" ); + equal($.datepicker.formatDate( "dd mm yy", new Date(2001, 12 - 1, 13)), + "13 12 2001", "Format date dd mm yy" ); + equal($.datepicker.formatDate( "yy-o", new Date(2001, 2 - 1, 3)), + "2001-34", "Format date yy-o" ); + equal($.datepicker.formatDate( "yy-oo", new Date(2001, 2 - 1, 3)), + "2001-034", "Format date yy-oo" ); + equal($.datepicker.formatDate( "D M y", new Date(2001, 2 - 1, 3)), + "Sat Feb 01", "Format date D M y" ); + equal($.datepicker.formatDate( "DD MM yy", new Date(2001, 2 - 1, 3)), + "Saturday February 2001", "Format date DD MM yy" ); + equal($.datepicker.formatDate( "DD, MM d, yy", new Date(2001, 2 - 1, 3)), + "Saturday, February 3, 2001", "Format date DD, MM d, yy" ); + equal($.datepicker.formatDate( "'day' d 'of' MM (''DD''), yy", new Date(2001, 2 - 1, 3)), "day 3 of February ('Saturday'), 2001", - "Format date 'day' d 'of' MM ('DD'), yy"); + "Format date 'day' d 'of' MM ('DD'), yy" ); gmtDate = new Date(2001, 2 - 1, 3); - gmtDate.setMinutes(gmtDate.getMinutes() - gmtDate.getTimezoneOffset()); - equal($.datepicker.formatDate("@", gmtDate), "981158400000", "Format date @"); - equal($.datepicker.formatDate("!", gmtDate), "631167552000000000", "Format date !"); + gmtDate.setMinutes( gmtDate.getMinutes() - gmtDate.getTimezoneOffset() ); + equal($.datepicker.formatDate( "@", gmtDate), "981158400000", "Format date @" ); + equal($.datepicker.formatDate( "!", gmtDate), "631167552000000000", "Format date !" ); fr = $.datepicker.regional.fr; settings = {dayNamesShort: fr.dayNamesShort, dayNames: fr.dayNames, monthNamesShort: fr.monthNamesShort, monthNames: fr.monthNames}; - equal($.datepicker.formatDate("D M y", new Date(2001, 4 - 1, 9), settings), - "lun. avr. 01", "Format date D M y with settings"); - equal($.datepicker.formatDate("DD MM yy", new Date(2001, 4 - 1, 9), settings), - "lundi avril 2001", "Format date DD MM yy with settings"); - equal($.datepicker.formatDate("DD, MM d, yy", new Date(2001, 4 - 1, 9), settings), - "lundi, avril 9, 2001", "Format date DD, MM d, yy with settings"); - equal($.datepicker.formatDate("'jour' d 'de' MM (''DD''), yy", + equal($.datepicker.formatDate( "D M y", new Date(2001, 4 - 1, 9), settings), + "lun. avr. 01", "Format date D M y with settings" ); + equal($.datepicker.formatDate( "DD MM yy", new Date(2001, 4 - 1, 9), settings), + "lundi avril 2001", "Format date DD MM yy with settings" ); + equal($.datepicker.formatDate( "DD, MM d, yy", new Date(2001, 4 - 1, 9), settings), + "lundi, avril 9, 2001", "Format date DD, MM d, yy with settings" ); + equal($.datepicker.formatDate( "'jour' d 'de' MM (''DD''), yy", new Date(2001, 4 - 1, 9), settings), "jour 9 de avril ('lundi'), 2001", - "Format date 'jour' d 'de' MM (''DD''), yy with settings"); + "Format date 'jour' d 'de' MM (''DD''), yy with settings" ); }); // TODO: Fix this test so it isn't mysteriously flaky in Browserstack on certain OS/Browser combos -// test("Ticket 6827: formatDate day of year calculation is wrong during day lights savings time", function(){ +// test( "Ticket 6827: formatDate day of year calculation is wrong during day lights savings time", function(){ // expect( 1 ); -// var time = $.datepicker.formatDate("oo", new Date("2010/03/30 12:00:00 CDT")); -// equal(time, "089"); +// var time = $.datepicker.formatDate( "oo", new Date( "2010/03/30 12:00:00 CDT" )); +// equal(time, "089" ); // }); test( "Ticket 7602: Stop datepicker from appearing with beforeShow event handler", function() { @@ -1266,7 +1266,7 @@ test( "Ticket 7602: Stop datepicker from appearing with beforeShow event handler }); dp = $( "#ui-datepicker-div" ); inp.datepicker( "show" ); - equal( dp.css( "display" ), "none","beforeShow returns false" ); + equal( dp.css( "display" ), "none", "beforeShow returns false" ); inp.datepicker( "destroy" ); }); */ diff --git a/tests/unit/datepicker/datepicker_test_helpers.js b/tests/unit/datepicker/datepicker_test_helpers.js index e99014fc0..0023422e2 100644 --- a/tests/unit/datepicker/datepicker_test_helpers.js +++ b/tests/unit/datepicker/datepicker_test_helpers.js @@ -1,18 +1,18 @@ TestHelpers.datepicker = { - addMonths: function(date, offset) { - var maxDay = 32 - new Date(date.getFullYear(), date.getMonth() + offset, 32).getDate(); - date.setDate(Math.min(date.getDate(), maxDay)); - date.setMonth(date.getMonth() + offset); + addMonths: function( date, offset ) { + var maxDay = 32 - new Date( date.getFullYear(), date.getMonth() + offset, 32 ).getDate(); + date.setDate( Math.min( date.getDate(), maxDay ) ); + date.setMonth( date.getMonth() + offset ); return date; }, - equalsDate: function(d1, d2, message) { - if (!d1 || !d2) { - ok(false, message + " - missing date"); + equalsDate: function( d1, d2, message ) { + if ( !d1 || !d2 ) { + ok( false, message + " - missing date" ); return; } - d1 = new Date(d1.getFullYear(), d1.getMonth(), d1.getDate()); - d2 = new Date(d2.getFullYear(), d2.getMonth(), d2.getDate()); - equal(d1.toString(), d2.toString(), message); + d1 = new Date( d1.getFullYear(), d1.getMonth(), d1.getDate() ); + d2 = new Date( d2.getFullYear(), d2.getMonth(), d2.getDate() ); + equal( d1.toString(), d2.toString(), message ); }, init: function( id, options ) { options = $.extend( { show: false }, options || {} ); diff --git a/ui/datepicker.js b/ui/datepicker.js index 5a3d9a191..929138c79 100644 --- a/ui/datepicker.js +++ b/ui/datepicker.js @@ -57,6 +57,7 @@ $.widget( "ui.datepicker", { open: null, select: null }, + _create: function() { this.options.dateFormat = this.options.dateFormat || { date: "short" }; this.date = $.date( null, this.options.dateFormat ); @@ -172,6 +173,7 @@ $.widget( "ui.datepicker", { newCell.children( "a" ).addClass( "ui-state-focus" ); } }, + _createPicker: function() { this.picker = $( "
" ) .addClass( "ui-front" ) @@ -205,10 +207,10 @@ $.widget( "ui.datepicker", { case $.ui.keyCode.DOWN: case $.ui.keyCode.UP: clearTimeout( this.closeTimer ); - this._delay(function() { + this._delay( function() { this.open( event ); this.grid.focus(); - }, 1); + }, 1 ); break; case $.ui.keyCode.HOME: if ( event.ctrlKey ) { @@ -257,7 +259,7 @@ $.widget( "ui.datepicker", { } this._delay( function() { suppressExpandOnFocus = false; - }, 100); + }, 100 ); }, blur: function() { suppressExpandOnFocus = false; @@ -271,7 +273,7 @@ $.widget( "ui.datepicker", { // also allows tabbing inside the calendar without it closing this.closeTimer = this._delay( function() { this.close( event ); - }, 150); + }, 150 ); }, focusin: function() { clearTimeout( this.closeTimer ); @@ -296,6 +298,7 @@ $.widget( "ui.datepicker", { } }); }, + _appendTo: function() { var element = this.options.appendTo; @@ -310,7 +313,7 @@ $.widget( "ui.datepicker", { } if ( !element.length ) { - element = this.document[0].body; + element = this.document[ 0 ].body; } return element; @@ -363,10 +366,10 @@ $.widget( "ui.datepicker", { html += "
" + "
"; - if ( months[i].first ) { + if ( months[ i ].first ) { html += this._buildPreviousLink(); } - if ( months[i].last ) { + if ( months[ i ].last ) { html += this._buildNextLink(); } @@ -380,8 +383,10 @@ $.widget( "ui.datepicker", { html += this._buildButtons(); this.date = currentDate; + return html; }, + _buildHeader: function() { return "
" + this._buildPreviousLink() + @@ -389,8 +394,10 @@ $.widget( "ui.datepicker", { this._buildTitlebar() + "
"; }, + _buildPreviousLink: function() { var labels = Globalize.translate( "datepicker" ); + return ""; }, + _buildNextLink: function() { var labels = Globalize.translate( "datepicker" ); + return ""; }, + _buildTitlebar: function() { var labels = Globalize.translate( "datepicker" ); + return "
" + "
" + this._buildTitle() + @@ -416,6 +427,7 @@ $.widget( "ui.datepicker", { ", " + labels.datePickerRole + "" + "
"; }, + _buildTitle: function() { return "" + this.date.monthName() + @@ -424,6 +436,7 @@ $.widget( "ui.datepicker", { this.date.year() + ""; }, + _buildGrid: function() { return "" + @@ -431,6 +444,7 @@ $.widget( "ui.datepicker", { this._buildGridBody() + "
"; }, + _buildGridHeading: function() { var cells = "", i = 0, @@ -442,10 +456,12 @@ $.widget( "ui.datepicker", { for ( i; i < this.date.weekdays().length; i++ ) { cells += this._buildGridHeaderCell( this.date.weekdays()[i] ); } + return "" + "" + cells + "" + ""; }, + _buildGridHeaderCell: function( day ) { return "" + "" + @@ -453,16 +469,20 @@ $.widget( "ui.datepicker", { "" + ""; }, + _buildGridBody: function() { // this.date.days() is not cached, and it has O(n^2) complexity. It is run O(n) times. So, it equals O(n^3). Not good at all. Caching. var days = this.date.days(), i = 0, rows = ""; + for ( i; i < days.length; i++ ) { - rows += this._buildWeekRow( days[i] ); + rows += this._buildWeekRow( days[ i ] ); } + return "" + rows + ""; }, + _buildWeekRow: function( week ) { var cells = "", i = 0; @@ -475,6 +495,7 @@ $.widget( "ui.datepicker", { } return "" + cells + ""; }, + _buildDayCell: function( day ) { var contents = "", idAttribute = day.render ? ( "id=" + this.id + "-" + day.date ) : "", @@ -493,6 +514,7 @@ $.widget( "ui.datepicker", { contents + ""; }, + _buildDayLink: function( day ) { var link, classes = [ "ui-state-default" ], @@ -516,10 +538,13 @@ $.widget( "ui.datepicker", { if ( day.today ) { link += ", " + labels.currentText + ""; } + return link; }, + _buildDayDisplay: function( day ) { var classes = []; + if ( day.current ) { classes.push( "ui-state-active" ); } @@ -530,20 +555,23 @@ $.widget( "ui.datepicker", { classes.push( day.extraClasses.split( " " ) ); } - return "" + - day.date + ""; + return "" + day.date + ""; }, + _buildButtons: function() { var labels = Globalize.translate( "datepicker" ); + return "
" + "" + "" + "
"; }, + _focusTrigger: function() { suppressExpandOnFocus = true; this.element.focus(); }, + // Refreshing the entire datepicker during interaction confuses screen readers, specifically // because the grid heading is marked up as a live region and will often not update if it's // destroyed and recreated instead of just having its text change. Additionally, interacting @@ -560,6 +588,7 @@ $.widget( "ui.datepicker", { this._refreshMultiplePicker(); } }, + _refreshMultiplePicker: function() { for ( var i = 0; i < this.options.numberOfMonths; i++ ) { $( ".ui-datepicker-title", this.picker ).eq( i ).html( this._buildTitle() ); @@ -573,6 +602,7 @@ $.widget( "ui.datepicker", { // to maintain the currently focused grid and base queries like this off of it. $( this.picker ).find( ".ui-state-focus" ).not( ":first" ).removeClass( "ui-state-focus" ); }, + open: function( event ) { if ( this.inline || this.isOpen ) { return; @@ -603,6 +633,7 @@ $.widget( "ui.datepicker", { this._trigger( "open", event ); }, + close: function( event ) { if ( this.inline ) { return; @@ -616,16 +647,19 @@ $.widget( "ui.datepicker", { this.isOpen = false; this._trigger( "close", event ); }, + _setHiddenPicker: function() { this.picker .attr( "aria-hidden", "true" ) .attr( "aria-expanded", "false" ); }, + _buildPosition: function() { return $.extend( {}, { of: this.element }, this.options.position ); }, + select: function( event, time ) { this.date.setTime( time ).select(); this.refresh(); @@ -639,6 +673,7 @@ $.widget( "ui.datepicker", { date: this.date.format() }); }, + _value: function( value ) { this.date.setTime( value ).select(); if ( !this.inline ) { @@ -646,6 +681,7 @@ $.widget( "ui.datepicker", { } this.refresh(); }, + value: function( value ) { if ( arguments.length ) { this._value( value ); @@ -653,6 +689,7 @@ $.widget( "ui.datepicker", { return this.isValid() ? this.date.format() : this.element.val(); } }, + valueAsDate: function( value ) { if ( arguments.length ) { this._value( value ); @@ -660,12 +697,15 @@ $.widget( "ui.datepicker", { return this.isValid() ? this.date.date() : null; } }, + isValid: function() { if ( this.inline ) { return true; } + return Globalize.parseDate( this.element.val(), this.options.dateFormat ) !== null; }, + _destroy: function() { if ( this.inline ) { this.picker.empty(); @@ -676,9 +716,11 @@ $.widget( "ui.datepicker", { .removeAttr( "aria-owns" ); } }, + widget: function() { return this.picker; }, + _setOption: function( key, value ) { this._super( key, value );