r3260 committed - dialog unit tests: options closeOnEscape, draggable
Revision: 3260
Author: rdworth
Date: Sat Sep 19 03:16:08 2009
Log: dialog unit tests: options closeOnEscape, draggable
http://code.google.com/p/jquery-ui/source/detail?r=3260
Modified:
/trunk/tests/unit/dialog/dialog_core.js
/trunk/tests/unit/dialog/dialog_options.js
=======================================
--- /trunk/tests/unit/dialog/dialog_core.js Tue Feb 3 20:35:18 2009
+++ /trunk/tests/unit/dialog/dialog_core.js Sat Sep 19 03:16:08 2009
@@ -40,20 +40,20 @@
function moved(dx, dy, msg) {
msg = msg ? msg + "." : "";
- var actual = { left: offsetAfter.left, top: offsetAfter.top };
- var expected = { left: offsetBefore.left + dx, top: offsetBefore.top + dy
};
+ var actual = { left: Math.round(offsetAfter.left), top:
Math.round(offsetAfter.top) };
+ var expected = { left: Math.round(offsetBefore.left + dx), top:
Math.round(offsetBefore.top + dy) };
same(actual, expected, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] '
+ msg);
}
function shouldmove(why) {
var handle = $(".ui-dialog-titlebar", dlg());
- drag(handle, 50, 50);
- moved(50, 50, why);
+ drag(handle, 50, -50);
+ moved(50, -50, why);
}
function shouldnotmove(why) {
var handle = $(".ui-dialog-titlebar", dlg());
- drag(handle, 50, 50);
+ drag(handle, 50, -50);
moved(0, 0, why);
}
=======================================
--- /trunk/tests/unit/dialog/dialog_options.js Fri Mar 27 17:37:16 2009
+++ /trunk/tests/unit/dialog/dialog_options.js Sat Sep 19 03:16:08 2009
@@ -72,7 +72,23 @@
});
test("closeOnEscape", function() {
- ok(false, 'missing test - untested code is broken code');
+ el = $('<div></div>').dialog({ closeOnEscape: false });
+ ok(true, 'closeOnEscape: false');
+ ok(dlg().is(':visible') && !dlg().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');
+
+ el.remove();
+
+ el = $('<div></div>').dialog({ closeOnEscape: true });
+ ok(true, 'closeOnEscape: true');
+ ok(dlg().is(':visible') && !dlg().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');
});
test("closeText", function() {
@@ -116,13 +132,13 @@
el = $('<div></div>').dialog({ draggable: false });
shouldnotmove();
- el.data('draggable.dialog', true);
+ el.dialog('option', 'draggable', true);
shouldmove();
el.remove();
el = $('<div></div>').dialog({ draggable: true });
shouldmove();
- el.data('draggable.dialog', false);
+ el.dialog('option', 'draggable', false);
shouldnotmove();
el.remove();
});