r2419 - Datepicker: Corrected unit tests for structural changes and end of month

r2419 - Datepicker: Corrected unit tests for structural changes and end of month


Author: kbwood.au
Date: Wed Apr 1 03:15:29 2009
New Revision: 2419
Modified:
trunk/tests/unit/datepicker/datepicker_core.js
trunk/tests/unit/datepicker/datepicker_options.js
Log:
Datepicker: Corrected unit tests for structural changes and end of month
Modified: trunk/tests/unit/datepicker/datepicker_core.js
==============================================================================
--- trunk/tests/unit/datepicker/datepicker_core.js    (original)
+++ trunk/tests/unit/datepicker/datepicker_core.js    Wed Apr 1 03:15:29 2009
@@ -24,11 +24,16 @@
    same(a1, a2, message);
}
+function addMonths(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;
+}
+
function init(id, options) {
    $.datepicker.setDefaults($.datepicker.regional['']);
-    var inp = $(id);
-    inp.datepicker($.extend({duration: ''}, options || {}));
-    return inp;
+    return $(id).datepicker($.extend({duration: ''}, options || {}));
}
var PROP_NAME = 'datepicker';
@@ -38,9 +43,9 @@
module("datepicker: core");
test('baseStructure', function() {
-    var dp = $('#ui-datepicker-div');
    var inp = init('#inp');
    inp.focus();
+    var dp = $('#ui-datepicker-div');
    var iframe = ($.browser.msie && parseInt($.browser.version) < 7);
    ok(dp.is(':visible'), 'Structure - datepicker visible');
    ok(!dp.is('.ui-datepicker-rtl'), 'Structure - not right-to-left');
@@ -94,26 +99,32 @@
    inp = init('#inp', {numberOfMonths: 2});
    inp.focus();
    ok(dp.is('.ui-datepicker-multi'), 'Structure multi [2] - multi-month');
-    equals(dp.children().length, 2 + (iframe ? 1 : 0), 'Structure multi [2] -
child count');
-    month = dp.children(':first');
-    ok(month.is('div.ui-datepicker-group') &&
month.is('div.ui-datepicker-group-first'), 'Structure multi [2] - first
month division');
-    month = dp.children(':eq(1)');
-    ok(month.is('div.ui-datepicker-group') &&
month.is('div.ui-datepicker-group-last'), 'Structure multi [2] - second
month division');
+    equals(dp.children().length, 3 + (iframe ? 1 : 0), 'Structure multi [2] -
child count');
+    var child = dp.children(':first');
+    ok(child.is('div.ui-datepicker-group') &&
child.is('div.ui-datepicker-group-first'), 'Structure multi [2] - first
month division');
+    child = dp.children(':eq(1)');
+    ok(child.is('div.ui-datepicker-group') &&
child.is('div.ui-datepicker-group-last'), 'Structure multi [2] - second
month division');
+    child = dp.children(':eq(2)');
+    ok(child.is('div.ui-datepicker-row-break'), 'Structure multi [2] - row
break');
    inp.datepicker('hide').datepicker('destroy');
    
    // Multi-month [2, 2]
    inp = init('#inp', {numberOfMonths: [2, 2]});
    inp.focus();
    ok(dp.is('.ui-datepicker-multi'), 'Structure multi - multi-month');
-    equals(dp.children().length, 4 + (iframe ? 1 : 0), 'Structure multi [2,2]
- child count');
-    month = dp.children(':first');
-    ok(month.is('div.ui-datepicker-group') &&
month.is('div.ui-datepicker-group-first'), 'Structure multi [2,2] - first
month division');
-    month = dp.children(':eq(1)');
-    ok(month.is('div.ui-datepicker-group') &&
month.is('div.ui-datepicker-group-last'), 'Structure multi [2,2] - second
month division');
-    month = dp.children(':eq(2)');
-    ok(month.is('div.ui-datepicker-group') &&
month.is('div.ui-datepicker-group-first'), 'Structure multi [2,2] - third
month division');
-    month = dp.children(':eq(3)');
-    ok(month.is('div.ui-datepicker-group') &&
month.is('div.ui-datepicker-group-last'), 'Structure multi [2,2] - fourth
month division');
+    equals(dp.children().length, 6 + (iframe ? 1 : 0), 'Structure multi [2,2]
- child count');
+    child = dp.children(':first');
+    ok(child.is('div.ui-datepicker-group') &&
child.is('div.ui-datepicker-group-first'), 'Structure multi [2,2] - first
month division');
+    child = dp.children(':eq(1)');
+    ok(child.is('div.ui-datepicker-group') &&
child.is('div.ui-datepicker-group-last'), 'Structure multi [2,2] - second
month division');
+    child = dp.children(':eq(2)');
+    ok(child.is('div.ui-datepicker-row-break'), 'Structure multi [2,2] - row
break');
+    child = dp.children(':eq(3)');
+    ok(child.is('div.ui-datepicker-group') &&
child.is('div.ui-datepicker-group-first'), 'Structure multi [2,2] - third
month division');
+    child = dp.children(':eq(4)');
+    ok(child.is('div.ui-datepicker-group') &&
child.is('div.ui-datepicker-group-last'), 'Structure multi [2,2] - fourth
month division');
+    child = dp.children(':eq(5)');
+    ok(child.is('div.ui-datepicker-row-break'), 'Structure multi [2,2] - row
break');
    inp.datepicker('hide').datepicker('destroy');
    
    // Inline
@@ -126,7 +137,7 @@
    var header = dp.children(':first');
    ok(header.is('div.ui-datepicker-header'), 'Structure inline - header
division');
    equals(header.children().length, 3, 'Structure inline - header child
count');
-    var table = month.children(':eq(1)');
+    var table = dp.children(':eq(1)');
    ok(table.is('table.ui-datepicker-calendar'), 'Structure inline - month
table');
    ok(table.children(':first').is('thead'), 'Structure inline - month table
thead');
    ok(table.children(':eq(1)').is('tbody'), 'Structure inline - month table
body');
@@ -136,11 +147,13 @@
    inl = init('#inl', {numberOfMonths: 2});
    dp = inl.children();
    ok(dp.is('.ui-datepicker-inline') &&
dp.is('.ui-datepicker-multi'), 'Structure inline multi - main div');    
-    equals(dp.children().length, 2 + (iframe ? 1 : 0), 'Structure multi -
child count');
-    month = dp.children(':first');
-    ok(month.is('div.ui-datepicker-group') &&
month.is('div.ui-datepicker-group-first'), 'Structure multi - first month
division');
-    month = dp.children(':eq(1)');
-    ok(month.is('div.ui-datepicker-group') &&
month.is('div.ui-datepicker-group-last'), 'Structure multi - second month
division');
+    equals(dp.children().length, 3 + (iframe ? 1 : 0), 'Structure inline
multi - child count');
+    child = dp.children(':first');
+    ok(child.is('div.ui-datepicker-group') &&
child.is('div.ui-datepicker-group-first'), 'Structure inline multi - first
month division');
+    child = dp.children(':eq(1)');
+    ok(child.is('div.ui-datepicker-group') &&
child.is('div.ui-datepicker-group-last'), 'Structure inline multi - second
month division');
+    child = dp.children(':eq(2)');
+    ok(child.is('div.ui-datepicker-row-break'), 'Structure inline multi - row
break');
    inl.datepicker('destroy');
});
Modified: trunk/tests/unit/datepicker/datepicker_options.js
==============================================================================
--- trunk/tests/unit/datepicker/datepicker_options.js    (original)
+++ trunk/tests/unit/datepicker/datepicker_options.js    Wed Apr 1 03:15:29
2009
@@ -187,13 +187,12 @@
    inp.datepicker('option', {defaultDate: ' -1 m '}).
        datepicker('hide').val('').datepicker('show').
        simulate('keydown', {keyCode: $.simulate.VK_ENTER});
-    date = new Date();
-    date.setMonth(date.getMonth() - 1);
+    date = addMonths(new Date(), -1);
    equalsDate(inp.datepicker('getDate'), date, 'Default date -1 m');
    inp.datepicker('option', {defaultDate: '+2M'}).
        datepicker('hide').val('').datepicker('show').
        simulate('keydown', {keyCode: $.simulate.VK_ENTER});
-    date.setMonth(date.getMonth() + 3);
+    date = addMonths(new Date(), 2);
    equalsDate(inp.datepicker('getDate'), date, 'Default date +2M');
    inp.datepicker('option', {defaultDate: '-2y'}).
        datepicker('hide').val('').datepicker('show').
@@ -209,8 +208,7 @@
    inp.datepicker('option', {defaultDate: '+1M +10d'}).
        datepicker('hide').val('').datepicker('show').
        simulate('keydown', {keyCode: $.simulate.VK_ENTER});
-    date = new Date();
-    date.setMonth(date.getMonth() + 1);
+    date = addMonths(new Date(), 1);
    date.setDate(date.getDate() + 10);
    equalsDate(inp.datepicker('getDate'), date, 'Default date +1M +10d');
    date = new Date(2007, 1 - 1, 26);
@@ -245,7 +243,8 @@
    equals(dp.find('.ui-datepicker-prev').text(), 'Prev', 'Navigation prev -
default');
    equals(dp.find('.ui-datepicker-current').text(), 'Today', 'Navigation
current - default');
    equals(dp.find('.ui-datepicker-next').text(), 'Next', 'Navigation next -
default');
-    inp.datepicker('hide').datepicker('option', {navigationAsDateFormat:
true, prevText: '< M', currentText: 'MM', nextText: 'M