dp1.datepicker();\r
ok(dp1.is('.hasDatepicker'), 'Marker class set');\r
ok($($.datepicker._datepickerDiv).html() == '', 'Content empty');\r
- dp1.focus();\r
+ dp1.datepicker('show');\r
ok($($.datepicker._datepickerDiv).html() != '', 'Content present');\r
- dp1.blur();\r
+ dp1.datepicker('hide');\r
equals($.datepicker._defaults.showOn, 'focus', 'Initial showOn');\r
$.datepicker.setDefaults({showOn: 'button'});\r
equals($.datepicker._defaults.showOn, 'button', 'Change default showOn');\r
equalsDate(dp1.datepicker('getDate'), new Date(2009, 2 - 1, 28), 'Keystroke ctrl+pgdn - Feb');\r
});\r
\r
+test('defaultDate', function() {\r
+ var dp1 = $('#dp1');\r
+ var date = new Date();\r
+ dp1.datepicker({speed: ''}).val('').datepicker('show');\r
+ dp1.simulate('keydown', {keyCode: $.simulate.VK_ENTER});\r
+ equalsDate(dp1.datepicker('getDate'), date, 'Default date null');\r
+ dp1.datepicker('change', {defaultDate: '-1d'}).\r
+ datepicker('hide').val('').datepicker('show');\r
+ dp1.simulate('keydown', {keyCode: $.simulate.VK_ENTER});\r
+ date.setDate(date.getDate() - 1);\r
+ equalsDate(dp1.datepicker('getDate'), date, 'Default date -1d');\r
+ dp1.datepicker('change', {defaultDate: '+3D'}).\r
+ datepicker('hide').val('').datepicker('show');\r
+ dp1.simulate('keydown', {keyCode: $.simulate.VK_ENTER});\r
+ date.setDate(date.getDate() + 4);\r
+ equalsDate(dp1.datepicker('getDate'), date, 'Default date +3D');\r
+ dp1.datepicker('change', {defaultDate: ' -2 w '}).\r
+ datepicker('hide').val('').datepicker('show');\r
+ dp1.simulate('keydown', {keyCode: $.simulate.VK_ENTER});\r
+ date = new Date();\r
+ date.setDate(date.getDate() - 14);\r
+ equalsDate(dp1.datepicker('getDate'), date, 'Default date -2 w');\r
+ dp1.datepicker('change', {defaultDate: '+1 W'}).\r
+ datepicker('hide').val('').datepicker('show');\r
+ dp1.simulate('keydown', {keyCode: $.simulate.VK_ENTER});\r
+ date.setDate(date.getDate() + 21);\r
+ equalsDate(dp1.datepicker('getDate'), date, 'Default date +1 W');\r
+ dp1.datepicker('change', {defaultDate: ' -1 m '}).\r
+ datepicker('hide').val('').datepicker('show');\r
+ dp1.simulate('keydown', {keyCode: $.simulate.VK_ENTER});\r
+ date = new Date();\r
+ date.setMonth(date.getMonth() - 1);\r
+ equalsDate(dp1.datepicker('getDate'), date, 'Default date -1 m');\r
+ dp1.datepicker('change', {defaultDate: '+2M'}).\r
+ datepicker('hide').val('').datepicker('show');\r
+ dp1.simulate('keydown', {keyCode: $.simulate.VK_ENTER});\r
+ date.setMonth(date.getMonth() + 3);\r
+ equalsDate(dp1.datepicker('getDate'), date, 'Default date +2M');\r
+ dp1.datepicker('change', {defaultDate: '-2y'}).\r
+ datepicker('hide').val('').datepicker('show');\r
+ dp1.simulate('keydown', {keyCode: $.simulate.VK_ENTER});\r
+ date = new Date();\r
+ date.setFullYear(date.getFullYear() - 2);\r
+ equalsDate(dp1.datepicker('getDate'), date, 'Default date -2y');\r
+ dp1.datepicker('change', {defaultDate: '+1 Y '}).\r
+ datepicker('hide').val('').datepicker('show');\r
+ dp1.simulate('keydown', {keyCode: $.simulate.VK_ENTER});\r
+ date.setFullYear(date.getFullYear() + 3);\r
+ equalsDate(dp1.datepicker('getDate'), date, 'Default date +1 Y');\r
+ dp1.datepicker('change', {defaultDate: '+10d +1M'}).\r
+ datepicker('hide').val('').datepicker('show');\r
+ dp1.simulate('keydown', {keyCode: $.simulate.VK_ENTER});\r
+ date = new Date();\r
+ date.setDate(date.getDate() + 10);\r
+ date.setMonth(date.getMonth() + 1);\r
+ equalsDate(dp1.datepicker('getDate'), date, 'Default date +10d +1M');\r
+ date = new Date(2007, 1 - 1, 26);\r
+ dp1.datepicker('change', {defaultDate: date}).\r
+ datepicker('hide').val('').datepicker('show');\r
+ dp1.simulate('keydown', {keyCode: $.simulate.VK_ENTER});\r
+ equalsDate(dp1.datepicker('getDate'), date, 'Default date 01/26/2007');\r
+});\r
+\r
test('minMax', function() {\r
var dp1 = $('#dp1');\r
var lastYear = new Date(2007, 6 - 1, 4);\r
dp1.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGDN}).\r
simulate('keydown', {keyCode: $.simulate.VK_ENTER});\r
equalsDate(dp1.datepicker('getDate'), maxDate, 'Min/max - null, 12/07/2008 - ctrl+pgdn');\r
+ // relative dates\r
+ var date = new Date();\r
+ date.setDate(date.getDate() - 7);\r
+ dp1.datepicker('change', {minDate: '-1w', maxDate: '+10 D +1 M'}).\r
+ datepicker('hide').val('').datepicker('show');\r
+ dp1.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGUP}).\r
+ simulate('keydown', {keyCode: $.simulate.VK_ENTER});\r
+ equalsDate(dp1.datepicker('getDate'), date, 'Min/max - -1w, +10 D +1 M - ctrl+pgup');\r
+ date.setDate(date.getDate() + 17);\r
+ date.setMonth(date.getMonth() + 1);\r
+ dp1.val('').datepicker('show');\r
+ dp1.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGDN}).\r
+ simulate('keydown', {keyCode: $.simulate.VK_ENTER});\r
+ equalsDate(dp1.datepicker('getDate'), date, 'Min/max - -1w, +10 D +1 M - ctrl+pgdn');\r
});\r
\r
test('ranges', function() {\r