From 5c87e2e448e9c8227970f774bc9565a6f34ac885 Mon Sep 17 00:00:00 2001 From: Richard Worth Date: Sat, 19 Sep 2009 10:16:08 +0000 Subject: [PATCH] dialog unit tests: options closeOnEscape, draggable --- tests/unit/dialog/dialog_core.js | 10 +++++----- tests/unit/dialog/dialog_options.js | 22 +++++++++++++++++++--- 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 = $('
').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 = $('
').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 = $('
').dialog({ draggable: false }); shouldnotmove(); - el.data('draggable.dialog', true); + el.dialog('option', 'draggable', true); shouldmove(); el.remove(); el = $('
').dialog({ draggable: true }); shouldmove(); - el.data('draggable.dialog', false); + el.dialog('option', 'draggable', false); shouldnotmove(); el.remove(); }); -- 2.39.5