aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Worth <rdworth@gmail.com>2009-09-19 10:16:08 +0000
committerRichard Worth <rdworth@gmail.com>2009-09-19 10:16:08 +0000
commit5c87e2e448e9c8227970f774bc9565a6f34ac885 (patch)
treef3c357c228d7f48f722331b8471b8aad1dacaa90
parent79916907b5be35062f852eb0a0b14ae81b046c8e (diff)
downloadjquery-ui-5c87e2e448e9c8227970f774bc9565a6f34ac885.tar.gz
jquery-ui-5c87e2e448e9c8227970f774bc9565a6f34ac885.zip
dialog unit tests: options closeOnEscape, draggable
-rw-r--r--tests/unit/dialog/dialog_core.js10
-rw-r--r--tests/unit/dialog/dialog_options.js22
2 files changed, 24 insertions, 8 deletions
diff --git a/tests/unit/dialog/dialog_core.js b/tests/unit/dialog/dialog_core.js
index e419f05f9..3924c1d7f 100644
--- a/tests/unit/dialog/dialog_core.js
+++ b/tests/unit/dialog/dialog_core.js
@@ -40,20 +40,20 @@ function drag(handle, dx, dy) {
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);
}
diff --git a/tests/unit/dialog/dialog_options.js b/tests/unit/dialog/dialog_options.js
index feb51fbb4..7254431fd 100644
--- a/tests/unit/dialog/dialog_options.js
+++ b/tests/unit/dialog/dialog_options.js
@@ -72,7 +72,23 @@ test("buttons", function() {
});
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 @@ test("draggable", function() {
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();
});