Skip to content
Permalink
Browse files

dialog unit tests: options closeOnEscape, draggable

  • Loading branch information
rdworth committed Sep 19, 2009
1 parent 7991690 commit 5c87e2e448e9c8227970f774bc9565a6f34ac885
Showing with 24 additions and 8 deletions.
  1. +5 −5 tests/unit/dialog/dialog_core.js
  2. +19 −3 tests/unit/dialog/dialog_options.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);
}

@@ -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();
});

0 comments on commit 5c87e2e

Please sign in to comment.
You can’t perform that action at this time.