aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMike Sherov <mike.sherov@gmail.com>2012-11-03 16:17:16 -0400
committerMike Sherov <mike.sherov@gmail.com>2012-11-03 16:17:16 -0400
commit3df9ea29e644a3dd6345161513dae5823d9b0460 (patch)
tree08bdc053f90d110cb4af39c4de464d92ad8142c6 /tests
parent68ad80c2922daccba773a9adafe9fb5efcb129a2 (diff)
downloadjquery-ui-3df9ea29e644a3dd6345161513dae5823d9b0460.tar.gz
jquery-ui-3df9ea29e644a3dd6345161513dae5823d9b0460.zip
Dev: remove globals from tests and moved test helpers to correct location - Fixed #8770 Dev: Remove globals and Standardize Test Suite
Diffstat (limited to 'tests')
-rw-r--r--tests/.jshintrc15
-rw-r--r--tests/unit/datepicker/datepicker.html1
-rw-r--r--tests/unit/datepicker/datepicker_core.js130
-rw-r--r--tests/unit/datepicker/datepicker_events.js10
-rw-r--r--tests/unit/datepicker/datepicker_methods.js38
-rw-r--r--tests/unit/datepicker/datepicker_options.js216
-rw-r--r--tests/unit/datepicker/datepicker_test_helpers.js22
-rw-r--r--tests/unit/datepicker/datepicker_tickets.js8
-rw-r--r--tests/unit/dialog/dialog.html1
-rw-r--r--tests/unit/dialog/dialog_core.js91
-rw-r--r--tests/unit/dialog/dialog_events.js238
-rw-r--r--tests/unit/dialog/dialog_methods.js28
-rw-r--r--tests/unit/dialog/dialog_options.js189
-rw-r--r--tests/unit/dialog/dialog_test_helpers.js45
-rw-r--r--tests/unit/dialog/dialog_tickets.js35
-rw-r--r--tests/unit/draggable/draggable.html1
-rw-r--r--tests/unit/draggable/draggable_core.js77
-rw-r--r--tests/unit/draggable/draggable_events.js44
-rw-r--r--tests/unit/draggable/draggable_methods.js14
-rw-r--r--tests/unit/draggable/draggable_options.js226
-rw-r--r--tests/unit/draggable/draggable_test_helpers.js57
-rw-r--r--tests/unit/droppable/droppable.html1
-rw-r--r--tests/unit/droppable/droppable_core.js11
-rw-r--r--tests/unit/droppable/droppable_methods.js14
-rw-r--r--tests/unit/droppable/droppable_options.js4
-rw-r--r--tests/unit/droppable/droppable_test_helpers.js10
-rw-r--r--tests/unit/resizable/resizable.html1
-rw-r--r--tests/unit/resizable/resizable_core.js16
-rw-r--r--tests/unit/resizable/resizable_test_helpers.js15
-rw-r--r--tests/unit/selectable/selectable.html1
-rw-r--r--tests/unit/selectable/selectable_core.js15
-rw-r--r--tests/unit/selectable/selectable_test_helpers.js12
-rw-r--r--tests/unit/sortable/sortable.html1
-rw-r--r--tests/unit/sortable/sortable_core.js18
-rw-r--r--tests/unit/sortable/sortable_methods.js14
-rw-r--r--tests/unit/sortable/sortable_test_helpers.js9
-rw-r--r--tests/unit/sortable/sortable_tickets.js12
37 files changed, 821 insertions, 819 deletions
diff --git a/tests/.jshintrc b/tests/.jshintrc
index c0f0f8d53..9e2881c12 100644
--- a/tests/.jshintrc
+++ b/tests/.jshintrc
@@ -14,27 +14,13 @@
"unused": true,
"predef": [
"asyncTest",
- "container",
"deepEqual",
- "d1",
- "d2",
- "dlg",
"domEqual",
- "drag",
- "dragged",
- "el",
"equal",
- "equalsDate",
"expect",
"Globalize",
- "heightAfter",
- "init",
- "modal",
"module",
- "moved",
"notEqual",
- "offsetAfter",
- "offsetBefore",
"ok",
"QUnit",
"start",
@@ -42,7 +28,6 @@
"stop",
"test",
"TestHelpers",
- "widthAfter",
"JSHINT"
]
} \ No newline at end of file
diff --git a/tests/unit/datepicker/datepicker.html b/tests/unit/datepicker/datepicker.html
index 9530600f1..c0c68979d 100644
--- a/tests/unit/datepicker/datepicker.html
+++ b/tests/unit/datepicker/datepicker.html
@@ -27,6 +27,7 @@
<script src="datepicker_events.js"></script>
<script src="datepicker_methods.js"></script>
<script src="datepicker_options.js"></script>
+ <script src="datepicker_test_helpers.js"></script>
<script src="datepicker_tickets.js"></script>
<script src="../swarminject.js"></script>
diff --git a/tests/unit/datepicker/datepicker_core.js b/tests/unit/datepicker/datepicker_core.js
index 1a7d8cc82..86f71a1c4 100644
--- a/tests/unit/datepicker/datepicker_core.js
+++ b/tests/unit/datepicker/datepicker_core.js
@@ -2,30 +2,6 @@
* datepicker_core.js
*/
-function equalsDate(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);
-}
-
-TestHelpers.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;
-};
-
-function init(id, options) {
- $.datepicker.setDefaults($.datepicker.regional['']);
- return $(id).datepicker($.extend({showAnim: ''}, options || {}));
-}
-
-TestHelpers.PROP_NAME = 'datepicker';
-
(function($) {
module("datepicker: core");
@@ -45,7 +21,7 @@ test("widget method", function() {
test('baseStructure', function() {
expect( 58 );
var header, title, table, thead, week, panel, inl, child,
- inp = init('#inp').focus(),
+ inp = TestHelpers.datepicker.init('#inp').focus(),
dp = $('#ui-datepicker-div');
ok(dp.is(':visible'), 'Structure - datepicker visible');
ok(!dp.is('.ui-datepicker-rtl'), 'Structure - not right-to-left');
@@ -80,7 +56,7 @@ test('baseStructure', function() {
inp.datepicker('hide').datepicker('destroy');
// Editable month/year and button panel
- inp = init('#inp', {changeMonth: true, changeYear: true, showButtonPanel: true});
+ inp = TestHelpers.datepicker.init('#inp', {changeMonth: true, changeYear: true, showButtonPanel: true});
inp.focus();
title = dp.find('div.ui-datepicker-title');
@@ -95,7 +71,7 @@ test('baseStructure', function() {
inp.datepicker('hide').datepicker('destroy');
// Multi-month 2
- inp = init('#inp', {numberOfMonths: 2});
+ inp = TestHelpers.datepicker.init('#inp', {numberOfMonths: 2});
inp.focus();
ok(dp.is('.ui-datepicker-multi'), 'Structure multi [2] - multi-month');
equal(dp.children().length, 3, 'Structure multi [2] - child count');
@@ -109,14 +85,14 @@ test('baseStructure', function() {
inp.datepicker('hide').datepicker('destroy');
// Multi-month 3
- inp = init('#inp', {numberOfMonths: 3});
+ inp = TestHelpers.datepicker.init('#inp', {numberOfMonths: 3});
inp.focus();
ok(dp.is('.ui-datepicker-multi-3'), 'Structure multi [3] - multi-3');
ok(! dp.is('.ui-datepicker-multi-2'), 'Structure multi [3] - Trac #6704');
inp.datepicker('hide').datepicker('destroy');
// Multi-month [2, 2]
- inp = init('#inp', {numberOfMonths: [2, 2]});
+ inp = TestHelpers.datepicker.init('#inp', {numberOfMonths: [2, 2]});
inp.focus();
ok(dp.is('.ui-datepicker-multi'), 'Structure multi - multi-month');
equal(dp.children().length, 6, 'Structure multi [2,2] - child count');
@@ -135,7 +111,7 @@ test('baseStructure', function() {
inp.datepicker('hide').datepicker('destroy');
// Inline
- inl = init('#inl');
+ inl = TestHelpers.datepicker.init('#inl');
dp = inl.children();
ok(dp.is('.ui-datepicker-inline'), 'Structure inline - main div');
ok(!dp.is('.ui-datepicker-rtl'), 'Structure inline - not right-to-left');
@@ -151,7 +127,7 @@ test('baseStructure', function() {
inl.datepicker('destroy');
// Inline multi-month
- inl = init('#inl', {numberOfMonths: 2});
+ inl = TestHelpers.datepicker.init('#inl', {numberOfMonths: 2});
dp = inl.children();
ok(dp.is('.ui-datepicker-inline') && dp.is('.ui-datepicker-multi'), 'Structure inline multi - main div');
equal(dp.children().length, 3, 'Structure inline multi - child count');
@@ -169,7 +145,7 @@ test('customStructure', function() {
var header, panel, title, thead,
dp = $('#ui-datepicker-div'),
// Check right-to-left localisation
- inp = init('#inp', $.datepicker.regional.he);
+ inp = TestHelpers.datepicker.init('#inp', $.datepicker.regional.he);
inp.data('showButtonPanel.datepicker',true);
inp.focus();
ok(dp.is('.ui-datepicker-rtl'), 'Structure RTL - right-to-left');
@@ -186,7 +162,7 @@ test('customStructure', function() {
inp.datepicker('hide').datepicker('destroy');
// Hide prev/next
- inp = init('#inp', {hideIfNoPrevNext: true, minDate: new Date(2008, 2 - 1, 4), maxDate: new Date(2008, 2 - 1, 14)});
+ inp = TestHelpers.datepicker.init('#inp', {hideIfNoPrevNext: true, minDate: new Date(2008, 2 - 1, 4), maxDate: new Date(2008, 2 - 1, 14)});
inp.val('02/10/2008').focus();
header = dp.children(':first');
ok(header.is('div.ui-datepicker-header'), 'Structure hide prev/next - header division');
@@ -195,7 +171,7 @@ test('customStructure', function() {
inp.datepicker('hide').datepicker('destroy');
// Changeable Month with read-only year
- inp = init('#inp', {changeMonth: true});
+ inp = TestHelpers.datepicker.init('#inp', {changeMonth: true});
inp.focus();
title = dp.children(':first').children(':last');
equal(title.children().length, 2, 'Structure changeable month - title child count');
@@ -204,7 +180,7 @@ test('customStructure', function() {
inp.datepicker('hide').datepicker('destroy');
// Changeable year with read-only month
- inp = init('#inp', {changeYear: true});
+ inp = TestHelpers.datepicker.init('#inp', {changeYear: true});
inp.focus();
title = dp.children(':first').children(':last');
equal(title.children().length, 2, 'Structure changeable year - title child count');
@@ -213,7 +189,7 @@ test('customStructure', function() {
inp.datepicker('hide').datepicker('destroy');
// Read-only first day of week
- inp = init('#inp', {changeFirstDay: false});
+ inp = TestHelpers.datepicker.init('#inp', {changeFirstDay: false});
inp.focus();
thead = dp.find('.ui-datepicker-calendar thead tr');
equal(thead.children().length, 7, 'Structure read-only first day - thead child count');
@@ -223,19 +199,19 @@ test('customStructure', function() {
test('keystrokes', function() {
expect( 26 );
- var inp = init('#inp'),
+ var inp = TestHelpers.datepicker.init('#inp'),
date = new Date();
inp.val('').datepicker('show').
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
- equalsDate(inp.datepicker('getDate'), date, 'Keystroke enter');
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), date, 'Keystroke enter');
inp.val('02/04/2008').datepicker('show').
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
- equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4),
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4),
'Keystroke enter - preset');
inp.val('02/04/2008').datepicker('show').
simulate('keydown', {ctrlKey: true, keyCode: $.ui.keyCode.HOME}).
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
- equalsDate(inp.datepicker('getDate'), date, 'Keystroke ctrl+home');
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), date, 'Keystroke ctrl+home');
inp.val('02/04/2008').datepicker('show').
simulate('keydown', {ctrlKey: true, keyCode: $.ui.keyCode.END});
ok(inp.datepicker('getDate') == null, 'Keystroke ctrl+end');
@@ -244,95 +220,95 @@ test('keystrokes', function() {
ok(inp.datepicker('getDate') == null, 'Keystroke esc');
inp.val('02/04/2008').datepicker('show').
simulate('keydown', {keyCode: $.ui.keyCode.ESCAPE});
- equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4),
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4),
'Keystroke esc - preset');
inp.val('02/04/2008').datepicker('show').
simulate('keydown', {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}).
simulate('keydown', {keyCode: $.ui.keyCode.ESCAPE});
- equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4),
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4),
'Keystroke esc - abandoned');
// Moving by day or week
inp.val('').datepicker('show').
simulate('keydown', {ctrlKey: true, keyCode: $.ui.keyCode.LEFT}).
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
date.setDate(date.getDate() - 1);
- equalsDate(inp.datepicker('getDate'), date, 'Keystroke ctrl+left');
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), date, 'Keystroke ctrl+left');
inp.val('').datepicker('show').
simulate('keydown', {keyCode: $.ui.keyCode.LEFT}).
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
date.setDate(date.getDate() + 1);
- equalsDate(inp.datepicker('getDate'), date, 'Keystroke left');
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), date, 'Keystroke left');
inp.val('').datepicker('show').
simulate('keydown', {ctrlKey: true, keyCode: $.ui.keyCode.RIGHT}).
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
date.setDate(date.getDate() + 1);
- equalsDate(inp.datepicker('getDate'), date, 'Keystroke ctrl+right');
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), date, 'Keystroke ctrl+right');
inp.val('').datepicker('show').
simulate('keydown', {keyCode: $.ui.keyCode.RIGHT}).
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
date.setDate(date.getDate() - 1);
- equalsDate(inp.datepicker('getDate'), date, 'Keystroke right');
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), date, 'Keystroke right');
inp.val('').datepicker('show').
simulate('keydown', {ctrlKey: true, keyCode: $.ui.keyCode.UP}).
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
date.setDate(date.getDate() - 7);
- equalsDate(inp.datepicker('getDate'), date, 'Keystroke ctrl+up');
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), date, 'Keystroke ctrl+up');
inp.val('').datepicker('show').
simulate('keydown', {keyCode: $.ui.keyCode.UP}).
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
date.setDate(date.getDate() + 7);
- equalsDate(inp.datepicker('getDate'), date, 'Keystroke up');
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), date, 'Keystroke up');
inp.val('').datepicker('show').
simulate('keydown', {ctrlKey: true, keyCode: $.ui.keyCode.DOWN}).
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
date.setDate(date.getDate() + 7);
- equalsDate(inp.datepicker('getDate'), date, 'Keystroke ctrl+down');
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), date, 'Keystroke ctrl+down');
inp.val('').datepicker('show').
simulate('keydown', {keyCode: $.ui.keyCode.DOWN}).
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
date.setDate(date.getDate() - 7);
- equalsDate(inp.datepicker('getDate'), date, 'Keystroke down');
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), date, 'Keystroke down');
// Moving by month or year
inp.val('02/04/2008').datepicker('show').
simulate('keydown', {keyCode: $.ui.keyCode.PAGE_UP}).
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
- equalsDate(inp.datepicker('getDate'), new Date(2008, 1 - 1, 4),
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), new Date(2008, 1 - 1, 4),
'Keystroke pgup');
inp.val('02/04/2008').datepicker('show').
simulate('keydown', {keyCode: $.ui.keyCode.PAGE_DOWN}).
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
- equalsDate(inp.datepicker('getDate'), new Date(2008, 3 - 1, 4),
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), new Date(2008, 3 - 1, 4),
'Keystroke pgdn');
inp.val('02/04/2008').datepicker('show').
simulate('keydown', {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}).
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
- equalsDate(inp.datepicker('getDate'), new Date(2007, 2 - 1, 4),
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), new Date(2007, 2 - 1, 4),
'Keystroke ctrl+pgup');
inp.val('02/04/2008').datepicker('show').
simulate('keydown', {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN}).
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
- equalsDate(inp.datepicker('getDate'), new Date(2009, 2 - 1, 4),
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), new Date(2009, 2 - 1, 4),
'Keystroke ctrl+pgdn');
// Check for moving to short months
inp.val('03/31/2008').datepicker('show').
simulate('keydown', {keyCode: $.ui.keyCode.PAGE_UP}).
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
- equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 29),
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 29),
'Keystroke pgup - Feb');
inp.val('01/30/2008').datepicker('show').
simulate('keydown', {keyCode: $.ui.keyCode.PAGE_DOWN}).
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
- equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 29),
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 29),
'Keystroke pgdn - Feb');
inp.val('02/29/2008').datepicker('show').
simulate('keydown', {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}).
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
- equalsDate(inp.datepicker('getDate'), new Date(2007, 2 - 1, 28),
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), new Date(2007, 2 - 1, 28),
'Keystroke ctrl+pgup - Feb');
inp.val('02/29/2008').datepicker('show').
simulate('keydown', {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN}).
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
- equalsDate(inp.datepicker('getDate'), new Date(2009, 2 - 1, 28),
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), new Date(2009, 2 - 1, 28),
'Keystroke ctrl+pgdn - Feb');
// Goto current
inp.datepicker('option', {gotoCurrent: true}).
@@ -340,35 +316,35 @@ test('keystrokes', function() {
simulate('keydown', {keyCode: $.ui.keyCode.PAGE_DOWN}).
simulate('keydown', {ctrlKey: true, keyCode: $.ui.keyCode.HOME}).
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
- equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4),
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4),
'Keystroke ctrl+home');
// Change steps
inp.datepicker('option', {stepMonths: 2, gotoCurrent: false}).
datepicker('hide').val('02/04/2008').datepicker('show').
simulate('keydown', {keyCode: $.ui.keyCode.PAGE_UP}).
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
- equalsDate(inp.datepicker('getDate'), new Date(2007, 12 - 1, 4),
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), new Date(2007, 12 - 1, 4),
'Keystroke pgup step 2');
inp.val('02/04/2008').datepicker('show').
simulate('keydown', {keyCode: $.ui.keyCode.PAGE_DOWN}).
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
- equalsDate(inp.datepicker('getDate'), new Date(2008, 4 - 1, 4),
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), new Date(2008, 4 - 1, 4),
'Keystroke pgdn step 2');
});
test('mouse', function() {
expect( 15 );
var inl,
- inp = init('#inp'),
+ inp = TestHelpers.datepicker.init('#inp'),
dp = $('#ui-datepicker-div'),
date = new Date();
inp.val('').datepicker('show');
$('.ui-datepicker-calendar tbody a:contains(10)', dp).simulate('click', {});
date.setDate(10);
- equalsDate(inp.datepicker('getDate'), date, 'Mouse click');
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), date, 'Mouse click');
inp.val('02/04/2008').datepicker('show');
$('.ui-datepicker-calendar tbody a:contains(12)', dp).simulate('click', {});
- equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 12),
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 12),
'Mouse click - preset');
inp.val('02/04/2008').datepicker('show');
inp.val('').datepicker('show');
@@ -376,66 +352,66 @@ test('mouse', function() {
ok(inp.datepicker('getDate') == null, 'Mouse click - close');
inp.val('02/04/2008').datepicker('show');
$('button.ui-datepicker-close', dp).simulate('click', {});
- equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4),
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4),
'Mouse click - close + preset');
inp.val('02/04/2008').datepicker('show');
$('a.ui-datepicker-prev', dp).simulate('click', {});
$('button.ui-datepicker-close', dp).simulate('click', {});
- equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4),
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4),
'Mouse click - abandoned');
// Current/previous/next
inp.val('02/04/2008').datepicker('option', {showButtonPanel: true}).datepicker('show');
$('.ui-datepicker-current', dp).simulate('click', {});
$('.ui-datepicker-calendar tbody a:contains(14)', dp).simulate('click', {});
date.setDate(14);
- equalsDate(inp.datepicker('getDate'), date, 'Mouse click - current');
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), date, 'Mouse click - current');
inp.val('02/04/2008').datepicker('show');
$('.ui-datepicker-prev', dp).simulate('click');
$('.ui-datepicker-calendar tbody a:contains(16)', dp).simulate('click');
- equalsDate(inp.datepicker('getDate'), new Date(2008, 1 - 1, 16),
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), new Date(2008, 1 - 1, 16),
'Mouse click - previous');
inp.val('02/04/2008').datepicker('show');
$('.ui-datepicker-next', dp).simulate('click');
$('.ui-datepicker-calendar tbody a:contains(18)', dp).simulate('click');
- equalsDate(inp.datepicker('getDate'), new Date(2008, 3 - 1, 18),
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), new Date(2008, 3 - 1, 18),
'Mouse click - next');
// Previous/next with minimum/maximum
inp.datepicker('option', {minDate: new Date(2008, 2 - 1, 2),
maxDate: new Date(2008, 2 - 1, 26)}).val('02/04/2008').datepicker('show');
$('.ui-datepicker-prev', dp).simulate('click');
$('.ui-datepicker-calendar tbody a:contains(16)', dp).simulate('click');
- equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 16),
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 16),
'Mouse click - previous + min/max');
inp.val('02/04/2008').datepicker('show');
$('.ui-datepicker-next', dp).simulate('click');
$('.ui-datepicker-calendar tbody a:contains(18)', dp).simulate('click');
- equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 18),
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 18),
'Mouse click - next + min/max');
// Inline
- inl = init('#inl');
+ inl = TestHelpers.datepicker.init('#inl');
dp = $('.ui-datepicker-inline', inl);
date = new Date();
inl.datepicker('setDate', date);
$('.ui-datepicker-calendar tbody a:contains(10)', dp).simulate('click', {});
date.setDate(10);
- equalsDate(inl.datepicker('getDate'), date, 'Mouse click inline');
+ TestHelpers.datepicker.equalsDate(inl.datepicker('getDate'), date, 'Mouse click inline');
inl.datepicker('option', {showButtonPanel: true}).datepicker('setDate', new Date(2008, 2 - 1, 4));
$('.ui-datepicker-calendar tbody a:contains(12)', dp).simulate('click', {});
- equalsDate(inl.datepicker('getDate'), new Date(2008, 2 - 1, 12), 'Mouse click inline - preset');
+ TestHelpers.datepicker.equalsDate(inl.datepicker('getDate'), new Date(2008, 2 - 1, 12), 'Mouse click inline - preset');
inl.datepicker('option', {showButtonPanel: true});
$('.ui-datepicker-current', dp).simulate('click', {});
$('.ui-datepicker-calendar tbody a:contains(14)', dp).simulate('click', {});
date.setDate(14);
- equalsDate(inl.datepicker('getDate'), date, 'Mouse click inline - current');
+ TestHelpers.datepicker.equalsDate(inl.datepicker('getDate'), date, 'Mouse click inline - current');
inl.datepicker('setDate', new Date(2008, 2 - 1, 4));
$('.ui-datepicker-prev', dp).simulate('click');
$('.ui-datepicker-calendar tbody a:contains(16)', dp).simulate('click');
- equalsDate(inl.datepicker('getDate'), new Date(2008, 1 - 1, 16),
+ TestHelpers.datepicker.equalsDate(inl.datepicker('getDate'), new Date(2008, 1 - 1, 16),
'Mouse click inline - previous');
inl.datepicker('setDate', new Date(2008, 2 - 1, 4));
$('.ui-datepicker-next', dp).simulate('click');
$('.ui-datepicker-calendar tbody a:contains(18)', dp).simulate('click');
- equalsDate(inl.datepicker('getDate'), new Date(2008, 3 - 1, 18),
+ TestHelpers.datepicker.equalsDate(inl.datepicker('getDate'), new Date(2008, 3 - 1, 18),
'Mouse click inline - next');
});
diff --git a/tests/unit/datepicker/datepicker_events.js b/tests/unit/datepicker/datepicker_events.js
index b71067472..81b152c66 100644
--- a/tests/unit/datepicker/datepicker_events.js
+++ b/tests/unit/datepicker/datepicker_events.js
@@ -24,13 +24,13 @@ function callback2(year, month, inst) {
test('events', function() {
expect( 26 );
var dateStr, newMonthYear, inp2,
- inp = 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.PROP_NAME), 'Callback selected inst');
+ 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').
@@ -59,7 +59,7 @@ test('events', function() {
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.PROP_NAME), 'Callback change month/year inst');
+ 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});
@@ -107,7 +107,7 @@ test('events', function() {
val('').datepicker('show').
simulate('keydown', {keyCode: $.ui.keyCode.ESCAPE});
equal(selectedThis, inp[0], 'Callback close this');
- equal(selectedInst, $.data(inp[0], TestHelpers.PROP_NAME), 'Callback close inst');
+ 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});
@@ -120,7 +120,7 @@ test('events', function() {
simulate('keydown', {ctrlKey: true, keyCode: $.ui.keyCode.END});
equal(selectedDate, '', 'Callback close date - ctrl+end');
- inp2 = init('#inp2');
+ inp2 = TestHelpers.datepicker.init('#inp2');
inp2.datepicker().datepicker('option', {onClose: callback}).datepicker('show');
inp.datepicker('show');
equal(selectedThis, inp2[0], 'Callback close this');
diff --git a/tests/unit/datepicker/datepicker_methods.js b/tests/unit/datepicker/datepicker_methods.js
index 5e692d1a0..d2964a266 100644
--- a/tests/unit/datepicker/datepicker_methods.js
+++ b/tests/unit/datepicker/datepicker_methods.js
@@ -8,65 +8,65 @@ module("datepicker: methods");
test('destroy', function() {
expect( 33 );
var inl,
- inp = init('#inp');
+ inp = TestHelpers.datepicker.init('#inp');
ok(inp.is('.hasDatepicker'), 'Default - marker class set');
- ok($.data(inp[0], TestHelpers.PROP_NAME), 'Default - instance present');
+ ok($.data(inp[0], TestHelpers.datepicker.PROP_NAME), 'Default - instance present');
ok(inp.next().is('#alt'), 'Default - button absent');
inp.datepicker('destroy');
inp = $('#inp');
ok(!inp.is('.hasDatepicker'), 'Default - marker class cleared');
- ok(!$.data(inp[0], TestHelpers.PROP_NAME), 'Default - instance absent');
+ ok(!$.data(inp[0], TestHelpers.datepicker.PROP_NAME), 'Default - instance absent');
ok(inp.next().is('#alt'), 'Default - button absent');
// With button
- inp= init('#inp', {showOn: 'both'});
+ inp= TestHelpers.datepicker.init('#inp', {showOn: 'both'});
ok(inp.is('.hasDatepicker'), 'Button - marker class set');
- ok($.data(inp[0], TestHelpers.PROP_NAME), 'Button - instance present');
+ ok($.data(inp[0], TestHelpers.datepicker.PROP_NAME), 'Button - instance present');
ok(inp.next().text() === '...', 'Button - button added');
inp.datepicker('destroy');
inp = $('#inp');
ok(!inp.is('.hasDatepicker'), 'Button - marker class cleared');
- ok(!$.data(inp[0], TestHelpers.PROP_NAME), 'Button - instance absent');
+ ok(!$.data(inp[0], TestHelpers.datepicker.PROP_NAME), 'Button - instance absent');
ok(inp.next().is('#alt'), 'Button - button removed');
// With append text
- inp = init('#inp', {appendText: 'Testing'});
+ inp = TestHelpers.datepicker.init('#inp', {appendText: 'Testing'});
ok(inp.is('.hasDatepicker'), 'Append - marker class set');
- ok($.data(inp[0], TestHelpers.PROP_NAME), 'Append - instance present');
+ ok($.data(inp[0], TestHelpers.datepicker.PROP_NAME), 'Append - instance present');
ok(inp.next().text() === 'Testing', 'Append - append text added');
inp.datepicker('destroy');
inp = $('#inp');
ok(!inp.is('.hasDatepicker'), 'Append - marker class cleared');
- ok(!$.data(inp[0], TestHelpers.PROP_NAME), 'Append - instance absent');
+ ok(!$.data(inp[0], TestHelpers.datepicker.PROP_NAME), 'Append - instance absent');
ok(inp.next().is('#alt'), 'Append - append text removed');
// With both
- inp= init('#inp', {showOn: 'both', buttonImageOnly: true,
+ inp= TestHelpers.datepicker.init('#inp', {showOn: 'both', buttonImageOnly: true,
buttonImage: 'img/calendar.gif', appendText: 'Testing'});
ok(inp.is('.hasDatepicker'), 'Both - marker class set');
- ok($.data(inp[0], TestHelpers.PROP_NAME), 'Both - instance present');
+ ok($.data(inp[0], TestHelpers.datepicker.PROP_NAME), 'Both - instance present');
ok(inp.next()[0].nodeName.toLowerCase() === 'img', 'Both - button added');
ok(inp.next().next().text() === 'Testing', 'Both - append text added');
inp.datepicker('destroy');
inp = $('#inp');
ok(!inp.is('.hasDatepicker'), 'Both - marker class cleared');
- ok(!$.data(inp[0], TestHelpers.PROP_NAME), 'Both - instance absent');
+ ok(!$.data(inp[0], TestHelpers.datepicker.PROP_NAME), 'Both - instance absent');
ok(inp.next().is('#alt'), 'Both - button and append text absent');
// Inline
- inl = init('#inl');
+ inl = TestHelpers.datepicker.init('#inl');
ok(inl.is('.hasDatepicker'), 'Inline - marker class set');
ok(inl.html() !== '', 'Inline - datepicker present');
- ok($.data(inl[0], TestHelpers.PROP_NAME), 'Inline - instance present');
+ ok($.data(inl[0], TestHelpers.datepicker.PROP_NAME), 'Inline - instance present');
ok(inl.next().length === 0 || inl.next().is('p'), 'Inline - button absent');
inl.datepicker('destroy');
inl = $('#inl');
ok(!inl.is('.hasDatepicker'), 'Inline - marker class cleared');
ok(inl.html() === '', 'Inline - datepicker absent');
- ok(!$.data(inl[0], TestHelpers.PROP_NAME), 'Inline - instance absent');
+ ok(!$.data(inl[0], TestHelpers.datepicker.PROP_NAME), 'Inline - instance absent');
ok(inl.next().length === 0 || inl.next().is('p'), 'Inline - button absent');
});
test('enableDisable', function() {
expect( 33 );
var inl, dp,
- inp = init('#inp');
+ inp = TestHelpers.datepicker.init('#inp');
ok(!inp.datepicker('isDisabled'), 'Enable/disable - initially marked as enabled');
ok(!inp[0].disabled, 'Enable/disable - field initially enabled');
inp.datepicker('disable');
@@ -77,7 +77,7 @@ test('enableDisable', function() {
ok(!inp[0].disabled, 'Enable/disable - field now enabled');
inp.datepicker('destroy');
// With a button
- inp = init('#inp', {showOn: 'button'});
+ inp = TestHelpers.datepicker.init('#inp', {showOn: 'button'});
ok(!inp.datepicker('isDisabled'), 'Enable/disable button - initially marked as enabled');
ok(!inp[0].disabled, 'Enable/disable button - field initially enabled');
ok(!inp.next('button')[0].disabled, 'Enable/disable button - button initially enabled');
@@ -91,7 +91,7 @@ test('enableDisable', function() {
ok(!inp.next('button')[0].disabled, 'Enable/disable button - button now enabled');
inp.datepicker('destroy');
// With an image button
- inp = init('#inp', {showOn: 'button', buttonImageOnly: true,
+ inp = TestHelpers.datepicker.init('#inp', {showOn: 'button', buttonImageOnly: true,
buttonImage: 'img/calendar.gif'});
ok(!inp.datepicker('isDisabled'), 'Enable/disable image - initially marked as enabled');
ok(!inp[0].disabled, 'Enable/disable image - field initially enabled');
@@ -106,7 +106,7 @@ test('enableDisable', function() {
ok(parseFloat(inp.next('img').css('opacity')) === 1, 'Enable/disable image - image now enabled');
inp.datepicker('destroy');
// Inline
- inl = init('#inl', {changeYear: true});
+ inl = TestHelpers.datepicker.init('#inl', {changeYear: true});
dp = $('.ui-datepicker-inline', inl);
ok(!inl.datepicker('isDisabled'), 'Enable/disable inline - initially marked as enabled');
ok(!dp.children().is('.ui-state-disabled'), 'Enable/disable inline - not visually disabled initially');
diff --git a/tests/unit/datepicker/datepicker_options.js b/tests/unit/datepicker/datepicker_options.js
index 7d3217364..00910469e 100644
--- a/tests/unit/datepicker/datepicker_options.js
+++ b/tests/unit/datepicker/datepicker_options.js
@@ -8,7 +8,7 @@ module("datepicker: options");
test('setDefaults', function() {
expect( 3 );
- init('#inp');
+ TestHelpers.datepicker.init('#inp');
equal($.datepicker._defaults.showOn, 'focus', 'Initial showOn');
$.datepicker.setDefaults({showOn: 'button'});
equal($.datepicker._defaults.showOn, 'button', 'Change default showOn');
@@ -18,8 +18,8 @@ test('setDefaults', function() {
test('option', function() {
expect( 17 );
- var inp = init('#inp'),
- inst = $.data(inp[0], TestHelpers.PROP_NAME);
+ 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');
@@ -37,7 +37,7 @@ test('option', function() {
equal($.datepicker._get(inst, 'showOn'), 'focus', 'Restore instance showOn');
equal($.datepicker._defaults.showOn, 'focus', 'Retain default showOn');
// Get option
- inp = init('#inp');
+ 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');
@@ -50,8 +50,8 @@ test('option', function() {
test('change', function() {
expect( 12 );
- var inp = init('#inp'),
- inst = $.data(inp[0], TestHelpers.PROP_NAME);
+ 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');
@@ -72,7 +72,7 @@ test('change', function() {
test('invocation', function() {
expect( 29 );
var button, image,
- inp = init('#inp'),
+ inp = TestHelpers.datepicker.init('#inp'),
dp = $('#ui-datepicker-div'),
body = $('body');
// On focus
@@ -90,7 +90,7 @@ test('invocation', function() {
ok(!dp.is(':visible'), 'Focus - hidden on external click');
inp.datepicker('hide').datepicker('destroy');
// On button
- inp = init('#inp', {showOn: 'button', buttonText: 'Popup'});
+ inp = TestHelpers.datepicker.init('#inp', {showOn: 'button', buttonText: 'Popup'});
ok(!dp.is(':visible'), 'Button - initially hidden');
button = inp.siblings('button');
image = inp.siblings('img');
@@ -105,7 +105,7 @@ test('invocation', function() {
ok(!dp.is(':visible'), 'Button - hidden on second button click');
inp.datepicker('hide').datepicker('destroy');
// On image button
- inp = init('#inp', {showOn: 'button', buttonImageOnly: true,
+ inp = TestHelpers.datepicker.init('#inp', {showOn: 'button', buttonImageOnly: true,
buttonImage: 'img/calendar.gif', buttonText: 'Cal'});
ok(!dp.is(':visible'), 'Image button - initially hidden');
button = inp.siblings('button');
@@ -122,7 +122,7 @@ test('invocation', function() {
ok(!dp.is(':visible'), 'Image button - hidden on second image click');
inp.datepicker('hide').datepicker('destroy');
// On both
- inp = init('#inp', {showOn: 'both', buttonImage: 'img/calendar.gif'});
+ inp = TestHelpers.datepicker.init('#inp', {showOn: 'both', buttonImage: 'img/calendar.gif'});
ok(!dp.is(':visible'), 'Both - initially hidden');
button = inp.siblings('button');
ok(button.length === 1, 'Both - button present');
@@ -143,7 +143,7 @@ test('invocation', function() {
test('otherMonths', function() {
expect( 8 );
- var inp = init('#inp'),
+ var inp = TestHelpers.datepicker.init('#inp'),
pop = $('#ui-datepicker-div');
inp.val('06/01/2009').datepicker('show');
equal(pop.find('tbody').text(), '\u00a0123456789101112131415161718192021222324252627282930\u00a0\u00a0\u00a0\u00a0',
@@ -165,104 +165,104 @@ test('otherMonths', function() {
test('defaultDate', function() {
expect( 17 );
- var inp = init('#inp'),
+ var inp = TestHelpers.datepicker.init('#inp'),
date = new Date();
inp.val('').datepicker('show').
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
- equalsDate(inp.datepicker('getDate'), date, 'Default date null');
+ 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});
date.setDate(date.getDate() - 2);
- equalsDate(inp.datepicker('getDate'), date, 'Default date -2');
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), date, 'Default date -2');
inp.datepicker('option', {defaultDate: 3}).
datepicker('hide').val('').datepicker('show').
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
date.setDate(date.getDate() + 5);
- equalsDate(inp.datepicker('getDate'), date, 'Default date 3');
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), date, 'Default date 3');
inp.datepicker('option', {defaultDate: 1 / 0}).
datepicker('hide').val('').datepicker('show').
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
date.setDate(date.getDate() - 3);
- equalsDate(inp.datepicker('getDate'), date, 'Default date Infinity');
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), date, 'Default date Infinity');
inp.datepicker('option', {defaultDate: 1 / 'a'}).
datepicker('hide').val('').datepicker('show').
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
- equalsDate(inp.datepicker('getDate'), date, 'Default date NaN');
+ 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});
date.setDate(date.getDate() - 1);
- equalsDate(inp.datepicker('getDate'), date, 'Default date -1d');
+ 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);
- equalsDate(inp.datepicker('getDate'), date, 'Default date +3D');
+ 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);
- equalsDate(inp.datepicker('getDate'), date, 'Default date -2 w');
+ 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);
- equalsDate(inp.datepicker('getDate'), date, 'Default date +1 W');
+ 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.addMonths(new Date(), -1);
- equalsDate(inp.datepicker('getDate'), date, 'Default date -1 m');
+ 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});
- date = TestHelpers.addMonths(new Date(), 2);
- equalsDate(inp.datepicker('getDate'), date, 'Default date +2M');
+ 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});
date = new Date();
date.setFullYear(date.getFullYear() - 2);
- equalsDate(inp.datepicker('getDate'), date, 'Default date -2y');
+ 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);
- equalsDate(inp.datepicker('getDate'), date, 'Default date +1 Y');
+ 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.addMonths(new Date(), 1);
+ date = TestHelpers.datepicker.addMonths(new Date(), 1);
date.setDate(date.getDate() + 10);
- 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});
date = new Date(2007, 7 - 1, 4);
- equalsDate(inp.datepicker('getDate'), date, 'Default date 07/04/2007');
+ 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);
- 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});
- equalsDate(inp.datepicker('getDate'), date, 'Default date 01/26/2007');
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), date, 'Default date 01/26/2007');
});
test('miscellaneous', function() {
expect( 19 );
var curYear, longNames, shortNames, date,
dp = $('#ui-datepicker-div'),
- inp = init('#inp');
+ inp = TestHelpers.datepicker.init('#inp');
// Year range
function genRange(start, offset) {
var i = start,
@@ -323,7 +323,7 @@ test('miscellaneous', function() {
test('minMax', function() {
expect( 17 );
var date,
- inp = init('#inp'),
+ inp = TestHelpers.datepicker.init('#inp'),
lastYear = new Date(2007, 6 - 1, 4),
nextYear = new Date(2009, 6 - 1, 4),
minDate = new Date(2008, 2 - 1, 29),
@@ -331,45 +331,45 @@ test('minMax', function() {
inp.val('06/04/2008').datepicker('show');
inp.simulate('keydown', {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}).
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
- equalsDate(inp.datepicker('getDate'), lastYear,
+ 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});
- equalsDate(inp.datepicker('getDate'), nextYear,
+ 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});
- equalsDate(inp.datepicker('getDate'), minDate,
+ 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});
- equalsDate(inp.datepicker('getDate'), nextYear,
+ 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});
- equalsDate(inp.datepicker('getDate'), minDate,
+ 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});
- equalsDate(inp.datepicker('getDate'), maxDate,
+ 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});
- equalsDate(inp.datepicker('getDate'), lastYear,
+ 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});
- equalsDate(inp.datepicker('getDate'), maxDate,
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), maxDate,
'Min/max - null, 12/07/2008 - ctrl+pgdn');
// Relative dates
date = new Date();
@@ -378,80 +378,80 @@ test('minMax', function() {
datepicker('hide').val('').datepicker('show');
inp.simulate('keydown', {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}).
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
- equalsDate(inp.datepicker('getDate'), date,
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), date,
'Min/max - -1w, +1 M +10 D - ctrl+pgup');
- date = TestHelpers.addMonths(new Date(), 1);
+ 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});
- equalsDate(inp.datepicker('getDate'), date,
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), date,
'Min/max - -1w, +1 M +10 D - ctrl+pgdn');
// With existing date
- inp = init('#inp');
+ inp = TestHelpers.datepicker.init('#inp');
inp.val('06/04/2008').datepicker('option', {minDate: minDate});
- equalsDate(inp.datepicker('getDate'), new Date(2008, 6 - 1, 4), 'Min/max - setDate > min');
+ 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});
- equalsDate(inp.datepicker('getDate'), minDate, 'Min/max - setDate < min');
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), minDate, 'Min/max - setDate < min');
inp.datepicker('option', {minDate: null}).val('06/04/2008').datepicker('option', {maxDate: maxDate});
- equalsDate(inp.datepicker('getDate'), new Date(2008, 6 - 1, 4), 'Min/max - setDate < max');
+ 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});
- equalsDate(inp.datepicker('getDate'), maxDate, 'Min/max - setDate > max');
+ 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});
- equalsDate(inp.datepicker('getDate'), minDate, 'Min/max - setDate < min');
+ 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});
- equalsDate(inp.datepicker('getDate'), new Date(2008, 6 - 1, 4), 'Min/max - setDate > min, < max');
+ 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});
- equalsDate(inp.datepicker('getDate'), maxDate, 'Min/max - setDate > max');
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), maxDate, 'Min/max - setDate > max');
});
test('setDate', function() {
expect( 24 );
var inl, alt, minDate, maxDate, dateAndTimeToSet, dateAndTimeClone,
- inp = 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);
- equalsDate(inp.datepicker('getDate'), date1, 'Set date - 2008-06-04');
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), date1, 'Set date - 2008-06-04');
date1 = new Date();
date1.setDate(date1.getDate() + 7);
inp.datepicker('setDate', +7);
- equalsDate(inp.datepicker('getDate'), date1, 'Set date - +7');
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), date1, 'Set date - +7');
date2.setFullYear(date2.getFullYear() + 2);
inp.datepicker('setDate', '+2y');
- equalsDate(inp.datepicker('getDate'), date2, 'Set date - +2y');
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), date2, 'Set date - +2y');
inp.datepicker('setDate', date1, date2);
- equalsDate(inp.datepicker('getDate'), date1, 'Set date - two dates');
+ 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');
- equalsDate(inp.datepicker('getDate'), date1, 'Set date - c +7');
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), date1, 'Set date - c +7');
date1.setDate(date1.getDate() + 7);
inp.datepicker('setDate', 'c+7');
- equalsDate(inp.datepicker('getDate'), date1, 'Set date - c+7');
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), date1, 'Set date - c+7');
date1.setDate(date1.getDate() - 21);
inp.datepicker('setDate', 'c -3 w');
- equalsDate(inp.datepicker('getDate'), date1, 'Set date - c -3 w');
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), date1, 'Set date - c -3 w');
// Inline
- inl = init('#inl');
+ inl = TestHelpers.datepicker.init('#inl');
date1 = new Date(2008, 6 - 1, 4);
date2 = new Date();
- equalsDate(inl.datepicker('getDate'), date2, 'Set date inline - default');
+ TestHelpers.datepicker.equalsDate(inl.datepicker('getDate'), date2, 'Set date inline - default');
inl.datepicker('setDate', date1);
- equalsDate(inl.datepicker('getDate'), date1, 'Set date inline - 2008-06-04');
+ 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);
- equalsDate(inl.datepicker('getDate'), date1, 'Set date inline - +7');
+ TestHelpers.datepicker.equalsDate(inl.datepicker('getDate'), date1, 'Set date inline - +7');
date2.setFullYear(date2.getFullYear() + 2);
inl.datepicker('setDate', '+2y');
- equalsDate(inl.datepicker('getDate'), date2, 'Set date inline - +2y');
+ TestHelpers.datepicker.equalsDate(inl.datepicker('getDate'), date2, 'Set date inline - +2y');
inl.datepicker('setDate', date1, date2);
- equalsDate(inl.datepicker('getDate'), date1, 'Set date inline - two dates');
+ 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
@@ -462,23 +462,23 @@ test('setDate', function() {
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 = 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);
- equalsDate(inp.datepicker('getDate'), date2, 'Set date min/max - setDate > min');
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), date2, 'Set date min/max - setDate > min');
inp.datepicker('setDate', date1);
- equalsDate(inp.datepicker('getDate'), minDate, 'Set date min/max - setDate < min');
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), minDate, 'Set date min/max - setDate < min');
inp.val('').datepicker('option', {maxDate: maxDate, minDate: null}).datepicker('setDate', date1);
- equalsDate(inp.datepicker('getDate'), date1, 'Set date min/max - setDate < max');
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), date1, 'Set date min/max - setDate < max');
inp.datepicker('setDate', date2);
- equalsDate(inp.datepicker('getDate'), maxDate, 'Set date min/max - setDate > max');
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), maxDate, 'Set date min/max - setDate > max');
inp.val('').datepicker('option', {minDate: minDate}).datepicker('setDate', date1);
- equalsDate(inp.datepicker('getDate'), minDate, 'Set date min/max - setDate < min');
+ TestHelpers.datepicker.equalsDate(inp.datepicker('getDate'), minDate, 'Set date min/max - setDate < min');
inp.datepicker('setDate', date2);
- equalsDate(inp.datepicker('getDate'), maxDate, 'Set date min/max - setDate > max');
+ 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);
@@ -487,7 +487,7 @@ test('setDate', function() {
test('altField', function() {
expect( 10 );
- var inp = init('#inp'),
+ var inp = TestHelpers.datepicker.init('#inp'),
alt = $('#alt');
// No alternate field set
alt.val('');
@@ -526,7 +526,7 @@ test('altField', function() {
test('autoSize', function() {
expect( 15 );
- var inp = init('#inp');
+ 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');
@@ -562,7 +562,7 @@ test('autoSize', function() {
test('daylightSaving', function() {
expect( 25 );
- var inp = init('#inp'),
+ var inp = TestHelpers.datepicker.init('#inp'),
dp = $('#ui-datepicker-div');
ok(true, 'Daylight saving - ' + new Date());
// Australia, Sydney - AM change, southern hemisphere
@@ -669,7 +669,7 @@ test('callbacks', function() {
expect( 13 );
// Before show
var dp, day20, day21,
- inp = init('#inp', {beforeShow: beforeAll}),
+ 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');
@@ -679,7 +679,7 @@ test('callbacks', function() {
deepEqual(beforeShowInst, inst, 'Before show - inst OK');
inp.datepicker('hide').datepicker('destroy');
// Before show day
- inp = init('#inp', {beforeShowDay: beforeDay});
+ 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');
@@ -698,7 +698,7 @@ test('callbacks', function() {
test('localisation', function() {
expect( 24 );
var dp, month, day, date,
- inp = init('#inp', $.datepicker.regional.fr);
+ 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');
@@ -765,72 +765,72 @@ test('iso8601Week', function() {
test('parseDate', function() {
expect( 26 );
- init('#inp');
+ TestHelpers.datepicker.init('#inp');
var currentYear, gmtDate, fr, settings, zh;
ok($.datepicker.parseDate('d m y', '') == null, 'Parse date empty');
- equalsDate($.datepicker.parseDate('d m y', '3 2 01'),
+ TestHelpers.datepicker.equalsDate($.datepicker.parseDate('d m y', '3 2 01'),
new Date(2001, 2 - 1, 3), 'Parse date d m y');
- equalsDate($.datepicker.parseDate('dd mm yy', '03 02 2001'),
+ TestHelpers.datepicker.equalsDate($.datepicker.parseDate('dd mm yy', '03 02 2001'),
new Date(2001, 2 - 1, 3), 'Parse date dd mm yy');
- equalsDate($.datepicker.parseDate('d m y', '13 12 01'),
+ TestHelpers.datepicker.equalsDate($.datepicker.parseDate('d m y', '13 12 01'),
new Date(2001, 12 - 1, 13), 'Parse date d m y');
- equalsDate($.datepicker.parseDate('dd mm yy', '13 12 2001'),
+ TestHelpers.datepicker.equalsDate($.datepicker.parseDate('dd mm yy', '13 12 2001'),
new Date(2001, 12 - 1, 13), 'Parse date dd mm yy');
- equalsDate($.datepicker.parseDate('y-o', '01-34'),
+ TestHelpers.datepicker.equalsDate($.datepicker.parseDate('y-o', '01-34'),
new Date(2001, 2 - 1, 3), 'Parse date y-o');
- equalsDate($.datepicker.parseDate('yy-oo', '2001-347'),
+ TestHelpers.datepicker.equalsDate($.datepicker.parseDate('yy-oo', '2001-347'),
new Date(2001, 12 - 1, 13), 'Parse date yy-oo');
- equalsDate($.datepicker.parseDate('oo yy', '348 2004'),
+ TestHelpers.datepicker.equalsDate($.datepicker.parseDate('oo yy', '348 2004'),
new Date(2004, 12 - 1, 13), 'Parse date oo yy');
- equalsDate($.datepicker.parseDate('D d M y', 'Sat 3 Feb 01'),
+ 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');
- equalsDate($.datepicker.parseDate('d MM DD yy', '3 February Saturday 2001'),
+ 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');
- equalsDate($.datepicker.parseDate('DD, MM d, yy', 'Saturday, February 3, 2001'),
+ 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');
- equalsDate($.datepicker.parseDate('\'day\' d \'of\' MM (\'\'DD\'\'), 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();
- equalsDate($.datepicker.parseDate('y-m-d', (currentYear - 2000) + '-02-03'),
+ 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');
- equalsDate($.datepicker.parseDate('y-m-d', (currentYear - 2000 + 10) + '-02-03'),
+ 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');
- equalsDate($.datepicker.parseDate('y-m-d', (currentYear - 2000 + 11) + '-02-03'),
+ 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');
- equalsDate($.datepicker.parseDate('y-m-d', '80-02-03', {shortYearCutoff: 80}),
+ 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');
- equalsDate($.datepicker.parseDate('y-m-d', '81-02-03', {shortYearCutoff: 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');
- equalsDate($.datepicker.parseDate('y-m-d', (currentYear - 2000 + 60) + '-02-03', {shortYearCutoff: '+60'}),
+ 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');
- equalsDate($.datepicker.parseDate('y-m-d', (currentYear - 2000 + 61) + '-02-03', {shortYearCutoff: '+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());
- equalsDate($.datepicker.parseDate('@', '981158400000'), gmtDate, 'Parse date @');
- 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};
- equalsDate($.datepicker.parseDate('D d M y', 'Lun. 9 Avril 01', settings),
+ TestHelpers.datepicker.equalsDate($.datepicker.parseDate('D d M y', 'Lun. 9 Avril 01', settings),
new Date(2001, 4 - 1, 9), 'Parse date D M y with settings');
- equalsDate($.datepicker.parseDate('d MM DD yy', '9 Avril Lundi 2001', 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');
- equalsDate($.datepicker.parseDate('DD, MM d, yy', 'Lundi, Avril 9, 2001', 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');
- equalsDate($.datepicker.parseDate('\'jour\' d \'de\' MM (\'\'DD\'\'), yy',
+ 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'];
- equalsDate($.datepicker.parseDate('yy M d', '2011 十一 22', zh),
+ 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() {
expect( 17 );
- init('#inp');
+ TestHelpers.datepicker.init('#inp');
var fr, settings;
function expectError(expr, value, error) {
try {
@@ -883,7 +883,7 @@ test('parseDateErrors', function() {
test('formatDate', function() {
expect( 16 );
- 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');
diff --git a/tests/unit/datepicker/datepicker_test_helpers.js b/tests/unit/datepicker/datepicker_test_helpers.js
new file mode 100644
index 000000000..2d374f561
--- /dev/null
+++ b/tests/unit/datepicker/datepicker_test_helpers.js
@@ -0,0 +1,22 @@
+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);
+ return 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);
+ },
+ init: function(id, options) {
+ $.datepicker.setDefaults($.datepicker.regional['']);
+ return $(id).datepicker($.extend({showAnim: ''}, options || {}));
+ },
+ PROP_NAME: 'datepicker'
+}; \ No newline at end of file
diff --git a/tests/unit/datepicker/datepicker_tickets.js b/tests/unit/datepicker/datepicker_tickets.js
index ff5dfde63..4440992ae 100644
--- a/tests/unit/datepicker/datepicker_tickets.js
+++ b/tests/unit/datepicker/datepicker_tickets.js
@@ -8,7 +8,7 @@ module("datepicker: tickets");
// http://forum.jquery.com/topic/several-breaking-changes-in-jquery-ui-1-8rc1
test('beforeShowDay-getDate', function() {
expect( 3 );
- var inp = init('#inp', {beforeShowDay: function() { inp.datepicker('getDate'); return [true, '']; }}),
+ var inp = TestHelpers.datepicker.init('#inp', {beforeShowDay: function() { inp.datepicker('getDate'); return [true, '']; }}),
dp = $('#ui-datepicker-div');
inp.val('01/01/2010').datepicker('show');
// contains non-breaking space
@@ -27,7 +27,7 @@ test('beforeShowDay-getDate', function() {
test('Ticket 7602: Stop datepicker from appearing with beforeShow event handler', function(){
expect( 3 );
- var inp = init('#inp',{
+ var inp = TestHelpers.datepicker.init('#inp',{
beforeShow: function(){
return false;
}
@@ -37,7 +37,7 @@ test('Ticket 7602: Stop datepicker from appearing with beforeShow event handler'
equal(dp.css('display'), 'none',"beforeShow returns false");
inp.datepicker('destroy');
- inp = init('#inp',{
+ inp = TestHelpers.datepicker.init('#inp',{
beforeShow: function(){
}
});
@@ -47,7 +47,7 @@ test('Ticket 7602: Stop datepicker from appearing with beforeShow event handler'
inp.datepicker('hide');
inp.datepicker('destroy');
- inp = init('#inp',{
+ inp = TestHelpers.datepicker.init('#inp',{
beforeShow: function(){
return true;
}
diff --git a/tests/unit/dialog/dialog.html b/tests/unit/dialog/dialog.html
index 6722f1bb0..cb74bb654 100644
--- a/tests/unit/dialog/dialog.html
+++ b/tests/unit/dialog/dialog.html
@@ -29,6 +29,7 @@
<script src="dialog_events.js"></script>
<script src="dialog_methods.js"></script>
<script src="dialog_options.js"></script>
+ <script src="dialog_test_helpers.js"></script>
<script src="dialog_tickets.js"></script>
<script src="../swarminject.js"></script>
diff --git a/tests/unit/dialog/dialog_core.js b/tests/unit/dialog/dialog_core.js
index a9e5e9be2..b36f6204f 100644
--- a/tests/unit/dialog/dialog_core.js
+++ b/tests/unit/dialog/dialog_core.js
@@ -2,80 +2,6 @@
* dialog_core.js
*/
-var el,
- offsetBefore, offsetAfter,
- heightBefore, heightAfter,
- widthBefore, widthAfter,
- dragged;
-
-function dlg() {
- return el.dialog('widget');
-}
-
-TestHelpers.isOpen = function(why) {
- ok(dlg().is(":visible"), why);
-};
-
-TestHelpers.isNotOpen = function(why) {
- ok(!dlg().is(":visible"), why);
-};
-
-function drag(handle, dx, dy) {
- var d = dlg();
- offsetBefore = d.offset();
- heightBefore = d.height();
- widthBefore = d.width();
- //this mouseover is to work around a limitation in resizable
- //TODO: fix resizable so handle doesn't require mouseover in order to be used
- $(handle, d).simulate("mouseover");
- $(handle, d).simulate("drag", {
- dx: dx || 0,
- dy: dy || 0
- });
- dragged = { dx: dx, dy: dy };
- offsetAfter = d.offset();
- heightAfter = d.height();
- widthAfter = d.width();
-}
-
-TestHelpers.dialogMoved = function(dx, dy, msg) {
- msg = msg ? msg + "." : "";
- var actual = { left: Math.round(offsetAfter.left), top: Math.round(offsetAfter.top) },
- expected = { left: Math.round(offsetBefore.left + dx), top: Math.round(offsetBefore.top + dy) };
- deepEqual(actual, expected, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ' + msg);
-};
-
-TestHelpers.shouldmove = function(why) {
- var handle = $(".ui-dialog-titlebar", dlg());
- drag(handle, 50, -50);
- TestHelpers.dialogMoved(50, -50, why);
-};
-
-TestHelpers.shouldnotmove = function(why) {
- var handle = $(".ui-dialog-titlebar", dlg());
- drag(handle, 50, -50);
- TestHelpers.dialogMoved(0, 0, why);
-};
-
-TestHelpers.resized = function(dw, dh, msg) {
- msg = msg ? msg + "." : "";
- var actual = { width: widthAfter, height: heightAfter },
- expected = { width: widthBefore + dw, height: heightBefore + dh };
- deepEqual(actual, expected, 'resized[' + dragged.dx + ', ' + dragged.dy + '] ' + msg);
-};
-
-TestHelpers.shouldresize = function(why) {
- var handle = $(".ui-resizable-se", dlg());
- drag(handle, 50, 50);
- TestHelpers.resized(50, 50, why);
-};
-
-TestHelpers.shouldnotresize = function(why) {
- var handle = $(".ui-resizable-se", dlg());
- drag(handle, 50, 50);
- TestHelpers.resized(0, 0, why);
-};
-
(function($) {
module("dialog: core");
@@ -83,8 +9,10 @@ module("dialog: core");
test("title id", function() {
expect(1);
- el = $('<div></div>').dialog();
- var titleId = dlg().find('.ui-dialog-title').attr('id');
+ var titleId,
+ el = $('<div></div>').dialog();
+
+ titleId = el.dialog('widget').find('.ui-dialog-title').attr('id');
ok( /ui-id-\d+$/.test( titleId ), 'auto-numbered title id');
el.remove();
});
@@ -92,16 +20,17 @@ test("title id", function() {
test("ARIA", function() {
expect(4);
- el = $('<div></div>').dialog();
+ var labelledBy,
+ el = $('<div></div>').dialog();
- equal(dlg().attr('role'), 'dialog', 'dialog role');
+ equal(el.dialog('widget').attr('role'), 'dialog', 'dialog role');
- var labelledBy = dlg().attr('aria-labelledby');
+ labelledBy = el.dialog('widget').attr('aria-labelledby');
ok(labelledBy.length > 0, 'has aria-labelledby attribute');
- equal(dlg().find('.ui-dialog-title').attr('id'), labelledBy,
+ equal(el.dialog('widget').find('.ui-dialog-title').attr('id'), labelledBy,
'proper aria-labelledby attribute');
- equal(dlg().find('.ui-dialog-titlebar-close').attr('role'), 'button',
+ equal(el.dialog('widget').find('.ui-dialog-titlebar-close').attr('role'), 'button',
'close link role');
el.remove();
diff --git a/tests/unit/dialog/dialog_events.js b/tests/unit/dialog/dialog_events.js
index 38b75a714..c5090d8f6 100644
--- a/tests/unit/dialog/dialog_events.js
+++ b/tests/unit/dialog/dialog_events.js
@@ -8,7 +8,7 @@ module("dialog: events");
test("open", function() {
expect(13);
- el = $("<div></div>");
+ var el = $("<div></div>");
el.dialog({
open: function(ev, ui) {
ok(el.data("dialog")._isOpen, "interal _isOpen flag is set");
@@ -42,163 +42,171 @@ test("open", function() {
test("dragStart", function() {
expect(9);
- el = $('<div></div>').dialog({
- dragStart: function(ev, ui) {
- ok(true, 'dragging fires dragStart callback');
- equal(this, el[0], "context of callback");
- equal(ev.type, 'dialogdragstart', 'event type in callback');
+ var handle,
+ el = $('<div></div>').dialog({
+ dragStart: function(ev, ui) {
+ ok(true, 'dragging fires dragStart callback');
+ equal(this, el[0], "context of callback");
+ equal(ev.type, 'dialogdragstart', 'event type in callback');
+ ok(ui.position !== undefined, "ui.position in callback");
+ ok(ui.offset !== undefined, "ui.offset in callback");
+ }
+ }).bind('dialogdragstart', function(ev, ui) {
+ ok(true, 'dragging fires dialogdragstart event');
+ equal(this, el[0], 'context of event');
ok(ui.position !== undefined, "ui.position in callback");
ok(ui.offset !== undefined, "ui.offset in callback");
- }
- }).bind('dialogdragstart', function(ev, ui) {
- ok(true, 'dragging fires dialogdragstart event');
- equal(this, el[0], 'context of event');
- ok(ui.position !== undefined, "ui.position in callback");
- ok(ui.offset !== undefined, "ui.offset in callback");
- });
- var handle = $(".ui-dialog-titlebar", dlg());
- drag(handle, 50, 50);
+ });
+
+ handle = $(".ui-dialog-titlebar", el.dialog('widget'));
+ TestHelpers.dialog.drag(el, handle, 50, 50);
el.remove();
});
test("drag", function() {
expect(9);
var handle,
- hasDragged = false;
+ hasDragged = false,
+ el = $('<div></div>').dialog({
+ drag: function(ev, ui) {
+ if (!hasDragged) {
+ ok(true, 'dragging fires drag callback');
+ equal(this, el[0], "context of callback");
+ equal(ev.type, 'dialogdrag', 'event type in callback');
+ ok(ui.position !== undefined, "ui.position in callback");
+ ok(ui.offset !== undefined, "ui.offset in callback");
- el = $('<div></div>').dialog({
- drag: function(ev, ui) {
- if (!hasDragged) {
- ok(true, 'dragging fires drag callback');
- equal(this, el[0], "context of callback");
- equal(ev.type, 'dialogdrag', 'event type in callback');
- ok(ui.position !== undefined, "ui.position in callback");
- ok(ui.offset !== undefined, "ui.offset in callback");
-
- hasDragged = true;
+ hasDragged = true;
+ }
}
- }
- }).one('dialogdrag', function(ev, ui) {
- ok(true, 'dragging fires dialogdrag event');
- equal(this, el[0], 'context of event');
- ok(ui.position !== undefined, "ui.position in callback");
- ok(ui.offset !== undefined, "ui.offset in callback");
- });
- handle = $(".ui-dialog-titlebar", dlg());
- drag(handle, 50, 50);
+ }).one('dialogdrag', function(ev, ui) {
+ ok(true, 'dragging fires dialogdrag event');
+ equal(this, el[0], 'context of event');
+ ok(ui.position !== undefined, "ui.position in callback");
+ ok(ui.offset !== undefined, "ui.offset in callback");
+ });
+
+ handle = $(".ui-dialog-titlebar", el.dialog('widget'));
+ TestHelpers.dialog.drag(el, handle, 50, 50);
el.remove();
});
test("dragStop", function() {
expect(9);
- el = $('<div></div>').dialog({
- dragStop: function(ev, ui) {
- ok(true, 'dragging fires dragStop callback');
- equal(this, el[0], "context of callback");
- equal(ev.type, 'dialogdragstop', 'event type in callback');
+ var handle,
+ el = $('<div></div>').dialog({
+ dragStop: function(ev, ui) {
+ ok(true, 'dragging fires dragStop callback');
+ equal(this, el[0], "context of callback");
+ equal(ev.type, 'dialogdragstop', 'event type in callback');
+ ok(ui.position !== undefined, "ui.position in callback");
+ ok(ui.offset !== undefined, "ui.offset in callback");
+ }
+ }).bind('dialogdragstop', function(ev, ui) {
+ ok(true, 'dragging fires dialogdragstop event');
+ equal(this, el[0], 'context of event');
ok(ui.position !== undefined, "ui.position in callback");
ok(ui.offset !== undefined, "ui.offset in callback");
- }
- }).bind('dialogdragstop', function(ev, ui) {
- ok(true, 'dragging fires dialogdragstop event');
- equal(this, el[0], 'context of event');
- ok(ui.position !== undefined, "ui.position in callback");
- ok(ui.offset !== undefined, "ui.offset in callback");
- });
- var handle = $(".ui-dialog-titlebar", dlg());
- drag(handle, 50, 50);
+ });
+
+ handle = $(".ui-dialog-titlebar", el.dialog('widget'));
+ TestHelpers.dialog.drag(el, handle, 50, 50);
el.remove();
});
test("resizeStart", function() {
expect(13);
- el = $('<div></div>').dialog({
- resizeStart: function(ev, ui) {
- ok(true, 'resizing fires resizeStart callback');
- equal(this, el[0], "context of callback");
- equal(ev.type, 'dialogresizestart', 'event type in callback');
+ var handle,
+ el = $('<div></div>').dialog({
+ resizeStart: function(ev, ui) {
+ ok(true, 'resizing fires resizeStart callback');
+ equal(this, el[0], "context of callback");
+ equal(ev.type, 'dialogresizestart', 'event type in callback');
+ ok(ui.originalPosition !== undefined, "ui.originalPosition in callback");
+ ok(ui.originalSize !== undefined, "ui.originalSize in callback");
+ ok(ui.position !== undefined, "ui.position in callback");
+ ok(ui.size !== undefined, "ui.size in callback");
+ }
+ }).bind('dialogresizestart', function(ev, ui) {
+ ok(true, 'resizing fires dialogresizestart event');
+ equal(this, el[0], 'context of event');
ok(ui.originalPosition !== undefined, "ui.originalPosition in callback");
ok(ui.originalSize !== undefined, "ui.originalSize in callback");
ok(ui.position !== undefined, "ui.position in callback");
ok(ui.size !== undefined, "ui.size in callback");
- }
- }).bind('dialogresizestart', function(ev, ui) {
- ok(true, 'resizing fires dialogresizestart event');
- equal(this, el[0], 'context of event');
- ok(ui.originalPosition !== undefined, "ui.originalPosition in callback");
- ok(ui.originalSize !== undefined, "ui.originalSize in callback");
- ok(ui.position !== undefined, "ui.position in callback");
- ok(ui.size !== undefined, "ui.size in callback");
- });
- var handle = $(".ui-resizable-se", dlg());
- drag(handle, 50, 50);
+ });
+
+ handle = $(".ui-resizable-se", el.dialog('widget'));
+ TestHelpers.dialog.drag(el, handle, 50, 50);
el.remove();
});
test("resize", function() {
expect(13);
var handle,
- hasResized = false;
-
- el = $('<div></div>').dialog({
- resize: function(ev, ui) {
- if (!hasResized) {
- ok(true, 'resizing fires resize callback');
- equal(this, el[0], "context of callback");
- equal(ev.type, 'dialogresize', 'event type in callback');
- ok(ui.originalPosition !== undefined, "ui.originalPosition in callback");
- ok(ui.originalSize !== undefined, "ui.originalSize in callback");
- ok(ui.position !== undefined, "ui.position in callback");
- ok(ui.size !== undefined, "ui.size in callback");
+ hasResized = false,
+ el = $('<div></div>').dialog({
+ resize: function(ev, ui) {
+ if (!hasResized) {
+ ok(true, 'resizing fires resize callback');
+ equal(this, el[0], "context of callback");
+ equal(ev.type, 'dialogresize', 'event type in callback');
+ ok(ui.originalPosition !== undefined, "ui.originalPosition in callback");
+ ok(ui.originalSize !== undefined, "ui.originalSize in callback");
+ ok(ui.position !== undefined, "ui.position in callback");
+ ok(ui.size !== undefined, "ui.size in callback");
- hasResized = true;
+ hasResized = true;
+ }
}
- }
- }).one('dialogresize', function(ev, ui) {
- ok(true, 'resizing fires dialogresize event');
- equal(this, el[0], 'context of event');
- ok(ui.originalPosition !== undefined, "ui.originalPosition in callback");
- ok(ui.originalSize !== undefined, "ui.originalSize in callback");
- ok(ui.position !== undefined, "ui.position in callback");
- ok(ui.size !== undefined, "ui.size in callback");
- });
- handle = $(".ui-resizable-se", dlg());
- drag(handle, 50, 50);
+ }).one('dialogresize', function(ev, ui) {
+ ok(true, 'resizing fires dialogresize event');
+ equal(this, el[0], 'context of event');
+ ok(ui.originalPosition !== undefined, "ui.originalPosition in callback");
+ ok(ui.originalSize !== undefined, "ui.originalSize in callback");
+ ok(ui.position !== undefined, "ui.position in callback");
+ ok(ui.size !== undefined, "ui.size in callback");
+ });
+
+ handle = $(".ui-resizable-se", el.dialog('widget'));
+ TestHelpers.dialog.drag(el, handle, 50, 50);
el.remove();
});
test("resizeStop", function() {
expect(13);
- el = $('<div></div>').dialog({
- resizeStop: function(ev, ui) {
- ok(true, 'resizing fires resizeStop callback');
- equal(this, el[0], "context of callback");
- equal(ev.type, 'dialogresizestop', 'event type in callback');
- ok(ui.originalPosition !== undefined, "ui.originalPosition in callback");
- ok(ui.originalSize !== undefined, "ui.originalSize in callback");
- ok(ui.position !== undefined, "ui.position in callback");
- ok(ui.size !== undefined, "ui.size in callback");
- }
- }).bind('dialogresizestop', function(ev, ui) {
- ok(true, 'resizing fires dialogresizestop event');
- equal(this, el[0], 'context of event');
- ok(ui.originalPosition !== undefined, "ui.originalPosition in callback");
- ok(ui.originalSize !== undefined, "ui.originalSize in callback");
- ok(ui.position !== undefined, "ui.position in callback");
- ok(ui.size !== undefined, "ui.size in callback");
- });
- var handle = $(".ui-resizable-se", dlg());
- drag(handle, 50, 50);
+ var handle,
+ el = $('<div></div>').dialog({
+ resizeStop: function(ev, ui) {
+ ok(true, 'resizing fires resizeStop callback');
+ equal(this, el[0], "context of callback");
+ equal(ev.type, 'dialogresizestop', 'event type in callback');
+ ok(ui.originalPosition !== undefined, "ui.originalPosition in callback");
+ ok(ui.originalSize !== undefined, "ui.originalSize in callback");
+ ok(ui.position !== undefined, "ui.position in callback");
+ ok(ui.size !== undefined, "ui.size in callback");
+ }
+ }).bind('dialogresizestop', function(ev, ui) {
+ ok(true, 'resizing fires dialogresizestop event');
+ equal(this, el[0], 'context of event');
+ ok(ui.originalPosition !== undefined, "ui.originalPosition in callback");
+ ok(ui.originalSize !== undefined, "ui.originalSize in callback");
+ ok(ui.position !== undefined, "ui.position in callback");
+ ok(ui.size !== undefined, "ui.size in callback");
+ });
+
+ handle = $(".ui-resizable-se", el.dialog('widget'));
+ TestHelpers.dialog.drag(el, handle, 50, 50);
el.remove();
});
asyncTest("close", function() {
expect(14);
- el = $('<div></div>').dialog({
+ var el = $('<div></div>').dialog({
close: function(ev, ui) {
ok(true, '.dialog("close") fires close callback');
equal(this, el[0], "context of callback");
@@ -234,7 +242,7 @@ asyncTest("close", function() {
test("beforeClose", function() {
expect(14);
- el = $('<div></div>').dialog({
+ var el = $('<div></div>').dialog({
beforeClose: function(ev, ui) {
ok(true, '.dialog("close") fires beforeClose callback');
equal(this, el[0], "context of callback");
@@ -243,8 +251,9 @@ test("beforeClose", function() {
return false;
}
});
+
el.dialog('close');
- TestHelpers.isOpen('beforeClose callback should prevent dialog from closing');
+ ok( el.dialog("widget").is(":visible"), 'beforeClose callback should prevent dialog from closing');
el.remove();
el = $('<div></div>').dialog();
@@ -256,7 +265,8 @@ test("beforeClose", function() {
return false;
});
el.dialog('close');
- TestHelpers.isOpen('beforeClose callback should prevent dialog from closing');
+
+ ok( el.dialog("widget").is(":visible"), 'beforeClose callback should prevent dialog from closing');
el.remove();
el = $('<div></div>').dialog().bind('dialogbeforeclose', function(ev, ui) {
@@ -266,7 +276,7 @@ test("beforeClose", function() {
return false;
});
el.dialog('close');
- TestHelpers.isOpen('dialogbeforeclose event should prevent dialog from closing');
+ ok( el.dialog("widget").is(":visible"), 'dialogbeforeclose event should prevent dialog from closing');
el.remove();
});
diff --git a/tests/unit/dialog/dialog_methods.js b/tests/unit/dialog/dialog_methods.js
index e7b2fc710..7048a76a9 100644
--- a/tests/unit/dialog/dialog_methods.js
+++ b/tests/unit/dialog/dialog_methods.js
@@ -24,7 +24,7 @@ test("init", function() {
$('<div></div>').appendTo('body').remove().dialog().remove();
ok(true, '.dialog() called on disconnected DOMElement - removed');
- el = $('<div></div>').dialog();
+ var el = $('<div></div>').dialog();
el.dialog("option", "foo");
el.remove();
ok(true, 'arbitrary option getter after init');
@@ -53,46 +53,49 @@ test("destroy", function() {
test("enable", function() {
expect( 3 );
- var expected = $('<div></div>').dialog(),
+ var el,
+ expected = $('<div></div>').dialog(),
actual = expected.dialog('enable');
equal(actual, expected, 'enable is chainable');
el = $('<div></div>').dialog({ disabled: true });
el.dialog('enable');
equal(el.dialog('option', 'disabled'), false, 'enable method sets disabled option to false');
- ok(!dlg().hasClass('ui-dialog-disabled'), 'enable method removes ui-dialog-disabled class from ui-dialog element');
+ ok(!el.dialog('widget').hasClass('ui-dialog-disabled'), 'enable method removes ui-dialog-disabled class from ui-dialog element');
});
test("disable", function() {
expect( 3 );
- var expected = $('<div></div>').dialog(),
+ var el,
+ expected = $('<div></div>').dialog(),
actual = expected.dialog('disable');
equal(actual, expected, 'disable is chainable');
el = $('<div></div>').dialog({ disabled: false });
el.dialog('disable');
equal(el.dialog('option', 'disabled'), true, 'disable method sets disabled option to true');
- ok(dlg().hasClass('ui-dialog-disabled'), 'disable method adds ui-dialog-disabled class to ui-dialog element');
+ ok(el.dialog('widget').hasClass('ui-dialog-disabled'), 'disable method adds ui-dialog-disabled class to ui-dialog element');
});
test("close", function() {
expect( 3 );
- var expected = $('<div></div>').dialog(),
+ var el,
+ expected = $('<div></div>').dialog(),
actual = expected.dialog('close');
equal(actual, expected, 'close is chainable');
el = $('<div></div>').dialog();
- ok(dlg().is(':visible') && !dlg().is(':hidden'), 'dialog visible before close method called');
+ ok(el.dialog('widget').is(':visible') && !el.dialog('widget').is(':hidden'), 'dialog visible before close method called');
el.dialog('close');
- ok(dlg().is(':hidden') && !dlg().is(':visible'), 'dialog hidden after close method called');
+ ok(el.dialog('widget').is(':hidden') && !el.dialog('widget').is(':visible'), 'dialog hidden after close method called');
});
test("isOpen", function() {
expect(4);
- el = $('<div></div>').dialog();
+ var el = $('<div></div>').dialog();
equal(el.dialog('isOpen'), true, "dialog is open after init");
el.dialog('close');
equal(el.dialog('isOpen'), false, "dialog is closed");
@@ -134,14 +137,15 @@ test("moveToTop", function() {
test("open", function() {
expect( 3 );
- var expected = $('<div></div>').dialog(),
+ var el,
+ expected = $('<div></div>').dialog(),
actual = expected.dialog('open');
equal(actual, expected, 'open is chainable');
el = $('<div></div>').dialog({ autoOpen: false });
- ok(dlg().is(':hidden') && !dlg().is(':visible'), 'dialog hidden before open method called');
+ ok(el.dialog('widget').is(':hidden') && !el.dialog('widget').is(':visible'), 'dialog hidden before open method called');
el.dialog('open');
- ok(dlg().is(':visible') && !dlg().is(':hidden'), 'dialog visible after open method called');
+ ok(el.dialog('widget').is(':visible') && !el.dialog('widget').is(':hidden'), 'dialog visible after open method called');
});
})(jQuery);
diff --git a/tests/unit/dialog/dialog_options.js b/tests/unit/dialog/dialog_options.js
index 1c823868e..b6ff2dfc4 100644
--- a/tests/unit/dialog/dialog_options.js
+++ b/tests/unit/dialog/dialog_options.js
@@ -8,12 +8,12 @@ module("dialog: options");
test("autoOpen", function() {
expect(2);
- el = $('<div></div>').dialog({ autoOpen: false });
- TestHelpers.isNotOpen('.dialog({ autoOpen: false })');
+ var el = $('<div></div>').dialog({ autoOpen: false });
+ ok( !el.dialog("widget").is(":visible"), '.dialog({ autoOpen: false })');
el.remove();
el = $('<div></div>').dialog({ autoOpen: true });
- TestHelpers.isOpen('.dialog({ autoOpen: true })');
+ ok( el.dialog("widget").is(":visible"), '.dialog({ autoOpen: true })');
el.remove();
});
@@ -22,20 +22,20 @@ test("buttons", function() {
var btn, i, newButtons,
buttons = {
- "Ok": function( ev ) {
- ok(true, "button click fires callback");
- equal(this, el[0], "context of callback");
- equal(ev.target, btn[0], "event target");
+ "Ok": function( ev ) {
+ ok(true, "button click fires callback");
+ equal(this, el[0], "context of callback");
+ equal(ev.target, btn[0], "event target");
+ },
+ "Cancel": function( ev ) {
+ ok(true, "button click fires callback");
+ equal(this, el[0], "context of callback");
+ equal(ev.target, btn[1], "event target");
+ }
},
- "Cancel": function( ev ) {
- ok(true, "button click fires callback");
- equal(this, el[0], "context of callback");
- equal(ev.target, btn[1], "event target");
- }
- };
+ el = $('<div></div>').dialog({ buttons: buttons });
- el = $('<div></div>').dialog({ buttons: buttons });
- btn = $("button", dlg());
+ btn = $("button", el.dialog('widget'));
equal(btn.length, 2, "number of buttons");
i = 0;
@@ -61,7 +61,7 @@ test("buttons", function() {
el.dialog("option", "buttons", newButtons);
deepEqual(el.dialog("option", "buttons"), newButtons, '.dialog("option", "buttons", ...) setter');
- btn = $("button", dlg());
+ btn = $("button", el.dialog('widget'));
equal(btn.length, 1, "number of buttons after setter");
btn.trigger('click');
@@ -72,7 +72,7 @@ test("buttons", function() {
});
el.dialog("option", "buttons", null);
- btn = $("button", dlg());
+ btn = $("button", el.dialog('widget'));
equal(btn.length, 0, "all buttons have been removed");
equal(el.find(".ui-dialog-buttonset").length, 0, "buttonset has been removed");
equal(el.parent().hasClass('ui-dialog-buttons'), false, "dialog wrapper removes class about having buttons");
@@ -83,19 +83,21 @@ test("buttons", function() {
test("buttons - advanced", function() {
expect(5);
- el = $("<div></div>").dialog({
- buttons: [
- {
- text: "a button",
- "class": "additional-class",
- id: "my-button-id",
- click: function() {
- equal(this, el[0], "correct context");
+ var buttons,
+ el = $("<div></div>").dialog({
+ buttons: [
+ {
+ text: "a button",
+ "class": "additional-class",
+ id: "my-button-id",
+ click: function() {
+ equal(this, el[0], "correct context");
+ }
}
- }
- ]
- });
- var buttons = dlg().find("button");
+ ]
+ });
+
+ buttons = el.dialog('widget').find("button");
equal(buttons.length, 1, "correct number of buttons");
equal(buttons.attr("id"), "my-button-id", "correct id");
equal(buttons.text(), "a button", "correct label");
@@ -107,40 +109,40 @@ test("buttons - advanced", function() {
test("closeOnEscape", function() {
expect( 6 );
- el = $('<div></div>').dialog({ closeOnEscape: false });
+ var el = $('<div></div>').dialog({ closeOnEscape: false });
ok(true, 'closeOnEscape: false');
- ok(dlg().is(':visible') && !dlg().is(':hidden'), 'dialog is open before ESC');
+ ok(el.dialog('widget').is(':visible') && !el.dialog('widget').is(':hidden'), 'dialog is open before ESC');
el.simulate('keydown', { keyCode: $.ui.keyCode.ESCAPE })
.simulate('keypress', { keyCode: $.ui.keyCode.ESCAPE })
.simulate('keyup', { keyCode: $.ui.keyCode.ESCAPE });
- ok(dlg().is(':visible') && !dlg().is(':hidden'), 'dialog is open after ESC');
+ ok(el.dialog('widget').is(':visible') && !el.dialog('widget').is(':hidden'), 'dialog is open after ESC');
el.remove();
el = $('<div></div>').dialog({ closeOnEscape: true });
ok(true, 'closeOnEscape: true');
- ok(dlg().is(':visible') && !dlg().is(':hidden'), 'dialog is open before ESC');
+ ok(el.dialog('widget').is(':visible') && !el.dialog('widget').is(':hidden'), 'dialog is open before ESC');
el.simulate('keydown', { keyCode: $.ui.keyCode.ESCAPE })
.simulate('keypress', { keyCode: $.ui.keyCode.ESCAPE })
.simulate('keyup', { keyCode: $.ui.keyCode.ESCAPE });
- ok(dlg().is(':hidden') && !dlg().is(':visible'), 'dialog is closed after ESC');
+ ok(el.dialog('widget').is(':hidden') && !el.dialog('widget').is(':visible'), 'dialog is closed after ESC');
});
test("closeText", function() {
expect(3);
- el = $('<div></div>').dialog();
- equal(dlg().find('.ui-dialog-titlebar-close span').text(), 'close',
+ var el = $('<div></div>').dialog();
+ equal(el.dialog('widget').find('.ui-dialog-titlebar-close span').text(), 'close',
'default close text');
el.remove();
el = $('<div></div>').dialog({ closeText: "foo" });
- equal(dlg().find('.ui-dialog-titlebar-close span').text(), 'foo',
+ equal(el.dialog('widget').find('.ui-dialog-titlebar-close span').text(), 'foo',
'closeText on init');
el.remove();
el = $('<div></div>').dialog().dialog('option', 'closeText', 'bar');
- equal(dlg().find('.ui-dialog-titlebar-close span').text(), 'bar',
+ equal(el.dialog('widget').find('.ui-dialog-titlebar-close span').text(), 'bar',
'closeText via option method');
el.remove();
});
@@ -148,131 +150,132 @@ test("closeText", function() {
test("dialogClass", function() {
expect(4);
- el = $('<div></div>').dialog();
- equal(dlg().is(".foo"), false, 'dialogClass not specified. foo class added');
+ var el = $('<div></div>').dialog();
+ equal(el.dialog('widget').is(".foo"), false, 'dialogClass not specified. foo class added');
el.remove();
el = $('<div></div>').dialog({ dialogClass: "foo" });
- equal(dlg().is(".foo"), true, 'dialogClass in init. foo class added');
+ equal(el.dialog('widget').is(".foo"), true, 'dialogClass in init. foo class added');
el.remove();
el = $('<div></div>').dialog({ dialogClass: "foo bar" });
- equal(dlg().is(".foo"), true, 'dialogClass in init, two classes. foo class added');
- equal(dlg().is(".bar"), true, 'dialogClass in init, two classes. bar class added');
+ equal(el.dialog('widget').is(".foo"), true, 'dialogClass in init, two classes. foo class added');
+ equal(el.dialog('widget').is(".bar"), true, 'dialogClass in init, two classes. bar class added');
el.remove();
});
test("draggable", function() {
expect(4);
- el = $('<div></div>').dialog({ draggable: false });
- TestHelpers.shouldnotmove();
+ var el = $('<div></div>').dialog({ draggable: false });
+
+ TestHelpers.dialog.testDrag(el, 50, -50, 0, 0);
el.dialog('option', 'draggable', true);
- TestHelpers.shouldmove();
+ TestHelpers.dialog.testDrag(el, 50, -50, 50, -50);
el.remove();
el = $('<div></div>').dialog({ draggable: true });
- TestHelpers.shouldmove();
+ TestHelpers.dialog.testDrag(el, 50, -50, 50, -50);
el.dialog('option', 'draggable', false);
- TestHelpers.shouldnotmove();
+ TestHelpers.dialog.testDrag(el, 50, -50, 0, 0);
el.remove();
});
test("height", function() {
expect(4);
- el = $('<div></div>').dialog();
- equal(dlg().outerHeight(), 150, "default height");
+ var el = $('<div></div>').dialog();
+ equal(el.dialog('widget').outerHeight(), 150, "default height");
el.remove();
el = $('<div></div>').dialog({ height: 237 });
- equal(dlg().outerHeight(), 237, "explicit height");
+ equal(el.dialog('widget').outerHeight(), 237, "explicit height");
el.remove();
el = $('<div></div>').dialog();
el.dialog('option', 'height', 238);
- equal(dlg().outerHeight(), 238, "explicit height set after init");
+ equal(el.dialog('widget').outerHeight(), 238, "explicit height set after init");
el.remove();
el = $('<div></div>').css("padding", "20px")
.dialog({ height: 240 });
- equal(dlg().outerHeight(), 240, "explicit height with padding");
+ equal(el.dialog('widget').outerHeight(), 240, "explicit height with padding");
el.remove();
});
test("maxHeight", function() {
expect(3);
- el = $('<div></div>').dialog({ maxHeight: 200 });
- drag('.ui-resizable-s', 1000, 1000);
- equal(heightAfter, 200, "maxHeight");
+ var el = $('<div></div>').dialog({ maxHeight: 200 });
+ TestHelpers.dialog.drag(el, '.ui-resizable-s', 1000, 1000);
+ equal(el.dialog('widget').height(), 200, "maxHeight");
el.remove();
el = $('<div></div>').dialog({ maxHeight: 200 });
- drag('.ui-resizable-n', -1000, -1000);
- equal(heightAfter, 200, "maxHeight");
+ TestHelpers.dialog.drag(el, '.ui-resizable-n', -1000, -1000);
+ equal(el.dialog('widget').height(), 200, "maxHeight");
el.remove();
el = $('<div></div>').dialog({ maxHeight: 200 }).dialog('option', 'maxHeight', 300);
- drag('.ui-resizable-s', 1000, 1000);
- equal(heightAfter, 300, "maxHeight");
+ TestHelpers.dialog.drag(el, '.ui-resizable-s', 1000, 1000);
+ equal(el.dialog('widget').height(), 300, "maxHeight");
el.remove();
});
test("maxWidth", function() {
expect(3);
- el = $('<div></div>').dialog({ maxWidth: 200 });
- drag('.ui-resizable-e', 1000, 1000);
- equal(widthAfter, 200, "maxWidth");
+ var el = $('<div></div>').dialog({ maxWidth: 200 });
+ TestHelpers.dialog.drag(el, '.ui-resizable-e', 1000, 1000);
+ equal(el.dialog('widget').width(), 200, "maxWidth");
el.remove();
el = $('<div></div>').dialog({ maxWidth: 200 });
- drag('.ui-resizable-w', -1000, -1000);
- equal(widthAfter, 200, "maxWidth");
+ TestHelpers.dialog.drag(el, '.ui-resizable-w', -1000, -1000);
+ equal(el.dialog('widget').width(), 200, "maxWidth");
el.remove();
el = $('<div></div>').dialog({ maxWidth: 200 }).dialog('option', 'maxWidth', 300);
- drag('.ui-resizable-w', -1000, -1000);
- equal(widthAfter, 300, "maxWidth");
+ TestHelpers.dialog.drag(el, '.ui-resizable-w', -1000, -1000);
+ equal(el.dialog('widget').width(), 300, "maxWidth");
el.remove();
});
test("minHeight", function() {
expect(3);
- el = $('<div></div>').dialog({ minHeight: 10 });
- drag('.ui-resizable-s', -1000, -1000);
- equal(heightAfter, 10, "minHeight");
+ var el = $('<div></div>').dialog({ minHeight: 10 });
+ TestHelpers.dialog.drag(el, '.ui-resizable-s', -1000, -1000);
+ equal(el.dialog('widget').height(), 10, "minHeight");
el.remove();
el = $('<div></div>').dialog({ minHeight: 10 });
- drag('.ui-resizable-n', 1000, 1000);
- equal(heightAfter, 10, "minHeight");
+ TestHelpers.dialog.drag(el, '.ui-resizable-n', 1000, 1000);
+ equal(el.dialog('widget').height(), 10, "minHeight");
el.remove();
el = $('<div></div>').dialog({ minHeight: 10 }).dialog('option', 'minHeight', 30);
- drag('.ui-resizable-n', 1000, 1000);
- equal(heightAfter, 30, "minHeight");
+ TestHelpers.dialog.drag(el, '.ui-resizable-n', 1000, 1000);
+ equal(el.dialog('widget').height(), 30, "minHeight");
el.remove();
});
test("minWidth", function() {
expect(3);
- el = $('<div></div>').dialog({ minWidth: 10 });
- drag('.ui-resizable-e', -1000, -1000);
- equal(widthAfter, 10, "minWidth");
+ var el = $('<div></div>').dialog({ minWidth: 10 });
+ TestHelpers.dialog.drag(el, '.ui-resizable-e', -1000, -1000);
+ equal(el.dialog('widget').width(), 10, "minWidth");
el.remove();
el = $('<div></div>').dialog({ minWidth: 10 });
- drag('.ui-resizable-w', 1000, 1000);
- equal(widthAfter, 10, "minWidth");
+ TestHelpers.dialog.drag(el, '.ui-resizable-w', 1000, 1000);
+ equal(el.dialog('widget').width(), 10, "minWidth");
el.remove();
el = $('<div></div>').dialog({ minWidth: 30 }).dialog('option', 'minWidth', 30);
- drag('.ui-resizable-w', 1000, 1000);
- equal(widthAfter, 30, "minWidth");
+ TestHelpers.dialog.drag(el, '.ui-resizable-w', 1000, 1000);
+ equal(el.dialog('widget').width(), 30, "minWidth");
el.remove();
});
@@ -394,16 +397,16 @@ test("position, at another element", function() {
test("resizable", function() {
expect(4);
- el = $('<div></div>').dialog();
- TestHelpers.shouldresize("[default]");
+ var el = $('<div></div>').dialog();
+ TestHelpers.dialog.shouldResize(el, 50, 50, "[default]");
el.dialog('option', 'resizable', false);
- TestHelpers.shouldnotresize('disabled after init');
+ TestHelpers.dialog.shouldResize(el, 0, 0, 'disabled after init');
el.remove();
el = $('<div></div>').dialog({ resizable: false });
- TestHelpers.shouldnotresize("disabled in init options");
+ TestHelpers.dialog.shouldResize(el, 0, 0, "disabled in init options");
el.dialog('option', 'resizable', true);
- TestHelpers.shouldresize('enabled after init');
+ TestHelpers.dialog.shouldResize(el, 50, 50, 'enabled after init');
el.remove();
});
@@ -411,13 +414,13 @@ test("title", function() {
expect(9);
function titleText() {
- return dlg().find(".ui-dialog-title").html();
+ return el.dialog('widget').find(".ui-dialog-title").html();
}
- el = $('<div></div>').dialog();
+ var el = $('<div></div>').dialog();
// some browsers return a non-breaking space and some return "&nbsp;"
// so we get the text to normalize to the actual non-breaking space
- equal(dlg().find(".ui-dialog-title").text(), " ", "[default]");
+ equal(el.dialog('widget').find(".ui-dialog-title").text(), " ", "[default]");
equal(el.dialog("option", "title"), "", "option not changed");
el.remove();
@@ -444,14 +447,14 @@ test("title", function() {
test("width", function() {
expect(3);
- el = $('<div></div>').dialog();
- equal(dlg().width(), 300, "default width");
+ var el = $('<div></div>').dialog();
+ equal(el.dialog('widget').width(), 300, "default width");
el.remove();
el = $('<div></div>').dialog({width: 437 });
- equal(dlg().width(), 437, "explicit width");
+ equal(el.dialog('widget').width(), 437, "explicit width");
el.dialog('option', 'width', 438);
- equal(dlg().width(), 438, 'explicit width after init');
+ equal(el.dialog('widget').width(), 438, 'explicit width after init');
el.remove();
});
diff --git a/tests/unit/dialog/dialog_test_helpers.js b/tests/unit/dialog/dialog_test_helpers.js
new file mode 100644
index 000000000..bbf43f48f
--- /dev/null
+++ b/tests/unit/dialog/dialog_test_helpers.js
@@ -0,0 +1,45 @@
+TestHelpers.dialog = {
+ drag: function(el, handle, dx, dy) {
+ var d = el.dialog('widget');
+ //this mouseover is to work around a limitation in resizable
+ //TODO: fix resizable so handle doesn't require mouseover in order to be used
+ $(handle, d).simulate("mouseover");
+ $(handle, d).simulate("drag", {
+ dx: dx || 0,
+ dy: dy || 0
+ });
+ },
+ testDrag: function(el, dx, dy, expectedDX, expectedDY, msg) {
+ var actual, expected, offsetAfter,
+ d = el.dialog('widget'),
+ handle = $(".ui-dialog-titlebar", d),
+ offsetBefore = d.offset();
+
+ TestHelpers.dialog.drag(el, handle, dx, dy);
+
+ offsetAfter = d.offset();
+
+ msg = msg ? msg + "." : "";
+
+ actual = { left: Math.round(offsetAfter.left), top: Math.round(offsetAfter.top) },
+ expected = { left: Math.round(offsetBefore.left + expectedDX), top: Math.round(offsetBefore.top + expectedDY) };
+ deepEqual(actual, expected, 'dragged[' + expectedDX + ', ' + expectedDY + '] ' + msg);
+ },
+ shouldResize: function(el, dw, dh, msg) {
+ var heightAfter, widthAfter, actual, expected,
+ d = el.dialog('widget'),
+ handle = $(".ui-resizable-se", d),
+ heightBefore = d.height(),
+ widthBefore = d.width();
+
+ TestHelpers.dialog.drag(el, handle, 50, 50);
+
+ heightAfter = d.height();
+ widthAfter = d.width();
+
+ msg = msg ? msg + "." : "";
+ actual = { width: widthAfter, height: heightAfter },
+ expected = { width: widthBefore + dw, height: heightBefore + dh };
+ deepEqual(actual, expected, 'resized[' + 50 + ', ' + 50 + '] ' + msg);
+ }
+}; \ No newline at end of file
diff --git a/tests/unit/dialog/dialog_tickets.js b/tests/unit/dialog/dialog_tickets.js
index 2b0214718..3055c5fc1 100644
--- a/tests/unit/dialog/dialog_tickets.js
+++ b/tests/unit/dialog/dialog_tickets.js
@@ -36,21 +36,21 @@ asyncTest( "#3123: Prevent tabbing out of modal dialogs", function() {
test("#4826: setting resizable false toggles resizable on dialog", function() {
expect(6);
- var i;
+ var i,
+ el = $('<div></div>').dialog({ resizable: false });
- el = $('<div></div>').dialog({ resizable: false });
- TestHelpers.shouldnotresize("[default]");
+ TestHelpers.dialog.shouldResize(el, 0, 0, "[default]");
for (i=0; i<2; i++) {
el.dialog('close').dialog('open');
- TestHelpers.shouldnotresize('initialized with resizable false toggle ('+ (i+1) +')');
+ TestHelpers.dialog.shouldResize(el, 0, 0, 'initialized with resizable false toggle ('+ (i+1) +')');
}
el.remove();
el = $('<div></div>').dialog({ resizable: true });
- TestHelpers.shouldresize("[default]");
+ TestHelpers.dialog.shouldResize(el, 50, 50, "[default]");
for (i=0; i<2; i++) {
el.dialog('close').dialog('option', 'resizable', false).dialog('open');
- TestHelpers.shouldnotresize('set option resizable false toggle ('+ (i+1) +')');
+ TestHelpers.dialog.shouldResize(el, 0, 0, 'set option resizable false toggle ('+ (i+1) +')');
}
el.remove();
@@ -59,11 +59,11 @@ test("#4826: setting resizable false toggles resizable on dialog", function() {
test("#5184: isOpen in dialogclose event is true", function() {
expect( 3 );
- el = $( "<div></div>" ).dialog({
- close: function() {
- ok( !el.dialog("isOpen"), "dialog is not open during close" );
- }
- });
+ var el = $( "<div></div>" ).dialog({
+ close: function() {
+ ok( !el.dialog("isOpen"), "dialog is not open during close" );
+ }
+ });
ok( el.dialog("isOpen"), "dialog is open after init" );
el.dialog( "close" );
ok( !el.dialog("isOpen"), "dialog is not open after close" );
@@ -72,7 +72,7 @@ test("#5184: isOpen in dialogclose event is true", function() {
test("#5531: dialog width should be at least minWidth on creation", function () {
expect( 4 );
- el = $('<div></div>').dialog({
+ var el = $('<div></div>').dialog({
width: 200,
minWidth: 300
});
@@ -95,7 +95,7 @@ test("#5531: dialog width should be at least minWidth on creation", function ()
test("#6137: dialog('open') causes form elements to reset on IE7", function() {
expect(2);
- d1 = $('<form><input type="radio" name="radio" id="a" value="a" checked="checked"></input>' +
+ var d1 = $('<form><input type="radio" name="radio" id="a" value="a" checked="checked"></input>' +
'<input type="radio" name="radio" id="b" value="b">b</input></form>').appendTo( "body" ).dialog({autoOpen: false});
d1.find('#b').prop( "checked", true );
@@ -109,8 +109,9 @@ test("#6137: dialog('open') causes form elements to reset on IE7", function() {
test("#6645: Missing element not found check in overlay", function(){
expect(2);
- d1 = $('<div title="dialog 1">Dialog 1</div>').dialog({modal: true});
- d2 = $('<div title="dialog 2">Dialog 2</div>').dialog({modal: true, close: function(){ d2.remove(); }});
+ var d1 = $('<div title="dialog 1">Dialog 1</div>').dialog({modal: true}),
+ d2 = $('<div title="dialog 2">Dialog 2</div>').dialog({modal: true, close: function(){ d2.remove(); }});
+
equal($.ui.dialog.overlay.instances.length, 2, 'two overlays created');
d2.dialog('close');
equal($.ui.dialog.overlay.instances.length, 1, 'one overlay remains after closing the 2nd overlay');
@@ -119,8 +120,8 @@ test("#6645: Missing element not found check in overlay", function(){
test("#4980: Destroy should place element back in original DOM position", function(){
expect( 2 );
- container = $('<div id="container"><div id="modal">Content</div></div>');
- modal = container.find('#modal');
+ var container = $('<div id="container"><div id="modal">Content</div></div>'),
+ modal = container.find('#modal');
modal.dialog();
ok(!$.contains(container[0], modal[0]), 'dialog should move modal element to outside container element');
modal.dialog('destroy');
diff --git a/tests/unit/draggable/draggable.html b/tests/unit/draggable/draggable.html
index 160467e89..dce226a9a 100644
--- a/tests/unit/draggable/draggable.html
+++ b/tests/unit/draggable/draggable.html
@@ -26,6 +26,7 @@
<script src="draggable_events.js"></script>
<script src="draggable_methods.js"></script>
<script src="draggable_options.js"></script>
+ <script src="draggable_test_helpers.js"></script>
<script src="../swarminject.js"></script>
</head>
diff --git a/tests/unit/draggable/draggable_core.js b/tests/unit/draggable/draggable_core.js
index 3ec3fb8dd..0e9d04be1 100644
--- a/tests/unit/draggable/draggable_core.js
+++ b/tests/unit/draggable/draggable_core.js
@@ -2,70 +2,6 @@
* draggable_core.js
*/
-TestHelpers.draggable = {};
-
-// todo: remove these hacks
-TestHelpers.draggable.unreliableOffset = $.ui.ie && ( !document.documentMode || document.documentMode < 8 ) ? 2 : 0;
-
-TestHelpers.draggable.drag = function(handle, dx, dy) {
- $(handle).simulate("drag", {
- dx: dx || 0,
- dy: dy || 0
- });
- return el.offset();
-};
-
-TestHelpers.draggable.testDrag = function(el, handle, dx, dy, expectedDX, expectedDY, msg) {
-
- var offsetBefore = el.offset(),
- offsetAfter = TestHelpers.draggable.drag(handle, dx, dy),
- actual = { left: offsetAfter.left, top: offsetAfter.top },
- expected = { left: offsetBefore.left + expectedDX, top: offsetBefore.top + expectedDY };
-
- msg = msg ? msg + "." : "";
- deepEqual(actual, expected, 'dragged[' + dx + ', ' + dy + '] ' + msg);
-};
-
-TestHelpers.draggable.shouldMove = function(el, why) {
- TestHelpers.draggable.testDrag(el, el, 50, 50, 50, 50, why);
-};
-
-TestHelpers.draggable.shouldNotMove = function(el, why) {
- TestHelpers.draggable.testDrag(el, el, 50, 50, 0, 0, why);
-};
-
-TestHelpers.draggable.testScroll = function(el, position ) {
- var oldPosition = $("#main").css('position');
- $("#main").css('position', position);
- TestHelpers.draggable.shouldMove(el, position+' parent');
- $("#main").css('position', oldPosition);
-};
-
-TestHelpers.draggable.restoreScroll = function( what ) {
- if( what ) {
- $(document).scrollTop(0); $(document).scrollLeft(0);
- } else {
- $("#main").scrollTop(0); $("#main").scrollLeft(0);
- }
-};
-
-TestHelpers.draggable.setScroll = function( what ) {
- if(what) {
- // todo: currently, the draggable interaction doesn't properly account for scrolled pages,
- // uncomment the line below to make the tests fail that should when the page is scrolled
- // $(document).scrollTop(100); $(document).scrollLeft(100);
- } else {
- $("#main").scrollTop(100); $("#main").scrollLeft(100);
- }
-};
-
-TestHelpers.draggable.border = function(el, side) {
- return parseInt(el.css('border-' + side + '-width'), 10) || 0;
-};
-TestHelpers.draggable.margin = function(el, side) {
- return parseInt(el.css('margin-' + side), 10) || 0;
-};
-
(function($) {
module("draggable");
@@ -79,12 +15,15 @@ test("element types", function() {
expect( typeNames.length );
$.each(typeNames, function(i) {
- var offsetBefore, offsetAfter, typeName = typeNames[i];
- el = $(document.createElement(typeName)).appendTo('#main');
+ var offsetBefore, offsetAfter,
+ typeName = typeNames[i],
+ el = $(document.createElement(typeName)).appendTo('#main');
+
(typeName === 'table' && el.append("<tr><td>content</td></tr>"));
el.draggable({ cancel: '' });
offsetBefore = el.offset();
- offsetAfter =TestHelpers.draggable.drag(el, 50, 50);
+ TestHelpers.draggable.drag(el, 50, 50);
+ offsetAfter = el.offset();
//there are some rounding errors in FF and Chrome, so we can't say equal, we have to settle for close enough
ok(offsetAfter.left - offsetBefore.left - 50 < 1 && offsetAfter.top - offsetBefore.top - 50 < 1, 'dragged[50, 50] ' + "&lt;" + typeName + "&gt;");
el.draggable("destroy");
@@ -94,13 +33,13 @@ test("element types", function() {
test("No options, relative", function() {
expect( 1 );
- el = $("#draggable1").draggable();
+ var el = $("#draggable1").draggable();
TestHelpers.draggable.shouldMove(el);
});
test("No options, absolute", function() {
expect( 1 );
- el = $("#draggable2").draggable();
+ var el = $("#draggable2").draggable();
TestHelpers.draggable.shouldMove(el);
});
diff --git a/tests/unit/draggable/draggable_events.js b/tests/unit/draggable/draggable_events.js
index 65e8097a7..6b1136cb0 100644
--- a/tests/unit/draggable/draggable_events.js
+++ b/tests/unit/draggable/draggable_events.js
@@ -9,12 +9,14 @@ test("callbacks occurrence count", function() {
expect(3);
- var start = 0, stop = 0, dragc = 0;
- el = $("#draggable2").draggable({
- start: function() { start++; },
- drag: function() { dragc++; },
- stop: function() { stop++; }
- });
+ var start = 0,
+ stop = 0,
+ dragc = 0,
+ el = $("#draggable2").draggable({
+ start: function() { start++; },
+ drag: function() { dragc++; },
+ stop: function() { stop++; }
+ });
TestHelpers.draggable.drag(el, 10, 10);
@@ -28,12 +30,14 @@ test("stopping the start callback", function() {
expect(3);
- var start = 0, stop = 0, dragc = 0;
- el = $("#draggable2").draggable({
- start: function() { start++; return false; },
- drag: function() { dragc++; },
- stop: function() { stop++; }
- });
+ var start = 0,
+ stop = 0,
+ dragc = 0,
+ el = $("#draggable2").draggable({
+ start: function() { start++; return false; },
+ drag: function() { dragc++; },
+ stop: function() { stop++; }
+ });
TestHelpers.draggable.drag(el, 10, 10);
@@ -47,12 +51,14 @@ test("stopping the drag callback", function() {
expect(3);
- var start = 0, stop = 0, dragc = 0;
- el = $("#draggable2").draggable({
- start: function() { start++;},
- drag: function() { dragc++; return false; },
- stop: function() { stop++; }
- });
+ var start = 0,
+ stop = 0,
+ dragc = 0,
+ el = $("#draggable2").draggable({
+ start: function() { start++;},
+ drag: function() { dragc++; return false; },
+ stop: function() { stop++; }
+ });
TestHelpers.draggable.drag(el, 10, 10);
@@ -66,7 +72,7 @@ test("stopping the stop callback", function() {
expect(1);
- el = $("#draggable2").draggable({
+ var el = $("#draggable2").draggable({
helper: 'clone',
stop: function() { return false; }
});
diff --git a/tests/unit/draggable/draggable_methods.js b/tests/unit/draggable/draggable_methods.js
index b4b7888b6..9ea353ca6 100644
--- a/tests/unit/draggable/draggable_methods.js
+++ b/tests/unit/draggable/draggable_methods.js
@@ -42,6 +42,9 @@ test("destroy", function() {
test("enable", function() {
expect(7);
+
+ var expected, actual, el;
+
el = $("#draggable2").draggable({ disabled: true });
TestHelpers.draggable.shouldNotMove(el, '.draggable({ disabled: true })');
@@ -57,13 +60,16 @@ test("enable", function() {
equal(el.draggable("option", "disabled"), false, "disabled option setter");
TestHelpers.draggable.shouldMove(el, '.draggable("option", "disabled", false)');
- var expected = $('<div></div>').draggable(),
- actual = expected.draggable('enable');
+ expected = $('<div></div>').draggable(),
+ actual = expected.draggable('enable');
equal(actual, expected, 'enable is chainable');
});
test("disable", function() {
expect(7);
+
+ var expected, actual, el;
+
el = $("#draggable2").draggable({ disabled: false });
TestHelpers.draggable.shouldMove(el, '.draggable({ disabled: false })');
@@ -80,8 +86,8 @@ test("disable", function() {
equal(el.draggable("option", "disabled"), true, "disabled option setter");
TestHelpers.draggable.shouldNotMove(el, '.draggable("option", "disabled", true)');
- var expected = $('<div></div>').draggable(),
- actual = expected.draggable('disable');
+ expected = $('<div></div>').draggable(),
+ actual = expected.draggable('disable');
equal(actual, expected, 'disable is chainable');
});
diff --git a/tests/unit/draggable/draggable_options.js b/tests/unit/draggable/draggable_options.js
index 4834dd9c4..3f4592d31 100644
--- a/tests/unit/draggable/draggable_options.js
+++ b/tests/unit/draggable/draggable_options.js
@@ -7,7 +7,7 @@ module("draggable: options");
test("{ addClasses: true }, default", function() {
expect( 1 );
- el = $("<div></div>").draggable({ addClasses: true });
+ var el = $("<div></div>").draggable({ addClasses: true });
ok(el.is(".ui-draggable"), "'ui-draggable' class added");
el.draggable("destroy");
@@ -15,7 +15,7 @@ test("{ addClasses: true }, default", function() {
test("{ addClasses: false }", function() {
expect( 1 );
- el = $("<div></div>").draggable({ addClasses: false });
+ var el = $("<div></div>").draggable({ addClasses: false });
ok(!el.is(".ui-draggable"), "'ui-draggable' class not added");
el.draggable("destroy");
@@ -23,7 +23,7 @@ test("{ addClasses: false }", function() {
test("{ appendTo: 'parent' }, default", function() {
expect( 2 );
- el = $("#draggable2").draggable({ appendTo: 'parent' });
+ var el = $("#draggable2").draggable({ appendTo: 'parent' });
TestHelpers.draggable.shouldMove(el);
el = $("#draggable1").draggable({ appendTo: 'parent' });
@@ -33,7 +33,7 @@ test("{ appendTo: 'parent' }, default", function() {
test("{ appendTo: Element }", function() {
expect( 2 );
- el = $("#draggable2").draggable({ appendTo: $("#draggable2").parent()[0] });
+ var el = $("#draggable2").draggable({ appendTo: $("#draggable2").parent()[0] });
TestHelpers.draggable.shouldMove(el);
el = $("#draggable1").draggable({ appendTo: $("#draggable2").parent()[0] });
@@ -42,7 +42,7 @@ test("{ appendTo: Element }", function() {
test("{ appendTo: Selector }", function() {
expect( 2 );
- el = $("#draggable2").draggable({ appendTo: "#main" });
+ var el = $("#draggable2").draggable({ appendTo: "#main" });
TestHelpers.draggable.shouldMove(el);
el = $("#draggable1").draggable({ appendTo: "#main" });
@@ -51,31 +51,32 @@ test("{ appendTo: Selector }", function() {
test("{ axis: false }, default", function() {
expect( 1 );
- el = $("#draggable2").draggable({ axis: false });
+ var el = $("#draggable2").draggable({ axis: false });
TestHelpers.draggable.shouldMove(el);
});
test("{ axis: 'x' }", function() {
expect( 1 );
- el = $("#draggable2").draggable({ axis: "x" });
+ var el = $("#draggable2").draggable({ axis: "x" });
TestHelpers.draggable.testDrag(el, el, 50, 50, 50, 0);
});
test("{ axis: 'y' }", function() {
expect( 1 );
- el = $("#draggable2").draggable({ axis: "y" });
+ var el = $("#draggable2").draggable({ axis: "y" });
TestHelpers.draggable.testDrag(el, el, 50, 50, 0, 50);
});
test("{ axis: ? }, unexpected", function() {
- var unexpected = {
- "true": true,
- "{}": {},
- "[]": [],
- "null": null,
- "undefined": undefined,
- "function() {}": function() {}
- };
+ var el,
+ unexpected = {
+ "true": true,
+ "{}": {},
+ "[]": [],
+ "null": null,
+ "undefined": undefined,
+ "function() {}": function() {}
+ };
expect( 6 );
@@ -91,7 +92,7 @@ test("{ cancel: 'input,textarea,button,select,option' }, default", function() {
$('<div id="draggable-option-cancel-default"><input type="text"></div>').appendTo('#main');
- el = $("#draggable-option-cancel-default").draggable({ cancel: "input,textarea,button,select,option" });
+ var el = $("#draggable-option-cancel-default").draggable({ cancel: "input,textarea,button,select,option" });
TestHelpers.draggable.shouldMove(el);
el.draggable("destroy");
@@ -104,7 +105,7 @@ test("{ cancel: 'input,textarea,button,select,option' }, default", function() {
test("{ cancel: 'span' }", function() {
expect( 2 );
- el = $("#draggable2").draggable();
+ var el = $("#draggable2").draggable();
TestHelpers.draggable.testDrag(el, "#draggable2 span", 50, 50, 50, 50);
el.draggable("destroy");
@@ -114,17 +115,18 @@ test("{ cancel: 'span' }", function() {
});
test("{ cancel: ? }, unexpected", function() {
- var unexpected = {
- "true": true,
- "false": false,
- "{}": {},
- "[]": [],
- "null": null,
- "undefined": undefined,
- "function() {return '';}": function() {return '';},
- "function() {return true;}": function() {return true;},
- "function() {return false;}": function() {return false;}
- };
+ var el,
+ unexpected = {
+ "true": true,
+ "false": false,
+ "{}": {},
+ "[]": [],
+ "null": null,
+ "undefined": undefined,
+ "function() {return '';}": function() {return '';},
+ "function() {return true;}": function() {return true;},
+ "function() {return false;}": function() {return false;}
+ };
expect( 9 );
@@ -152,28 +154,32 @@ test("{ containment: Element }", function() {
test("{ containment: 'parent' }, relative", function() {
expect( 1 );
- el = $("#draggable1").draggable({ containment: 'parent' });
- var p = el.parent(),
+ var offsetAfter,
+ el = $("#draggable1").draggable({ containment: 'parent' }),
+ p = el.parent(),
po = p.offset(),
expected = {
left: po.left + TestHelpers.draggable.border(p, 'left') + TestHelpers.draggable.margin(el, 'left'),
top: po.top + TestHelpers.draggable.border(p, 'top') + TestHelpers.draggable.margin(el, 'top')
- },
- offsetAfter = TestHelpers.draggable.drag(el, -100, -100);
+ };
+ TestHelpers.draggable.drag(el, -100, -100);
+ offsetAfter = el.offset();
deepEqual(offsetAfter, expected, 'compare offset to parent');
});
test("{ containment: 'parent' }, absolute", function() {
expect( 1 );
- el = $("#draggable2").draggable({ containment: 'parent' });
- var p = el.parent(),
+ var offsetAfter,
+ el = $("#draggable2").draggable({ containment: 'parent' }),
+ p = el.parent(),
po = p.offset(),
expected = {
left: po.left + TestHelpers.draggable.border(p, 'left') + TestHelpers.draggable.margin(el, 'left'),
top: po.top + TestHelpers.draggable.border(p, 'top') + TestHelpers.draggable.margin(el, 'top')
- },
- offsetAfter = TestHelpers.draggable.drag(el, -100, -100);
+ };
+ TestHelpers.draggable.drag(el, -100, -100);
+ offsetAfter = el.offset();
deepEqual(offsetAfter, expected, 'compare offset to parent');
});
@@ -210,7 +216,7 @@ test("{ cursor: 'auto' }, default", function() {
var expected = "auto", actual, before, after;
- el = $("#draggable2").draggable({
+ $("#draggable2").draggable({
cursor: expected,
start: function() {
actual = getCursor();
@@ -234,7 +240,7 @@ test("{ cursor: 'move' }", function() {
var expected = "move", actual, before, after;
- el = $("#draggable2").draggable({
+ $("#draggable2").draggable({
cursor: expected,
start: function() {
actual = getCursor();
@@ -266,14 +272,14 @@ test("{ cursorAt: { left: -5, top: -5 } }", function() {
cursorAtX = -5, cursorAtY = -5;
$.each(['relative', 'absolute'], function(i, position) {
- var before, pos, expected;
- el = $('#draggable' + (i + 1)).draggable({
- cursorAt: { left: cursorAtX, top: cursorAtY },
- drag: function(event, ui) {
- equal(ui.offset.left, expected.left, position + ' left');
- equal(ui.offset.top, expected.top, position + ' top');
- }
- });
+ var before, pos, expected,
+ el = $('#draggable' + (i + 1)).draggable({
+ cursorAt: { left: cursorAtX, top: cursorAtY },
+ drag: function(event, ui) {
+ equal(ui.offset.left, expected.left, position + ' left');
+ equal(ui.offset.top, expected.top, position + ' top');
+ }
+ });
before = el.offset();
pos = {
@@ -285,6 +291,7 @@ test("{ cursorAt: { left: -5, top: -5 } }", function() {
top: before.top + offsetY - cursorAtY + deltaY - TestHelpers.draggable.unreliableOffset
};
+ // todo: replace this with simulated drag event
el.simulate("mousedown", pos);
pos.clientX += deltaX;
pos.clientY += deltaY;
@@ -301,14 +308,14 @@ test("{ cursorAt: { right: 10, bottom: 20 } }", function() {
cursorAtX = 10, cursorAtY = 20;
$.each(['relative', 'absolute'], function(i, position) {
- var before, pos, expected;
- el = $('#draggable' + (i + 1)).draggable({
- cursorAt: { right: cursorAtX, bottom: cursorAtY },
- drag: function(event, ui) {
- equal(ui.offset.left, expected.left, position + ' left');
- equal(ui.offset.top, expected.top, position + ' top');
- }
- });
+ var before, pos, expected,
+ el = $('#draggable' + (i + 1)).draggable({
+ cursorAt: { right: cursorAtX, bottom: cursorAtY },
+ drag: function(event, ui) {
+ equal(ui.offset.left, expected.left, position + ' left');
+ equal(ui.offset.top, expected.top, position + ' top');
+ }
+ });
before = el.offset();
pos = {
clientX: before.left + offsetX,
@@ -319,6 +326,7 @@ test("{ cursorAt: { right: 10, bottom: 20 } }", function() {
top: before.top + offsetY - el.height() + cursorAtY + deltaY - TestHelpers.draggable.unreliableOffset
};
+ // todo: replace this with simulated drag event
el.simulate("mousedown", pos);
pos.clientX += deltaX;
pos.clientY += deltaY;
@@ -335,14 +343,15 @@ test("{ cursorAt: [10, 20] }", function() {
cursorAtX = 10, cursorAtY = 20;
$.each(['relative', 'absolute'], function(i, position) {
- var before, pos, expected;
- el = $('#draggable' + (i + 1)).draggable({
- cursorAt: { left: cursorAtX, top: cursorAtY },
- drag: function(event, ui) {
- equal(ui.offset.left, expected.left, position + ' left');
- equal(ui.offset.top, expected.top, position + ' top');
- }
- });
+ var before, pos, expected,
+ el = $('#draggable' + (i + 1)).draggable({
+ cursorAt: { left: cursorAtX, top: cursorAtY },
+ drag: function(event, ui) {
+ equal(ui.offset.left, expected.left, position + ' left');
+ equal(ui.offset.top, expected.top, position + ' top');
+ }
+ });
+
before = el.offset();
pos = {
clientX: before.left + offsetX,
@@ -353,6 +362,7 @@ test("{ cursorAt: [10, 20] }", function() {
top: before.top + offsetY - cursorAtY + deltaY - TestHelpers.draggable.unreliableOffset
};
+ // todo: replace this with simulated drag event
el.simulate("mousedown", pos);
pos.clientX += deltaX;
pos.clientY += deltaY;
@@ -369,14 +379,15 @@ test("{ cursorAt: '20, 40' }", function() {
cursorAtX = 20, cursorAtY = 40;
$.each(['relative', 'absolute'], function(i, position) {
- var before, pos, expected;
- el = $('#draggable' + (i + 1)).draggable({
- cursorAt: { left: cursorAtX, top: cursorAtY },
- drag: function(event, ui) {
- equal(ui.offset.left, expected.left, position + ' left');
- equal(ui.offset.top, expected.top, position + ' top');
- }
- });
+ var before, pos, expected,
+ el = $('#draggable' + (i + 1)).draggable({
+ cursorAt: { left: cursorAtX, top: cursorAtY },
+ drag: function(event, ui) {
+ equal(ui.offset.left, expected.left, position + ' left');
+ equal(ui.offset.top, expected.top, position + ' top');
+ }
+ });
+
before = el.offset();
pos = {
clientX: before.left + offsetX,
@@ -387,6 +398,7 @@ test("{ cursorAt: '20, 40' }", function() {
top: before.top + offsetY - cursorAtY + deltaY - TestHelpers.draggable.unreliableOffset
};
+ // todo: replace this with simulated drag event
el.simulate("mousedown", pos);
pos.clientX += deltaX;
pos.clientY += deltaY;
@@ -398,7 +410,7 @@ test("{ cursorAt: '20, 40' }", function() {
test("{ distance: 10 }", function() {
expect( 3 );
- el = $("#draggable2").draggable({ distance: 10 });
+ var el = $("#draggable2").draggable({ distance: 10 });
TestHelpers.draggable.testDrag(el, el, -9, -9, 0, 0, 'distance not met');
TestHelpers.draggable.testDrag(el, el, -10, -10, -10, -10, 'distance met');
@@ -410,7 +422,7 @@ test("{ distance: 10 }", function() {
test("{ grid: [50, 50] }, relative", function() {
expect( 2 );
- el = $("#draggable1").draggable({ grid: [50, 50] });
+ var el = $("#draggable1").draggable({ grid: [50, 50] });
TestHelpers.draggable.testDrag(el, el, 24, 24, 0, 0);
TestHelpers.draggable.testDrag(el, el, 26, 25, 50, 50);
});
@@ -418,7 +430,7 @@ test("{ grid: [50, 50] }, relative", function() {
test("{ grid: [50, 50] }, absolute", function() {
expect( 2 );
- el = $("#draggable2").draggable({ grid: [50, 50] });
+ var el = $("#draggable2").draggable({ grid: [50, 50] });
TestHelpers.draggable.testDrag(el, el, 24, 24, 0, 0);
TestHelpers.draggable.testDrag(el, el, 26, 25, 50, 50);
});
@@ -426,7 +438,7 @@ test("{ grid: [50, 50] }, absolute", function() {
test("{ handle: 'span' }", function() {
expect( 2 );
- el = $("#draggable2").draggable({ handle: 'span' });
+ var el = $("#draggable2").draggable({ handle: 'span' });
TestHelpers.draggable.testDrag(el, "#draggable2 span", 50, 50, 50, 50, "drag span");
TestHelpers.draggable.shouldNotMove(el, "drag element");
@@ -435,21 +447,21 @@ test("{ handle: 'span' }", function() {
test("{ helper: 'clone' }, relative", function() {
expect( 1 );
- el = $("#draggable1").draggable({ helper: "clone" });
+ var el = $("#draggable1").draggable({ helper: "clone" });
TestHelpers.draggable.shouldNotMove(el);
});
test("{ helper: 'clone' }, absolute", function() {
expect( 1 );
- el = $("#draggable2").draggable({ helper: "clone" });
+ var el = $("#draggable2").draggable({ helper: "clone" });
TestHelpers.draggable.shouldNotMove(el);
});
test("{ helper: 'original' }, relative, with scroll offset on parent", function() {
expect( 3 );
- el = $("#draggable1").draggable({ helper: "original" });
+ var el = $("#draggable1").draggable({ helper: "original" });
TestHelpers.draggable.setScroll();
TestHelpers.draggable.testScroll(el, 'relative');
@@ -467,7 +479,7 @@ test("{ helper: 'original' }, relative, with scroll offset on parent", function(
test("{ helper: 'original' }, relative, with scroll offset on root", function() {
expect( 3 );
- el = $("#draggable1").draggable({ helper: "original" });
+ var el = $("#draggable1").draggable({ helper: "original" });
TestHelpers.draggable.setScroll('root');
TestHelpers.draggable.testScroll(el, 'relative');
@@ -486,7 +498,7 @@ test("{ helper: 'original' }, relative, with scroll offset on root and parent",
expect(3);
- el = $("#draggable1").draggable({ helper: "original" });
+ var el = $("#draggable1").draggable({ helper: "original" });
TestHelpers.draggable.setScroll();
TestHelpers.draggable.setScroll('root');
@@ -509,7 +521,7 @@ test("{ helper: 'original' }, absolute, with scroll offset on parent", function(
expect(3);
- el = $("#draggable1").css({ position: 'absolute', top: 0, left: 0 }).draggable({ helper: "original" });
+ var el = $("#draggable1").css({ position: 'absolute', top: 0, left: 0 }).draggable({ helper: "original" });
TestHelpers.draggable.setScroll();
TestHelpers.draggable.testScroll(el, 'relative');
@@ -528,7 +540,7 @@ test("{ helper: 'original' }, absolute, with scroll offset on root", function()
expect(3);
- el = $("#draggable1").css({ position: 'absolute', top: 0, left: 0 }).draggable({ helper: "original" });
+ var el = $("#draggable1").css({ position: 'absolute', top: 0, left: 0 }).draggable({ helper: "original" });
TestHelpers.draggable.setScroll('root');
TestHelpers.draggable.testScroll(el, 'relative');
@@ -547,7 +559,7 @@ test("{ helper: 'original' }, absolute, with scroll offset on root and parent",
expect(3);
- el = $("#draggable1").css({ position: 'absolute', top: 0, left: 0 }).draggable({ helper: "original" });
+ var el = $("#draggable1").css({ position: 'absolute', top: 0, left: 0 }).draggable({ helper: "original" });
TestHelpers.draggable.setScroll();
TestHelpers.draggable.setScroll('root');
@@ -570,7 +582,7 @@ test("{ helper: 'original' }, fixed, with scroll offset on parent", function() {
expect(3);
- el = $("#draggable1").css({ position: 'fixed', top: 0, left: 0 }).draggable({ helper: "original" });
+ var el = $("#draggable1").css({ position: 'fixed', top: 0, left: 0 }).draggable({ helper: "original" });
TestHelpers.draggable.setScroll();
TestHelpers.draggable.testScroll(el, 'relative');
@@ -589,7 +601,7 @@ test("{ helper: 'original' }, fixed, with scroll offset on root", function() {
expect(3);
- el = $("#draggable1").css({ position: 'fixed', top: 0, left: 0 }).draggable({ helper: "original" });
+ var el = $("#draggable1").css({ position: 'fixed', top: 0, left: 0 }).draggable({ helper: "original" });
TestHelpers.draggable.setScroll('root');
TestHelpers.draggable.testScroll(el, 'relative');
@@ -607,7 +619,7 @@ test("{ helper: 'original' }, fixed, with scroll offset on root and parent", fun
expect(3);
- el = $("#draggable1").css({ position: 'fixed', top: 0, left: 0 }).draggable({ helper: "original" });
+ var el = $("#draggable1").css({ position: 'fixed', top: 0, left: 0 }).draggable({ helper: "original" });
TestHelpers.draggable.setScroll();
TestHelpers.draggable.setScroll('root');
@@ -631,11 +643,10 @@ test("{ helper: 'clone' }, absolute", function() {
expect(1);
var helperOffset = null,
- origOffset = $("#draggable1").offset();
-
- el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) {
- helperOffset = ui.helper.offset();
- } });
+ origOffset = $("#draggable1").offset(),
+ el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) {
+ helperOffset = ui.helper.offset();
+ } });
TestHelpers.draggable.drag(el, 1, 1);
deepEqual({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[1, 1] ');
@@ -648,11 +659,10 @@ test("{ helper: 'clone' }, absolute with scroll offset on parent", function() {
TestHelpers.draggable.setScroll();
var helperOffset = null,
- origOffset = null;
-
- el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) {
- helperOffset = ui.helper.offset();
- } });
+ origOffset = null,
+ el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) {
+ helperOffset = ui.helper.offset();
+ } });
$("#main").css('position', 'relative');
origOffset = $("#draggable1").offset();
@@ -679,11 +689,10 @@ test("{ helper: 'clone' }, absolute with scroll offset on root", function() {
TestHelpers.draggable.setScroll('root');
var helperOffset = null,
- origOffset = null;
-
- el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) {
- helperOffset = ui.helper.offset();
- } });
+ origOffset = null,
+ el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) {
+ helperOffset = ui.helper.offset();
+ } });
$("#main").css('position', 'relative');
origOffset = $("#draggable1").offset();
@@ -710,12 +719,12 @@ test("{ helper: 'clone' }, absolute with scroll offset on root and parent", func
TestHelpers.draggable.setScroll('root');
TestHelpers.draggable.setScroll();
- var helperOffset = null,
- origOffset = null;
- el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) {
- helperOffset = ui.helper.offset();
- } });
+ var helperOffset = null,
+ origOffset = null,
+ el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) {
+ helperOffset = ui.helper.offset();
+ } });
$("#main").css('position', 'relative');
origOffset = $("#draggable1").offset();
@@ -742,7 +751,8 @@ test("{ opacity: 0.5 }", function() {
expect(1);
var opacity = null;
- el = $("#draggable2").draggable({
+
+ $("#draggable2").draggable({
opacity: 0.5,
start: function() {
opacity = $(this).css("opacity");
@@ -762,7 +772,7 @@ test("{ zIndex: 10 }", function() {
var actual,
expected = 10;
- el = $("#draggable2").draggable({
+ $("#draggable2").draggable({
zIndex: expected,
start: function() {
actual = $(this).css("zIndex");
diff --git a/tests/unit/draggable/draggable_test_helpers.js b/tests/unit/draggable/draggable_test_helpers.js
new file mode 100644
index 000000000..7057df1f8
--- /dev/null
+++ b/tests/unit/draggable/draggable_test_helpers.js
@@ -0,0 +1,57 @@
+TestHelpers.draggable = {
+ // todo: remove the unreliable offset hacks
+ unreliableOffset: $.ui.ie && ( !document.documentMode || document.documentMode < 8 ) ? 2 : 0,
+ drag: function(handle, dx, dy) {
+ $(handle).simulate("drag", {
+ dx: dx || 0,
+ dy: dy || 0
+ });
+ },
+ testDrag: function(el, handle, dx, dy, expectedDX, expectedDY, msg) {
+ var offsetAfter, actual, expected,
+ offsetBefore = el.offset();
+
+ TestHelpers.draggable.drag(handle, dx, dy);
+ offsetAfter = el.offset();
+
+ actual = { left: offsetAfter.left, top: offsetAfter.top },
+ expected = { left: offsetBefore.left + expectedDX, top: offsetBefore.top + expectedDY };
+
+ msg = msg ? msg + "." : "";
+ deepEqual(actual, expected, 'dragged[' + dx + ', ' + dy + '] ' + msg);
+ },
+ shouldMove: function(el, why) {
+ TestHelpers.draggable.testDrag(el, el, 50, 50, 50, 50, why);
+ },
+ shouldNotMove: function(el, why) {
+ TestHelpers.draggable.testDrag(el, el, 50, 50, 0, 0, why);
+ },
+ testScroll: function(el, position ) {
+ var oldPosition = $("#main").css('position');
+ $("#main").css('position', position);
+ TestHelpers.draggable.shouldMove(el, position+' parent');
+ $("#main").css('position', oldPosition);
+ },
+ restoreScroll: function( what ) {
+ if( what ) {
+ $(document).scrollTop(0); $(document).scrollLeft(0);
+ } else {
+ $("#main").scrollTop(0); $("#main").scrollLeft(0);
+ }
+ },
+ setScroll: function( what ) {
+ if(what) {
+ // todo: currently, the draggable interaction doesn't properly account for scrolled pages,
+ // uncomment the line below to make the tests fail that should when the page is scrolled
+ // $(document).scrollTop(100); $(document).scrollLeft(100);
+ } else {
+ $("#main").scrollTop(100); $("#main").scrollLeft(100);
+ }
+ },
+ border: function(el, side) {
+ return parseInt(el.css('border-' + side + '-width'), 10) || 0;
+ },
+ margin: function(el, side) {
+ return parseInt(el.css('margin-' + side), 10) || 0;
+ }
+}; \ No newline at end of file
diff --git a/tests/unit/droppable/droppable.html b/tests/unit/droppable/droppable.html
index cd29b1cdf..7cd5eb0f5 100644
--- a/tests/unit/droppable/droppable.html
+++ b/tests/unit/droppable/droppable.html
@@ -27,6 +27,7 @@
<script src="droppable_events.js"></script>
<script src="droppable_methods.js"></script>
<script src="droppable_options.js"></script>
+ <script src="droppable_test_helpers.js"></script>
<script src="../swarminject.js"></script>
</head>
diff --git a/tests/unit/droppable/droppable_core.js b/tests/unit/droppable/droppable_core.js
index 21763bc63..c98850a03 100644
--- a/tests/unit/droppable/droppable_core.js
+++ b/tests/unit/droppable/droppable_core.js
@@ -2,17 +2,6 @@
* droppable_core.js
*/
-TestHelpers.droppable = {
- shouldDrop: function() {
- // todo: actually implement this
- ok(true, 'missing test - untested code is broken code');
- },
- shouldNotDrop: function() {
- // todo: actually implement this
- ok(true, 'missing test - untested code is broken code');
- }
-};
-
(function($) {
module("droppable: core");
diff --git a/tests/unit/droppable/droppable_methods.js b/tests/unit/droppable/droppable_methods.js
index 3f1293ae4..76501c5b1 100644
--- a/tests/unit/droppable/droppable_methods.js
+++ b/tests/unit/droppable/droppable_methods.js
@@ -43,6 +43,9 @@ test("destroy", function() {
test("enable", function() {
expect(7);
+
+ var el, expected, actual;
+
el = $("#droppable1").droppable({ disabled: true });
TestHelpers.droppable.shouldNotDrop();
el.droppable("enable");
@@ -55,13 +58,16 @@ test("enable", function() {
equal(el.droppable("option", "disabled"), false, "disabled option setter");
TestHelpers.droppable.shouldDrop();
- var expected = $('<div></div>').droppable(),
- actual = expected.droppable('enable');
+ expected = $('<div></div>').droppable(),
+ actual = expected.droppable('enable');
equal(actual, expected, 'enable is chainable');
});
test("disable", function() {
expect(7);
+
+ var el, actual, expected;
+
el = $("#droppable1").droppable({ disabled: false });
TestHelpers.droppable.shouldDrop();
el.droppable("disable");
@@ -74,8 +80,8 @@ test("disable", function() {
equal(el.droppable("option", "disabled"), true, "disabled option setter");
TestHelpers.droppable.shouldNotDrop();
- var expected = $('<div></div>').droppable(),
- actual = expected.droppable('disable');
+ expected = $('<div></div>').droppable(),
+ actual = expected.droppable('disable');
equal(actual, expected, 'disable is chainable');
});
diff --git a/tests/unit/droppable/droppable_options.js b/tests/unit/droppable/droppable_options.js
index db3201e88..c2ecdcfda 100644
--- a/tests/unit/droppable/droppable_options.js
+++ b/tests/unit/droppable/droppable_options.js
@@ -24,14 +24,14 @@ test("activeClass", function() {
*/
test("{ addClasses: true }, default", function() {
expect( 1 );
- el = $("<div></div>").droppable({ addClasses: true });
+ var el = $("<div></div>").droppable({ addClasses: true });
ok(el.is(".ui-droppable"), "'ui-droppable' class added");
el.droppable("destroy");
});
test("{ addClasses: false }", function() {
expect( 1 );
- el = $("<div></div>").droppable({ addClasses: false });
+ var el = $("<div></div>").droppable({ addClasses: false });
ok(!el.is(".ui-droppable"), "'ui-droppable' class not added");
el.droppable("destroy");
});
diff --git a/tests/unit/droppable/droppable_test_helpers.js b/tests/unit/droppable/droppable_test_helpers.js
new file mode 100644
index 000000000..79311788c
--- /dev/null
+++ b/tests/unit/droppable/droppable_test_helpers.js
@@ -0,0 +1,10 @@
+TestHelpers.droppable = {
+ shouldDrop: function() {
+ // todo: actually implement this
+ ok(true, 'missing test - untested code is broken code');
+ },
+ shouldNotDrop: function() {
+ // todo: actually implement this
+ ok(true, 'missing test - untested code is broken code');
+ }
+}; \ No newline at end of file
diff --git a/tests/unit/resizable/resizable.html b/tests/unit/resizable/resizable.html
index 50099efee..eca465ae9 100644
--- a/tests/unit/resizable/resizable.html
+++ b/tests/unit/resizable/resizable.html
@@ -26,6 +26,7 @@
<script src="resizable_events.js"></script>
<script src="resizable_methods.js"></script>
<script src="resizable_options.js"></script>
+ <script src="resizable_test_helpers.js"></script>
<script src="../swarminject.js"></script>
</head>
diff --git a/tests/unit/resizable/resizable_core.js b/tests/unit/resizable/resizable_core.js
index f4e6cdedd..01f15bd4b 100644
--- a/tests/unit/resizable/resizable_core.js
+++ b/tests/unit/resizable/resizable_core.js
@@ -2,22 +2,6 @@
* resizable_core.js
*/
-TestHelpers.resizable = {
- drag: function(el, dx, dy, complete) {
-
- // speed = sync -> Drag syncrhonously.
- // speed = fast|slow -> Drag asyncrhonously - animated.
-
- //this mouseover is to work around a limitation in resizable
- //TODO: fix resizable so handle doesn't require mouseover in order to be used
- $(el).simulate("mouseover");
-
- return $(el).simulate("drag", {
- dx: dx||0, dy: dy||0, speed: 'sync', complete: complete
- });
- }
-};
-
(function($) {
module("resizable: core");
diff --git a/tests/unit/resizable/resizable_test_helpers.js b/tests/unit/resizable/resizable_test_helpers.js
new file mode 100644
index 000000000..fe6c84900
--- /dev/null
+++ b/tests/unit/resizable/resizable_test_helpers.js
@@ -0,0 +1,15 @@
+TestHelpers.resizable = {
+ drag: function(el, dx, dy, complete) {
+
+ // speed = sync -> Drag syncrhonously.
+ // speed = fast|slow -> Drag asyncrhonously - animated.
+
+ //this mouseover is to work around a limitation in resizable
+ //TODO: fix resizable so handle doesn't require mouseover in order to be used
+ $(el).simulate("mouseover");
+
+ return $(el).simulate("drag", {
+ dx: dx||0, dy: dy||0, speed: 'sync', complete: complete
+ });
+ }
+}; \ No newline at end of file
diff --git a/tests/unit/selectable/selectable.html b/tests/unit/selectable/selectable.html
index 18ffc6ef7..13718e1f3 100644
--- a/tests/unit/selectable/selectable.html
+++ b/tests/unit/selectable/selectable.html
@@ -26,6 +26,7 @@
<script src="selectable_events.js"></script>
<script src="selectable_methods.js"></script>
<script src="selectable_options.js"></script>
+ <script src="selectable_test_helpers.js"></script>
<script src="../swarminject.js"></script>
</head>
diff --git a/tests/unit/selectable/selectable_core.js b/tests/unit/selectable/selectable_core.js
index de89e66a7..9953b6c07 100644
--- a/tests/unit/selectable/selectable_core.js
+++ b/tests/unit/selectable/selectable_core.js
@@ -1,16 +1,3 @@
/*
* selectable_core.js
- */
-
-TestHelpers.selectable = {
- drag: function drag(el, dx, dy) {
- var off = el.offset(),
- pos = { clientX: off.left, clientY: off.top };
- el.simulate("mousedown", pos);
- $(document).simulate("mousemove", pos);
- pos.clientX += dx;
- pos.clientY += dy;
- $(document).simulate("mousemove", pos);
- $(document).simulate("mouseup", pos);
- }
-}; \ No newline at end of file
+ */ \ No newline at end of file
diff --git a/tests/unit/selectable/selectable_test_helpers.js b/tests/unit/selectable/selectable_test_helpers.js
new file mode 100644
index 000000000..c707ab622
--- /dev/null
+++ b/tests/unit/selectable/selectable_test_helpers.js
@@ -0,0 +1,12 @@
+TestHelpers.selectable = {
+ drag: function(el, dx, dy) {
+ var off = el.offset(),
+ pos = { clientX: off.left, clientY: off.top };
+ el.simulate("mousedown", pos);
+ $(document).simulate("mousemove", pos);
+ pos.clientX += dx;
+ pos.clientY += dy;
+ $(document).simulate("mousemove", pos);
+ $(document).simulate("mouseup", pos);
+ }
+}; \ No newline at end of file
diff --git a/tests/unit/sortable/sortable.html b/tests/unit/sortable/sortable.html
index 644b931ee..b7b7b0007 100644
--- a/tests/unit/sortable/sortable.html
+++ b/tests/unit/sortable/sortable.html
@@ -26,6 +26,7 @@
<script src="sortable_events.js"></script>
<script src="sortable_methods.js"></script>
<script src="sortable_options.js"></script>
+ <script src="sortable_test_helpers.js"></script>
<script src="sortable_tickets.js"></script>
<script src="../swarminject.js"></script>
diff --git a/tests/unit/sortable/sortable_core.js b/tests/unit/sortable/sortable_core.js
index f036121b8..211f8ac95 100644
--- a/tests/unit/sortable/sortable_core.js
+++ b/tests/unit/sortable/sortable_core.js
@@ -1,19 +1,3 @@
/*
* sortable_core.js
- */
-
-(function($) {
-
-TestHelpers.sortable = {
- sort: function(handle, dx, dy, index, msg) {
- $(handle).simulate("drag", {
- dx: dx || 0,
- dy: dy || 0
- });
- equal($(handle).parent().children().index(handle), index, msg);
- }
-};
-
-module("sortable: core");
-
-})(jQuery);
+ */ \ No newline at end of file
diff --git a/tests/unit/sortable/sortable_methods.js b/tests/unit/sortable/sortable_methods.js
index 85b418ac8..de32e2f5d 100644
--- a/tests/unit/sortable/sortable_methods.js
+++ b/tests/unit/sortable/sortable_methods.js
@@ -42,6 +42,9 @@ test("destroy", function() {
test("enable", function() {
expect(5);
+
+ var el, actual, expected;
+
el = $("#sortable").sortable({ disabled: true });
TestHelpers.sortable.sort($("li", el)[0], 0, 44, 0, '.sortable({ disabled: true })');
@@ -56,13 +59,16 @@ test("enable", function() {
TestHelpers.sortable.sort($("li", el)[0], 0, 44, 2, '.sortable("option", "disabled", false)');
- var expected = $('<div></div>').sortable(),
- actual = expected.sortable('enable');
+ expected = $('<div></div>').sortable(),
+ actual = expected.sortable('enable');
equal(actual, expected, 'enable is chainable');
});
test("disable", function() {
expect(7);
+
+ var el, actual, expected;
+
el = $("#sortable").sortable({ disabled: false });
TestHelpers.sortable.sort($("li", el)[0], 0, 44, 2, '.sortable({ disabled: false })');
@@ -78,8 +84,8 @@ test("disable", function() {
ok(el.sortable("widget").is(":not(.ui-state-disabled)"), "sortable element does not get ui-state-disabled since it's an interaction");
TestHelpers.sortable.sort($("li", el)[0], 0, 44, 0, '.sortable("option", "disabled", true)');
- var expected = $('<div></div>').sortable(),
- actual = expected.sortable('disable');
+ expected = $('<div></div>').sortable(),
+ actual = expected.sortable('disable');
equal(actual, expected, 'disable is chainable');
});
diff --git a/tests/unit/sortable/sortable_test_helpers.js b/tests/unit/sortable/sortable_test_helpers.js
new file mode 100644
index 000000000..7569b5797
--- /dev/null
+++ b/tests/unit/sortable/sortable_test_helpers.js
@@ -0,0 +1,9 @@
+TestHelpers.sortable = {
+ sort: function(handle, dx, dy, index, msg) {
+ $(handle).simulate("drag", {
+ dx: dx || 0,
+ dy: dy || 0
+ });
+ equal($(handle).parent().children().index(handle), index, msg);
+ }
+}; \ No newline at end of file
diff --git a/tests/unit/sortable/sortable_tickets.js b/tests/unit/sortable/sortable_tickets.js
index c8ec08502..eebd8dc21 100644
--- a/tests/unit/sortable/sortable_tickets.js
+++ b/tests/unit/sortable/sortable_tickets.js
@@ -8,12 +8,12 @@ module("sortable: tickets");
test("#3019: Stop fires too early", function() {
expect(2);
- var helper = null;
- el = $("#sortable").sortable({
- stop: function(event, ui) {
- helper = ui.helper;
- }
- });
+ var helper = null,
+ el = $("#sortable").sortable({
+ stop: function(event, ui) {
+ helper = ui.helper;
+ }
+ });
TestHelpers.sortable.sort($("li", el)[0], 0, 44, 2, 'Dragging the sortable');
equal(helper, null, "helper should be false");