mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Dialog: Added some more tests.
This commit is contained in:
parent
f500db5d75
commit
48cce41f39
167
tests/dialog.js
167
tests/dialog.js
@ -33,19 +33,19 @@ var el,
|
|||||||
widthBefore, widthAfter,
|
widthBefore, widthAfter,
|
||||||
dragged;
|
dragged;
|
||||||
|
|
||||||
var dlg = function() {
|
function dlg() {
|
||||||
return el.data("dialog").element.parents(".ui-dialog:first");
|
return el.data("dialog").element.parents(".ui-dialog:first");
|
||||||
}
|
}
|
||||||
|
|
||||||
var isOpen = function(why) {
|
function isOpen(why) {
|
||||||
ok(dlg().is(":visible"), why);
|
ok(dlg().is(":visible"), why);
|
||||||
}
|
}
|
||||||
|
|
||||||
var isNotOpen = function(why) {
|
function isNotOpen(why) {
|
||||||
ok(!dlg().is(":visible"), why);
|
ok(!dlg().is(":visible"), why);
|
||||||
}
|
}
|
||||||
|
|
||||||
var drag = function(handle, dx, dy) {
|
function drag(handle, dx, dy) {
|
||||||
var d = dlg();
|
var d = dlg();
|
||||||
offsetBefore = d.offset();
|
offsetBefore = d.offset();
|
||||||
heightBefore = d.height();
|
heightBefore = d.height();
|
||||||
@ -63,7 +63,7 @@ var drag = function(handle, dx, dy) {
|
|||||||
widthAfter = d.width();
|
widthAfter = d.width();
|
||||||
}
|
}
|
||||||
|
|
||||||
var moved = function(dx, dy, msg) {
|
function moved(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: offsetBefore.top + dy };
|
var expected = { left: offsetBefore.left + dx, top: offsetBefore.top + dy };
|
||||||
@ -82,7 +82,7 @@ function shouldnotmove(why) {
|
|||||||
moved(0, 0, why);
|
moved(0, 0, why);
|
||||||
}
|
}
|
||||||
|
|
||||||
var resized = function(dw, dh, msg) {
|
function resized(dw, dh, msg) {
|
||||||
msg = msg ? msg + "." : "";
|
msg = msg ? msg + "." : "";
|
||||||
var actual = { width: widthAfter, height: heightAfter };
|
var actual = { width: widthAfter, height: heightAfter };
|
||||||
var expected = { width: widthBefore + dw, height: heightBefore + dh };
|
var expected = { width: widthBefore + dw, height: heightBefore + dh };
|
||||||
@ -101,9 +101,13 @@ function shouldnotresize(why) {
|
|||||||
resized(0, 0, why);
|
resized(0, 0, why);
|
||||||
}
|
}
|
||||||
|
|
||||||
var border = function(el, side) { return parseInt(el.css('border-' + side + '-width')); }
|
function broder(el, side){
|
||||||
|
return parseInt(el.css('border-' + side + '-width'), 10);
|
||||||
|
}
|
||||||
|
|
||||||
var margin = function(el, side) { return parseInt(el.css('margin-' + side)); }
|
function margin(el, side) {
|
||||||
|
return parseInt(el.css('margin-' + side), 10);
|
||||||
|
}
|
||||||
|
|
||||||
// Dialog Tests
|
// Dialog Tests
|
||||||
module("dialog");
|
module("dialog");
|
||||||
@ -123,7 +127,7 @@ test("init", function() {
|
|||||||
$('<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');
|
||||||
@ -193,9 +197,11 @@ 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();
|
||||||
@ -203,25 +209,32 @@ test("autoOpen", function() {
|
|||||||
|
|
||||||
test("autoResize", function() {
|
test("autoResize", function() {
|
||||||
expect(2);
|
expect(2);
|
||||||
|
|
||||||
|
var actual,
|
||||||
|
before,
|
||||||
|
expected,
|
||||||
|
handle;
|
||||||
|
|
||||||
el = $('<div>content<br>content<br>content<br>content<br>content</div>').dialog({ autoResize: false });
|
el = $('<div>content<br>content<br>content<br>content<br>content</div>').dialog({ autoResize: false });
|
||||||
var expected = { height: el.height() };
|
expected = { height: el.height() };
|
||||||
var handle = $(".ui-resizable-se", dlg());
|
handle = $(".ui-resizable-se", dlg());
|
||||||
drag(handle, 50, 50);
|
drag(handle, 50, 50);
|
||||||
var actual = { height: el.height() };
|
actual = { height: el.height() };
|
||||||
compare2(actual, expected, '.dialog({ autoResize: false })');
|
compare2(actual, expected, '.dialog({ autoResize: false })');
|
||||||
el.remove();
|
el.remove();
|
||||||
el = $('<div>content<br>content<br>content<br>content<br>content</div>').dialog({ autoResize: true });
|
el = $('<div>content<br>content<br>content<br>content<br>content</div>').dialog({ autoResize: true });
|
||||||
var before = { width: el.width(), height: el.height() };
|
before = { width: el.width(), height: el.height() };
|
||||||
var handle = $(".ui-resizable-se", dlg());
|
handle = $(".ui-resizable-se", dlg());
|
||||||
drag(handle, 50, 50);
|
drag(handle, 50, 50);
|
||||||
var expected = { width: before.width + 50, height: before.height + 50 };
|
expected = { width: before.width + 50, height: before.height + 50 };
|
||||||
var actual = { width: el.width(), height: el.height() };
|
actual = { width: el.width(), height: el.height() };
|
||||||
compare2(actual, expected, '.dialog({ autoResize: true })');
|
compare2(actual, expected, '.dialog({ autoResize: true })');
|
||||||
el.remove();
|
el.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("buttons", function() {
|
test("buttons", function() {
|
||||||
expect(14);
|
expect(17);
|
||||||
|
|
||||||
var buttons = {
|
var buttons = {
|
||||||
"Ok": function(ev, ui) {
|
"Ok": function(ev, ui) {
|
||||||
ok(true, "button click fires callback");
|
ok(true, "button click fires callback");
|
||||||
@ -233,21 +246,28 @@ test("buttons", function() {
|
|||||||
equals(this, el[0], "context of callback");
|
equals(this, el[0], "context of callback");
|
||||||
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;
|
||||||
$.each(buttons, function(key, val) {
|
$.each(buttons, function(key, val) {
|
||||||
equals(btn.eq(i).text(), key, "text of button " + (i+1));
|
equals(btn.eq(i).text(), key, "text of button " + (i+1));
|
||||||
i += 1;
|
i++;
|
||||||
});
|
});
|
||||||
|
|
||||||
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 = {
|
var newButtons = {
|
||||||
"Close": function() {}
|
"Close": function(ev, ui) {
|
||||||
|
ok(true, "button click fires callback");
|
||||||
|
equals(this, el[0], "context of callback");
|
||||||
|
equals(ev.target, btn[0], "event target");
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
equals(el.data("buttons.dialog"), buttons, '.data("buttons.dialog") getter');
|
equals(el.data("buttons.dialog"), buttons, '.data("buttons.dialog") getter');
|
||||||
el.data("buttons.dialog", newButtons);
|
el.data("buttons.dialog", newButtons);
|
||||||
@ -255,7 +275,9 @@ test("buttons", function() {
|
|||||||
|
|
||||||
btn = $("button", dlg());
|
btn = $("button", dlg());
|
||||||
equals(btn.length, 1, "number of buttons after setter");
|
equals(btn.length, 1, "number of buttons after setter");
|
||||||
var i = 0;
|
btn.trigger('click');
|
||||||
|
|
||||||
|
i = 0;
|
||||||
$.each(newButtons, function(key, val) {
|
$.each(newButtons, function(key, val) {
|
||||||
equals(btn.eq(i).text(), key, "text of button " + (i+1));
|
equals(btn.eq(i).text(), key, "text of button " + (i+1));
|
||||||
i += 1;
|
i += 1;
|
||||||
@ -266,12 +288,15 @@ test("buttons", function() {
|
|||||||
|
|
||||||
test("dialogClass", function() {
|
test("dialogClass", function() {
|
||||||
expect(4);
|
expect(4);
|
||||||
|
|
||||||
el = $('<div/>').dialog();
|
el = $('<div/>').dialog();
|
||||||
equals(dlg().is(".foo"), false, 'dialogClass not specified. foo class added');
|
equals(dlg().is(".foo"), false, 'dialogClass not specified. foo class added');
|
||||||
el.remove();
|
el.remove();
|
||||||
|
|
||||||
el = $('<div/>').dialog({ dialogClass: "foo" });
|
el = $('<div/>').dialog({ dialogClass: "foo" });
|
||||||
equals(dlg().is(".foo"), true, 'dialogClass in init. foo class added');
|
equals(dlg().is(".foo"), true, 'dialogClass in init. foo class added');
|
||||||
el.remove();
|
el.remove();
|
||||||
|
|
||||||
el = $('<div/>').dialog({ dialogClass: "foo bar" });
|
el = $('<div/>').dialog({ dialogClass: "foo bar" });
|
||||||
equals(dlg().is(".foo"), true, 'dialogClass in init, two classes. foo class added');
|
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');
|
equals(dlg().is(".bar"), true, 'dialogClass in init, two classes. bar class added');
|
||||||
@ -279,71 +304,112 @@ test("dialogClass", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("draggable", function() {
|
test("draggable", function() {
|
||||||
expect(2);
|
expect(4);
|
||||||
|
|
||||||
el = $('<div/>').dialog({ draggable: false });
|
el = $('<div/>').dialog({ draggable: false });
|
||||||
shouldnotmove();
|
shouldnotmove();
|
||||||
|
el.data('draggable.dialog', true);
|
||||||
|
shouldmove();
|
||||||
el.remove();
|
el.remove();
|
||||||
|
|
||||||
el = $('<div/>').dialog({ draggable: true });
|
el = $('<div/>').dialog({ draggable: true });
|
||||||
shouldmove();
|
shouldmove();
|
||||||
|
el.data('draggable.dialog', false);
|
||||||
|
shouldnotmove();
|
||||||
el.remove();
|
el.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("height", function() {
|
test("height", function() {
|
||||||
expect(2);
|
expect(3);
|
||||||
|
|
||||||
el = $('<div/>').dialog();
|
el = $('<div/>').dialog();
|
||||||
equals(dlg().height(), defaults.height, "default height");
|
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, "explicit height");
|
equals(dlg().height(), 437, "explicit height");
|
||||||
el.remove();
|
el.remove();
|
||||||
|
|
||||||
|
el = $('<div/>').dialog();
|
||||||
|
el.data('height.dialog', 438);
|
||||||
|
equals(dlg().height(), 438, "explicit height set after init");
|
||||||
|
el.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("maxHeight", function() {
|
test("maxHeight", function() {
|
||||||
expect(2);
|
expect(3);
|
||||||
|
|
||||||
el = $('<div/>').dialog({ maxHeight: 400 });
|
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();
|
||||||
|
|
||||||
|
el = $('<div/>').dialog({ maxHeight: 400 }).data('maxHeight.dialog', 600);
|
||||||
|
drag('.ui-resizable-n', -1000, -1000);
|
||||||
|
equals(heightAfter, 600, "maxHeight");
|
||||||
|
el.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("maxWidth", function() {
|
test("maxWidth", function() {
|
||||||
expect(2);
|
expect(3);
|
||||||
|
|
||||||
el = $('<div/>').dialog({ maxWidth: 400 });
|
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();
|
||||||
|
|
||||||
|
el = $('<div/>').dialog({ maxWidth: 400 }).data('maxWidth.dialog', 600);
|
||||||
|
drag('.ui-resizable-w', -1000, -1000);
|
||||||
|
equals(widthAfter, 600, "maxWidth");
|
||||||
|
el.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("minHeight", function() {
|
test("minHeight", function() {
|
||||||
expect(2);
|
expect(3);
|
||||||
|
|
||||||
el = $('<div/>').dialog({ minHeight: 10 });
|
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();
|
||||||
|
|
||||||
|
el = $('<div/>').dialog({ minHeight: 10 }).data('minHeight.dialog', 30);
|
||||||
|
drag('.ui-resizable-n', 1000, 1000);
|
||||||
|
equals(heightAfter, 30, "minHeight");
|
||||||
|
el.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("minWidth", function() {
|
test("minWidth", function() {
|
||||||
expect(2);
|
expect(3);
|
||||||
|
|
||||||
el = $('<div/>').dialog({ minWidth: 10 });
|
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();
|
||||||
|
|
||||||
|
el = $('<div/>').dialog({ minWidth: 30 }).data('minWidth.dialog', 30);
|
||||||
|
drag('.ui-resizable-w', 1000, 1000);
|
||||||
|
equals(widthAfter, 30, "minWidth");
|
||||||
|
el.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("modal", function() {
|
test("modal", function() {
|
||||||
@ -359,14 +425,19 @@ test("position", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("resizable", function() {
|
test("resizable", function() {
|
||||||
expect(2);
|
expect(4);
|
||||||
|
|
||||||
el = $('<div/>').dialog();
|
el = $('<div/>').dialog();
|
||||||
shouldresize("[default]");
|
shouldresize("[default]");
|
||||||
el.remove();
|
el.data('resizable.dialog', false);
|
||||||
el = $('<div/>').dialog({ resizable: false });
|
shouldnotresize('disabled after init');
|
||||||
shouldnotresize("disabled in init options");
|
|
||||||
el.remove();
|
el.remove();
|
||||||
|
|
||||||
|
el = $('<div/>').dialog({ resizable: false });
|
||||||
|
shouldnotresize("disabled in init options");
|
||||||
|
el.data('resizable.dialog', true);
|
||||||
|
shouldresize('enabled after init');
|
||||||
|
el.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("stack", function() {
|
test("stack", function() {
|
||||||
@ -374,23 +445,44 @@ test("stack", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("title", function() {
|
test("title", function() {
|
||||||
expect(4);
|
expect(5);
|
||||||
|
|
||||||
function titleText() {
|
function titleText() {
|
||||||
return dlg().find(".ui-dialog-title").html();
|
return dlg().find(".ui-dialog-title").html();
|
||||||
}
|
}
|
||||||
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();
|
||||||
el = $('<div/>').dialog({ title: 'foo' }); equals(titleText(), "foo", "title in init options"); el.remove();
|
equals(titleText(), " ", "[default]");
|
||||||
el = $('<div title="foo"/>').dialog({ title: 'bar' }); equals(titleText(), "bar", "title in init options should override title in element attribute"); el.remove();
|
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();
|
||||||
|
|
||||||
|
el = $('<div/>').dialog().data('title.dialog', 'foo');
|
||||||
|
equals(titleText(), 'foo', 'title after init');
|
||||||
|
el.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("width", function() {
|
test("width", function() {
|
||||||
expect(2);
|
expect(3);
|
||||||
|
|
||||||
el = $('<div/>').dialog();
|
el = $('<div/>').dialog();
|
||||||
equals(dlg().width(), defaults.width, "default width");
|
equals(dlg().width(), defaults.width, "default width");
|
||||||
el.remove();
|
el.remove();
|
||||||
|
|
||||||
el = $('<div/>').dialog({width: 437 });
|
el = $('<div/>').dialog({width: 437 });
|
||||||
equals(dlg().width(), 437, "explicit width");
|
equals(dlg().width(), 437, "explicit width");
|
||||||
|
el.data('width.dialog', 438);
|
||||||
|
equals(dlg().width(), 438, 'explicit width after init');
|
||||||
el.remove();
|
el.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -398,6 +490,7 @@ module("dialog: Methods");
|
|||||||
|
|
||||||
test("isOpen", function() {
|
test("isOpen", function() {
|
||||||
expect(4);
|
expect(4);
|
||||||
|
|
||||||
el = $('<div/>').dialog();
|
el = $('<div/>').dialog();
|
||||||
equals(el.dialog('isOpen'), true, "dialog is open after init");
|
equals(el.dialog('isOpen'), true, "dialog is open after init");
|
||||||
el.dialog('close');
|
el.dialog('close');
|
||||||
|
Loading…
Reference in New Issue
Block a user