--- /dev/null
+module('datepicker');\r
+\r
+function equalsDate(d1, d2, message) {\r
+ if (!d1 || !d2) {\r
+ ok(false, message + ' - missing date');\r
+ return;\r
+ }\r
+ d1 = new Date(d1.getFullYear(), d1.getMonth(), d1.getDate());\r
+ d2 = new Date(d2.getFullYear(), d2.getMonth(), d2.getDate());\r
+ equals(d1.toString(), d2.toString(), message);\r
+}\r
+\r
+test('defaults', function() {\r
+ var dp1 = $('#dp1');\r
+ dp1.datepicker();\r
+ ok(dp1.is('.hasDatepicker'), 'Marker class set');\r
+ ok($($.datepicker._datepickerDiv).html() == '', 'Content empty');\r
+ dp1.focus();\r
+ ok($($.datepicker._datepickerDiv).html() != '', 'Content present');\r
+ dp1.blur();\r
+ equals($.datepicker._defaults.showOn, 'focus', 'Initial showOn');\r
+ $.datepicker.setDefaults({showOn: 'button'});\r
+ equals($.datepicker._defaults.showOn, 'button', 'Change default showOn');\r
+ $.datepicker.setDefaults({showOn: 'focus'});\r
+ equals($.datepicker._defaults.showOn, 'focus', 'Restore showOn');\r
+});\r
+\r
+test('remove', function() {\r
+ var rem = $('#rem');\r
+ rem.datepicker();\r
+ ok(rem.is('.hasDatepicker'), 'Marker class set');\r
+ ok(rem[0]._calId != null, 'Datepicker ID present');\r
+ rem.datepicker('destroy');\r
+ ok(!rem.is('.hasDatepicker'), 'Marker class cleared');\r
+ ok(rem[0]._calId == null, 'Datepicker ID absent');\r
+});\r
+\r
+test('change', function() {\r
+ var dp1 = $('#dp1');\r
+ dp1.datepicker();\r
+ var inst = $.datepicker._inst[dp1[0]._calId];\r
+ equals(inst._settings.showOn, null, 'Initial setting showOn');\r
+ equals(inst._get('showOn'), 'focus', 'Initial instance showOn');\r
+ equals($.datepicker._defaults.showOn, 'focus', 'Initial default showOn');\r
+ dp1.datepicker('change', 'showOn', 'button');\r
+ equals(inst._settings.showOn, 'button', 'Change setting showOn');\r
+ equals(inst._get('showOn'), 'button', 'Change instance showOn');\r
+ equals($.datepicker._defaults.showOn, 'focus', 'Retain default showOn');\r
+ dp1.datepicker('change', {showOn: 'both'});\r
+ equals(inst._settings.showOn, 'both', 'Change setting showOn');\r
+ equals(inst._get('showOn'), 'both', 'Change instance showOn');\r
+ equals($.datepicker._defaults.showOn, 'focus', 'Retain default showOn');\r
+ dp1.datepicker('change', 'showOn', undefined);\r
+ equals(inst._settings.showOn, null, 'Clear setting showOn');\r
+ equals(inst._get('showOn'), 'focus', 'Restore instance showOn');\r
+ equals($.datepicker._defaults.showOn, 'focus', 'Retain default showOn');\r
+});\r
+\r
+test('enableDisable', function() {\r
+ var dp1 = $('#dp1');\r
+ dp1.datepicker();\r
+ ok(!dp1.datepicker('isDisabled'), 'Initially enabled');\r
+ dp1.datepicker('disable');\r
+ ok(dp1.datepicker('isDisabled'), 'Now disabled');\r
+ dp1.datepicker('enable');\r
+ ok(!dp1.datepicker('isDisabled'), 'Now enabled');\r
+});\r
+/*\r
+test('keystrokes', function() {\r
+ var dp1 = $('#dp1');\r
+ dp1.datepicker().val('').focus();\r
+ dp1.simulate('keydown', {keyCode: 13});\r
+ equalsDate(dp1.datepicker('getDate'), new Date(), 'Select today');\r
+ dp1.blur();\r
+});\r
+*/\r
+test('noWeekends', function() {\r
+ for (var i = 1; i <= 31; i++) {\r
+ var date = new Date(2001, 1 - 1, i);\r
+ isObj($.datepicker.noWeekends(date), [(i + 1) % 7 >= 2, ''],\r
+ 'No weekends ' + date);\r
+ }\r
+});\r
+\r
+test('iso8601Week', function() {\r
+ var date = new Date(2000, 12 - 1, 31);\r
+ equals($.datepicker.iso8601Week(date), 52, 'ISO 8601 week ' + date);\r
+ date = new Date(2001, 1 - 1, 1);\r
+ equals($.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date);\r
+ date = new Date(2001, 1 - 1, 7);\r
+ equals($.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date);\r
+ date = new Date(2001, 1 - 1, 8);\r
+ equals($.datepicker.iso8601Week(date), 2, 'ISO 8601 week ' + date);\r
+ date = new Date(2003, 12 - 1, 28);\r
+ equals($.datepicker.iso8601Week(date), 52, 'ISO 8601 week ' + date);\r
+ date = new Date(2003, 12 - 1, 29);\r
+ equals($.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date);\r
+ date = new Date(2004, 1 - 1, 4);\r
+ equals($.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date);\r
+ date = new Date(2004, 1 - 1, 5);\r
+ equals($.datepicker.iso8601Week(date), 2, 'ISO 8601 week ' + date);\r
+ date = new Date(2009, 12 - 1, 28);\r
+ equals($.datepicker.iso8601Week(date), 53, 'ISO 8601 week ' + date);\r
+ date = new Date(2010, 1 - 1, 3);\r
+ equals($.datepicker.iso8601Week(date), 53, 'ISO 8601 week ' + date);\r
+ date = new Date(2010, 1 - 1, 4);\r
+ equals($.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date);\r
+ date = new Date(2010, 1 - 1, 10);\r
+ equals($.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date);\r
+});\r
+\r
+test('parseDate', function() {\r
+ ok($.datepicker.parseDate('d m y', '') == null, 'Parse date empty');\r
+ equalsDate($.datepicker.parseDate('d m y', '3 2 01'),\r
+ new Date(2001, 2 - 1, 3), 'Parse date d m y');\r
+ equalsDate($.datepicker.parseDate('dd mm yy', '03 02 2001'),\r
+ new Date(2001, 2 - 1, 3), 'Parse date dd mm yy');\r
+ equalsDate($.datepicker.parseDate('d m y', '13 12 01'),\r
+ new Date(2001, 12 - 1, 13), 'Parse date d m y');\r
+ equalsDate($.datepicker.parseDate('dd mm yy', '13 12 2001'),\r
+ new Date(2001, 12 - 1, 13), 'Parse date dd mm yy');\r
+ equalsDate($.datepicker.parseDate('D d M y', 'Sat 3 Feb 01'),\r
+ new Date(2001, 2 - 1, 3), 'Parse date D d M y');\r
+ equalsDate($.datepicker.parseDate('d MM DD yy', '3 February Saturday 2001'),\r
+ new Date(2001, 2 - 1, 3), 'Parse date dd MM DD yy');\r
+ equalsDate($.datepicker.parseDate('DD, MM d, yy', 'Saturday, February 3, 2001'),\r
+ new Date(2001, 2 - 1, 3), 'Parse date DD, MM d, yy');\r
+ equalsDate($.datepicker.parseDate('\'day\' d of MM (\'\'DD\'\'), yy', 'day 3 of February (\'Saturday\'), 2001'),\r
+ new Date(2001, 2 - 1, 3), 'Parse date \'day\' d of MM (\'\'DD\'\'), yy');\r
+ var daysShort = ['D1', 'D2', 'D3', 'D4', 'D5', 'D6', 'D7'];\r
+ var daysLong = ['Day1', 'Day2', 'Day3', 'Day4', 'Day5', 'Day6', 'Day7'];\r
+ var monthsShort = ['M1', 'M2', 'M3', 'M4', 'M5', 'M6',\r
+ 'M7', 'M8', 'M9', 'M10', 'M11', 'M12'];\r
+ var monthsLong = ['Mon1', 'Mon2', 'Mon3', 'Mon4', 'Mon5', 'Mon6', \r
+ 'Mon7', 'Mon8', 'Mon9', 'Mon10', 'Mon11', 'Mon12'];\r
+ var settings = {dayNamesShort: daysShort, dayNames: daysLong,\r
+ monthNamesShort: monthsShort, monthNames: monthsLong};\r
+ equalsDate($.datepicker.parseDate('D d M y', 'D7 3 M2 01', settings),\r
+ new Date(2001, 2 - 1, 3), 'Parse date D M y with settings');\r
+ equalsDate($.datepicker.parseDate('d MM DD yy', '3 Mon2 Day7 2001', settings),\r
+ new Date(2001, 2 - 1, 3), 'Parse date d MM DD yy with settings');\r
+ equalsDate($.datepicker.parseDate('DD, MM d, yy', 'Day7, Mon2 3, 2001', settings),\r
+ new Date(2001, 2 - 1, 3), 'Parse date DD, MM d, yy with settings');\r
+ equalsDate($.datepicker.parseDate('\'day\' d of MM (\'\'DD\'\'), yy', 'day 3 of Mon2 (\'Day7\'), 2001', settings),\r
+ new Date(2001, 2 - 1, 3), 'Parse date \'day\' d of MM (\'\'DD\'\'), yy with settings');\r
+});\r
+\r
+test('parseDateErrors', function() {\r
+ var expectError = function(expr, value, error) {\r
+ try {\r
+ expr();\r
+ ok(false, 'Parsed error ' + value);\r
+ }\r
+ catch (e) {\r
+ equals(e, error, 'Parsed error ' + value);\r
+ }\r
+ };\r
+ expectError(function() { $.datepicker.parseDate(null, 'Sat 2 01'); },\r
+ 'Sat 2 01', 'Invalid arguments');\r
+ expectError(function() { $.datepicker.parseDate('d m y', null); },\r
+ 'null', 'Invalid arguments');\r
+ expectError(function() { $.datepicker.parseDate('d m y', 'Sat 2 01'); },\r
+ 'Sat 2 01', 'Missing number at position 0');\r
+ expectError(function() { $.datepicker.parseDate('d m y', '3 Feb 01'); },\r
+ '3 Feb 01', 'Missing number at position 2');\r
+ expectError(function() { $.datepicker.parseDate('d m y', '3 2 AD01'); },\r
+ '3 2 AD01', 'Missing number at position 4');\r
+ expectError(function() { $.datepicker.parseDate('D d M y', 'D7 3 Feb 01'); },\r
+ 'D7 3 Feb 01', 'Unknown name at position 0');\r
+ expectError(function() { $.datepicker.parseDate('D d M y', 'Sat 3 M2 01'); },\r
+ 'Sat 3 M2 01', 'Unknown name at position 6');\r
+ expectError(function() { $.datepicker.parseDate('DD, MM d, yy', 'Saturday- Feb 3, 2001'); },\r
+ 'Sat- Feb 3, 2001', 'Unexpected literal at position 8');\r
+ expectError(function() { $.datepicker.parseDate('\'day\' d of MM (\'\'DD\'\'), yy', 'day 3 of February ("Saturday"), 2001'); },\r
+ 'day 3 of Mon2 ("Day7"), 2001', 'Unexpected literal at position 19');\r
+ expectError(function() { $.datepicker.parseDate('d m y', '29 2 01'); },\r
+ '29 2 01', 'Invalid date');\r
+ var daysShort = ['D1', 'D2', 'D3', 'D4', 'D5', 'D6', 'D7'];\r
+ var daysLong = ['Day1', 'Day2', 'Day3', 'Day4', 'Day5', 'Day6', 'Day7'];\r
+ var monthsShort = ['M1', 'M2', 'M3', 'M4', 'M5', 'M6',\r
+ 'M7', 'M8', 'M9', 'M10', 'M11', 'M12'];\r
+ var monthsLong = ['Mon1', 'Mon2', 'Mon3', 'Mon4', 'Mon5', 'Mon6', \r
+ 'Mon7', 'Mon8', 'Mon9', 'Mon10', 'Mon11', 'Mon12'];\r
+ var settings = {dayNamesShort: daysShort, dayNames: daysLong,\r
+ monthNamesShort: monthsShort, monthNames: monthsLong};\r
+ expectError(function() { $.datepicker.parseDate('D d M y', 'Sat 3 M2 01', settings); },\r
+ 'Sat 3 M2 01', 'Unknown name at position 0');\r
+ expectError(function() { $.datepicker.parseDate('D d M y', 'D7 3 Feb 01', settings); },\r
+ 'D7 3 Feb 01', 'Unknown name at position 5');\r
+});\r
+\r
+test('formatDate', function() {\r
+ equals($.datepicker.formatDate('d m y', new Date(2001, 2 - 1, 3)),\r
+ '3 2 01', 'Format date d m y');\r
+ equals($.datepicker.formatDate('dd mm yy', new Date(2001, 2 - 1, 3)),\r
+ '03 02 2001', 'Format date dd mm yy');\r
+ equals($.datepicker.formatDate('d m y', new Date(2001, 12 - 1, 13)),\r
+ '13 12 01', 'Format date d m y');\r
+ equals($.datepicker.formatDate('dd mm yy', new Date(2001, 12 - 1, 13)),\r
+ '13 12 2001', 'Format date dd mm yy');\r
+ equals($.datepicker.formatDate('D M y', new Date(2001, 2 - 1, 3)),\r
+ 'Sat Feb 01', 'Format date D M y');\r
+ equals($.datepicker.formatDate('DD MM yy', new Date(2001, 2 - 1, 3)),\r
+ 'Saturday February 2001', 'Format date DD MM yy');\r
+ equals($.datepicker.formatDate('DD, MM d, yy', new Date(2001, 2 - 1, 3)),\r
+ 'Saturday, February 3, 2001', 'Format date DD, MM d, yy');\r
+ equals($.datepicker.formatDate('\'day\' d of MM (\'\'DD\'\'), yy', new Date(2001, 2 - 1, 3)),\r
+ 'day 3 of February (\'Saturday\'), 2001', 'Format date \'day\' d of MM (\'\'DD\'\'), yy');\r
+ var daysShort = ['D1', 'D2', 'D3', 'D4', 'D5', 'D6', 'D7'];\r
+ var daysLong = ['Day1', 'Day2', 'Day3', 'Day4', 'Day5', 'Day6', 'Day7'];\r
+ var monthsShort = ['M1', 'M2', 'M3', 'M4', 'M5', 'M6',\r
+ 'M7', 'M8', 'M9', 'M10', 'M11', 'M12'];\r
+ var monthsLong = ['Mon1', 'Mon2', 'Mon3', 'Mon4', 'Mon5', 'Mon6', \r
+ 'Mon7', 'Mon8', 'Mon9', 'Mon10', 'Mon11', 'Mon12'];\r
+ var settings = {dayNamesShort: daysShort, dayNames: daysLong,\r
+ monthNamesShort: monthsShort, monthNames: monthsLong};\r
+ equals($.datepicker.formatDate('D M y', new Date(2001, 2 - 1, 3), settings),\r
+ 'D7 M2 01', 'Format date D M y with settings');\r
+ equals($.datepicker.formatDate('DD MM yy', new Date(2001, 2 - 1, 3), settings),\r
+ 'Day7 Mon2 2001', 'Format date DD MM yy with settings');\r
+ equals($.datepicker.formatDate('DD, MM d, yy', new Date(2001, 2 - 1, 3), settings),\r
+ 'Day7, Mon2 3, 2001', 'Format date DD, MM d, yy with settings');\r
+ equals($.datepicker.formatDate('\'day\' d of MM (\'\'DD\'\'), yy', new Date(2001, 2 - 1, 3), settings),\r
+ 'day 3 of Mon2 (\'Day7\'), 2001', 'Format date \'day\' d of MM (\'\'DD\'\'), yy with settings');\r
+});\r