]> source.dussan.org Git - jquery-ui.git/commitdiff
dialog unit tests: options closeOnEscape, draggable
authorRichard Worth <rdworth@gmail.com>
Sat, 19 Sep 2009 10:16:08 +0000 (10:16 +0000)
committerRichard Worth <rdworth@gmail.com>
Sat, 19 Sep 2009 10:16:08 +0000 (10:16 +0000)
tests/unit/dialog/dialog_core.js
tests/unit/dialog/dialog_options.js

index e419f05f9526e5bf5ef8c4aff30800a95fcdeab1..3924c1d7fa4783f10f9d91cc7551f8813b382016 100644 (file)
@@ -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);
 }
 
index feb51fbb47bebd5552402646a976a10ab967f124..7254431fde9f48371da9ff88af2f78b18c218608 100644 (file)
@@ -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();
 });