mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-12-07 06:14:24 +00:00
tests dialog - added some tests and placeholders
This commit is contained in:
parent
2361bda9ba
commit
9196c2022c
205
tests/dialog.js
205
tests/dialog.js
@ -6,6 +6,26 @@
|
|||||||
// Dialog Test Helper Functions
|
// Dialog Test Helper Functions
|
||||||
//
|
//
|
||||||
|
|
||||||
|
var defaults = {
|
||||||
|
autoOpen: true,
|
||||||
|
buttons: {},
|
||||||
|
disabled: false,
|
||||||
|
dialogClass: null,
|
||||||
|
draggable: true,
|
||||||
|
height: 200,
|
||||||
|
maxHeight: null,
|
||||||
|
maxWidth: null,
|
||||||
|
minHeight: 100,
|
||||||
|
minWidth: 150,
|
||||||
|
modal: false,
|
||||||
|
overlay: {},
|
||||||
|
position: 'center',
|
||||||
|
resizable: true,
|
||||||
|
stack: true,
|
||||||
|
title: null,
|
||||||
|
width: 300
|
||||||
|
};
|
||||||
|
|
||||||
var el,
|
var el,
|
||||||
offsetBefore, offsetAfter,
|
offsetBefore, offsetAfter,
|
||||||
heightBefore, heightAfter,
|
heightBefore, heightAfter,
|
||||||
@ -29,6 +49,9 @@ var drag = function(handle, dx, dy) {
|
|||||||
offsetBefore = d.offset();
|
offsetBefore = d.offset();
|
||||||
heightBefore = d.height();
|
heightBefore = d.height();
|
||||||
widthBefore = d.width();
|
widthBefore = d.width();
|
||||||
|
//this mouseover is to work around a limitation in resizable
|
||||||
|
//TODO: fix resizable so handle doesn't require mouseover in order to be used
|
||||||
|
$(handle, d).simulate("mouseover");
|
||||||
$(handle, d).simulate("drag", {
|
$(handle, d).simulate("drag", {
|
||||||
dx: dx || 0,
|
dx: dx || 0,
|
||||||
dy: dy || 0
|
dy: dy || 0
|
||||||
@ -39,10 +62,10 @@ var drag = function(handle, dx, dy) {
|
|||||||
widthAfter = d.width();
|
widthAfter = d.width();
|
||||||
}
|
}
|
||||||
|
|
||||||
var moved = function (dx, dy, msg) {
|
var moved = function(dx, dy, msg) {
|
||||||
msg = msg ? msg + "." : "";
|
msg = msg ? msg + "." : "";
|
||||||
var actual = { left: offsetAfter.left, top: offsetAfter.top };
|
var actual = { left: offsetAfter.left, top: offsetAfter.top };
|
||||||
var expected = { left: offsetBefore.left + dx, top: offsetAfter.top };
|
var expected = { left: offsetBefore.left + dx, top: offsetBefore.top + dy };
|
||||||
compare2(actual, expected, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ' + msg);
|
compare2(actual, expected, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ' + msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,6 +81,25 @@ function shouldnotmove(why) {
|
|||||||
moved(0, 0, why);
|
moved(0, 0, why);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var resized = function(dw, dh, msg) {
|
||||||
|
msg = msg ? msg + "." : "";
|
||||||
|
var actual = { width: widthAfter, height: heightAfter };
|
||||||
|
var expected = { width: widthBefore + dw, height: heightBefore + dh };
|
||||||
|
compare2(actual, expected, 'resized[' + dragged.dx + ', ' + dragged.dy + '] ' + msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
function shouldresize(why) {
|
||||||
|
var handle = $(".ui-resizable-se", dlg());
|
||||||
|
drag(handle, 50, 50);
|
||||||
|
resized(50, 50, why);
|
||||||
|
}
|
||||||
|
|
||||||
|
function shouldnotresize(why) {
|
||||||
|
var handle = $(".ui-resizable-se", dlg());
|
||||||
|
drag(handle, 50, 50);
|
||||||
|
resized(0, 0, why);
|
||||||
|
}
|
||||||
|
|
||||||
var border = function(el, side) { return parseInt(el.css('border-' + side + '-width')); }
|
var border = function(el, side) { return parseInt(el.css('border-' + side + '-width')); }
|
||||||
|
|
||||||
var margin = function(el, side) { return parseInt(el.css('margin-' + side)); }
|
var margin = function(el, side) { return parseInt(el.css('margin-' + side)); }
|
||||||
@ -74,18 +116,18 @@ test("init", function() {
|
|||||||
$([]).dialog().remove();
|
$([]).dialog().remove();
|
||||||
ok(true, '.dialog() called on empty collection');
|
ok(true, '.dialog() called on empty collection');
|
||||||
|
|
||||||
$("<div/>").dialog().remove();
|
$('<div/>').dialog().remove();
|
||||||
ok(true, '.dialog() called on disconnected DOMElement');
|
ok(true, '.dialog() called on disconnected DOMElement');
|
||||||
|
|
||||||
$("<div/>").dialog().dialog("foo").remove();
|
$('<div/>').dialog().dialog("foo").remove();
|
||||||
ok(true, 'arbitrary method called after init');
|
ok(true, 'arbitrary method called after init');
|
||||||
|
|
||||||
el = $("<div/>").dialog()
|
el = $('<div/>').dialog()
|
||||||
var foo = el.data("foo.dialog");
|
var foo = el.data("foo.dialog");
|
||||||
el.remove();
|
el.remove();
|
||||||
ok(true, 'arbitrary option getter after init');
|
ok(true, 'arbitrary option getter after init');
|
||||||
|
|
||||||
$("<div/>").dialog().data("foo.dialog", "bar").remove();
|
$('<div/>').dialog().data("foo.dialog", "bar").remove();
|
||||||
ok(true, 'arbitrary option setter after init');
|
ok(true, 'arbitrary option setter after init');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -98,18 +140,18 @@ test("destroy", function() {
|
|||||||
$([]).dialog().dialog("destroy").remove();
|
$([]).dialog().dialog("destroy").remove();
|
||||||
ok(true, '.dialog("destroy") called on empty collection');
|
ok(true, '.dialog("destroy") called on empty collection');
|
||||||
|
|
||||||
$("<div/>").dialog().dialog("destroy").remove();
|
$('<div/>').dialog().dialog("destroy").remove();
|
||||||
ok(true, '.dialog("destroy") called on disconnected DOMElement');
|
ok(true, '.dialog("destroy") called on disconnected DOMElement');
|
||||||
|
|
||||||
$("<div/>").dialog().dialog("destroy").dialog("foo").remove();
|
$('<div/>').dialog().dialog("destroy").dialog("foo").remove();
|
||||||
ok(true, 'arbitrary method called after destroy');
|
ok(true, 'arbitrary method called after destroy');
|
||||||
|
|
||||||
el = $("<div/>").dialog();
|
el = $('<div/>').dialog();
|
||||||
var foo = el.dialog("destroy").data("foo.dialog");
|
var foo = el.dialog("destroy").data("foo.dialog");
|
||||||
el.remove();
|
el.remove();
|
||||||
ok(true, 'arbitrary option getter after destroy');
|
ok(true, 'arbitrary option getter after destroy');
|
||||||
|
|
||||||
$("<div/>").dialog().dialog("destroy").data("foo.dialog", "bar").remove();
|
$('<div/>').dialog().dialog("destroy").data("foo.dialog", "bar").remove();
|
||||||
ok(true, 'arbitrary option setter after destroy');
|
ok(true, 'arbitrary option setter after destroy');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -137,24 +179,6 @@ test("element types", function() {
|
|||||||
|
|
||||||
test("defaults", function() {
|
test("defaults", function() {
|
||||||
el = $('<div/>').dialog();
|
el = $('<div/>').dialog();
|
||||||
var defaults = {
|
|
||||||
autoOpen: true,
|
|
||||||
buttons: {},
|
|
||||||
disabled: false,
|
|
||||||
draggable: true,
|
|
||||||
height: 200,
|
|
||||||
maxHeight: null,
|
|
||||||
maxWidth: null,
|
|
||||||
minHeight: 100,
|
|
||||||
minWidth: 150,
|
|
||||||
modal: false,
|
|
||||||
overlay: {},
|
|
||||||
position: 'center',
|
|
||||||
resizable: true,
|
|
||||||
stack: true,
|
|
||||||
title: null,
|
|
||||||
width: 300
|
|
||||||
};
|
|
||||||
$.each(defaults, function(key, val) {
|
$.each(defaults, function(key, val) {
|
||||||
var actual = el.data(key + ".dialog"), expected = val,
|
var actual = el.data(key + ".dialog"), expected = val,
|
||||||
method = (expected && expected.constructor == Object) ?
|
method = (expected && expected.constructor == Object) ?
|
||||||
@ -168,18 +192,16 @@ module("dialog: Options");
|
|||||||
|
|
||||||
test("autoOpen", function() {
|
test("autoOpen", function() {
|
||||||
expect(2);
|
expect(2);
|
||||||
|
el = $('<div/>').dialog({ autoOpen: false });
|
||||||
el = $("<div/>").dialog({ autoOpen: false });
|
|
||||||
isNotOpen('.dialog({ autoOpen: false })');
|
isNotOpen('.dialog({ autoOpen: false })');
|
||||||
el.remove();
|
el.remove();
|
||||||
|
el = $('<div/>').dialog({ autoOpen: true });
|
||||||
el = $("<div/>").dialog({ autoOpen: true });
|
|
||||||
isOpen('.dialog({ autoOpen: true })');
|
isOpen('.dialog({ autoOpen: true })');
|
||||||
el.remove();
|
el.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("buttons", function() {
|
test("buttons", function() {
|
||||||
expect(10);
|
expect(14);
|
||||||
var buttons = {
|
var buttons = {
|
||||||
"Ok": function(ev, ui) {
|
"Ok": function(ev, ui) {
|
||||||
ok(true, "button click fires callback");
|
ok(true, "button click fires callback");
|
||||||
@ -192,7 +214,7 @@ test("buttons", function() {
|
|||||||
equals(ev.target, btn[1], "event target");
|
equals(ev.target, btn[1], "event target");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
el = $("<div/>").dialog({ buttons: buttons });
|
el = $('<div/>').dialog({ buttons: buttons });
|
||||||
var btn = $("button", dlg());
|
var btn = $("button", dlg());
|
||||||
equals(btn.length, 2, "number of buttons");
|
equals(btn.length, 2, "number of buttons");
|
||||||
var i = 0;
|
var i = 0;
|
||||||
@ -202,71 +224,156 @@ test("buttons", function() {
|
|||||||
});
|
});
|
||||||
equals(btn.parent().attr('className'), 'ui-dialog-buttonpane', "buttons in container");
|
equals(btn.parent().attr('className'), 'ui-dialog-buttonpane', "buttons in container");
|
||||||
btn.trigger("click");
|
btn.trigger("click");
|
||||||
|
|
||||||
|
var newButtons = {
|
||||||
|
"Close": function() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
equals(el.data("buttons.dialog"), buttons, '.data("buttons.dialog") getter');
|
||||||
|
el.data("buttons.dialog", newButtons);
|
||||||
|
equals(el.data("buttons.dialog"), newButtons, '.data("buttons.dialog", ...) setter');
|
||||||
|
|
||||||
|
btn = $("button", dlg());
|
||||||
|
equals(btn.length, 1, "number of buttons after setter");
|
||||||
|
var i = 0;
|
||||||
|
$.each(newButtons, function(key, val) {
|
||||||
|
equals(btn.eq(i).text(), key, "text of button " + (i+1));
|
||||||
|
i += 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
el.remove();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("dialogClass", function() {
|
||||||
|
expect(4);
|
||||||
|
el = $('<div/>').dialog();
|
||||||
|
equals(dlg().is(".foo"), false, 'dialogClass not specified. foo class added');
|
||||||
|
el.remove();
|
||||||
|
el = $('<div/>').dialog({ dialogClass: "foo" });
|
||||||
|
equals(dlg().is(".foo"), true, 'dialogClass in init. foo class added');
|
||||||
|
el.remove();
|
||||||
|
el = $('<div/>').dialog({ dialogClass: "foo bar" });
|
||||||
|
equals(dlg().is(".foo"), true, 'dialogClass in init, two classes. foo class added');
|
||||||
|
equals(dlg().is(".bar"), true, 'dialogClass in init, two classes. bar class added');
|
||||||
el.remove();
|
el.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("draggable", function() {
|
test("draggable", function() {
|
||||||
el = $("<div/>").dialog({ draggable: false });
|
expect(2);
|
||||||
|
el = $('<div/>').dialog({ draggable: false });
|
||||||
shouldnotmove();
|
shouldnotmove();
|
||||||
el.remove();
|
el.remove();
|
||||||
el = $("<div/>").dialog({ draggable: true });
|
el = $('<div/>').dialog({ draggable: true });
|
||||||
shouldmove();
|
shouldmove();
|
||||||
el.remove();
|
el.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("height", function() {
|
test("height", function() {
|
||||||
el = $("<div/>").dialog();
|
expect(2);
|
||||||
equals(dlg().height(), 200, "default height");
|
el = $('<div/>').dialog();
|
||||||
|
equals(dlg().height(), defaults.height, "default height");
|
||||||
el.remove();
|
el.remove();
|
||||||
el = $("<div/>").dialog({ height: 437 });
|
el = $('<div/>').dialog({ height: 437 });
|
||||||
equals(dlg().height(), 437, "default height");
|
equals(dlg().height(), 437, "explicit height");
|
||||||
el.remove();
|
el.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("maxHeight", function() {
|
test("maxHeight", function() {
|
||||||
el = $("<div/>").dialog({ maxHeight: 400 });
|
expect(2);
|
||||||
|
el = $('<div/>').dialog({ maxHeight: 400 });
|
||||||
drag('.ui-resizable-s', 1000, 1000);
|
drag('.ui-resizable-s', 1000, 1000);
|
||||||
equals(heightAfter, 400, "maxHeight");
|
equals(heightAfter, 400, "maxHeight");
|
||||||
el.remove();
|
el.remove();
|
||||||
el = $("<div/>").dialog({ maxHeight: 400 });
|
el = $('<div/>').dialog({ maxHeight: 400 });
|
||||||
drag('.ui-resizable-n', -1000, -1000);
|
drag('.ui-resizable-n', -1000, -1000);
|
||||||
equals(heightAfter, 400, "maxHeight");
|
equals(heightAfter, 400, "maxHeight");
|
||||||
el.remove();
|
el.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("maxWidth", function() {
|
test("maxWidth", function() {
|
||||||
el = $("<div/>").dialog({ maxWidth: 400 });
|
expect(2);
|
||||||
|
el = $('<div/>').dialog({ maxWidth: 400 });
|
||||||
drag('.ui-resizable-e', 1000, 1000);
|
drag('.ui-resizable-e', 1000, 1000);
|
||||||
equals(widthAfter, 400, "maxWidth");
|
equals(widthAfter, 400, "maxWidth");
|
||||||
el.remove();
|
el.remove();
|
||||||
el = $("<div/>").dialog({ maxWidth: 400 });
|
el = $('<div/>').dialog({ maxWidth: 400 });
|
||||||
drag('.ui-resizable-w', -1000, -1000);
|
drag('.ui-resizable-w', -1000, -1000);
|
||||||
equals(widthAfter, 400, "maxWidth");
|
equals(widthAfter, 400, "maxWidth");
|
||||||
el.remove();
|
el.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("minHeight", function() {
|
test("minHeight", function() {
|
||||||
el = $("<div/>").dialog({ minHeight: 10 });
|
expect(2);
|
||||||
|
el = $('<div/>').dialog({ minHeight: 10 });
|
||||||
drag('.ui-resizable-s', -1000, -1000);
|
drag('.ui-resizable-s', -1000, -1000);
|
||||||
equals(heightAfter, 10, "minHeight");
|
equals(heightAfter, 10, "minHeight");
|
||||||
el.remove();
|
el.remove();
|
||||||
el = $("<div/>").dialog({ minHeight: 10 });
|
el = $('<div/>').dialog({ minHeight: 10 });
|
||||||
drag('.ui-resizable-n', 1000, 1000);
|
drag('.ui-resizable-n', 1000, 1000);
|
||||||
equals(heightAfter, 10, "minHeight");
|
equals(heightAfter, 10, "minHeight");
|
||||||
el.remove();
|
el.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("minWidth", function() {
|
test("minWidth", function() {
|
||||||
el = $("<div/>").dialog({ minWidth: 10 });
|
expect(2);
|
||||||
|
el = $('<div/>').dialog({ minWidth: 10 });
|
||||||
drag('.ui-resizable-e', -1000, -1000);
|
drag('.ui-resizable-e', -1000, -1000);
|
||||||
equals(widthAfter, 10, "minWidth");
|
equals(widthAfter, 10, "minWidth");
|
||||||
el.remove();
|
el.remove();
|
||||||
el = $("<div/>").dialog({ minWidth: 10 });
|
el = $('<div/>').dialog({ minWidth: 10 });
|
||||||
drag('.ui-resizable-w', 1000, 1000);
|
drag('.ui-resizable-w', 1000, 1000);
|
||||||
equals(widthAfter, 10, "minWidth");
|
equals(widthAfter, 10, "minWidth");
|
||||||
el.remove();
|
el.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("modal", function() {
|
||||||
|
ok(false, "missing test");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("overlay", function() {
|
||||||
|
ok(false, "missing test");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("position", function() {
|
||||||
|
ok(false, "missing test");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("resizable", function() {
|
||||||
|
expect(2);
|
||||||
|
el = $('<div/>').dialog();
|
||||||
|
shouldresize("[default]");
|
||||||
|
el.remove();
|
||||||
|
el = $('<div/>').dialog({ resizable: false });
|
||||||
|
shouldnotresize("disabled in init options");
|
||||||
|
el.remove();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
test("stack", function() {
|
||||||
|
ok(false, "missing test");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("title", function() {
|
||||||
|
expect(4);
|
||||||
|
function titleText() {
|
||||||
|
return dlg().find(".ui-dialog-title").text();
|
||||||
|
}
|
||||||
|
el = $('<div/>').dialog(); equals(titleText(), "", "[default]"); el.remove();
|
||||||
|
el = $('<div title="foo"/>').dialog(); equals(titleText(), "foo", "title in element attribute"); el.remove();
|
||||||
|
el = $('<div/>').dialog({ title: 'foo' }); equals(titleText(), "foo", "title in init options"); el.remove();
|
||||||
|
el = $('<div title="foo"/>').dialog({ title: 'bar' }); equals(titleText(), "bar", "title in init options should override title in element attribute"); el.remove();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("width", function() {
|
||||||
|
expect(2);
|
||||||
|
el = $('<div/>').dialog();
|
||||||
|
equals(dlg().width(), defaults.width, "default width");
|
||||||
|
el.remove();
|
||||||
|
el = $('<div/>').dialog({width: 437 });
|
||||||
|
equals(dlg().width(), 437, "explicit width");
|
||||||
|
el.remove();
|
||||||
|
});
|
||||||
|
|
||||||
module("dialog: Methods");
|
module("dialog: Methods");
|
||||||
|
|
||||||
module("dialog: Callbacks");
|
module("dialog: Callbacks");
|
||||||
@ -297,7 +404,7 @@ test("open", function() {
|
|||||||
|
|
||||||
test("close", function() {
|
test("close", function() {
|
||||||
expect(2);
|
expect(2);
|
||||||
el = $("<div/>").dialog({
|
el = $('<div/>').dialog({
|
||||||
close: function(ev, ui) {
|
close: function(ev, ui) {
|
||||||
ok(true, '.dialog("close") fires close callback');
|
ok(true, '.dialog("close") fires close callback');
|
||||||
equals(this, el[0], "context of callback");
|
equals(this, el[0], "context of callback");
|
||||||
|
@ -21,7 +21,7 @@ var drag = function(handle, dx, dy) {
|
|||||||
var moved = function (dx, dy, msg) {
|
var moved = function (dx, dy, msg) {
|
||||||
msg = msg ? msg + "." : "";
|
msg = msg ? msg + "." : "";
|
||||||
var actual = { left: offsetAfter.left, top: offsetAfter.top };
|
var actual = { left: offsetAfter.left, top: offsetAfter.top };
|
||||||
var expected = { left: offsetBefore.left + dx, top: offsetAfter.top };
|
var expected = { left: offsetBefore.left + dx, top: offsetBefore.top + dy };
|
||||||
compare2(actual, expected, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ' + msg);
|
compare2(actual, expected, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ' + msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user