aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/dialog
diff options
context:
space:
mode:
authorBen Hollis <bhollis@amazon.com>2010-06-06 15:00:49 -0700
committerScott González <scott.gonzalez@gmail.com>2010-07-14 16:29:28 -0400
commit6de9a5368c3e0523f91f08e7b1516549ce006f98 (patch)
treec75cb231c521f029692f75da1e6f6efff7332fe9 /tests/unit/dialog
parentd8caa61be66db215f74e276dec73356531b7faf4 (diff)
downloadjquery-ui-6de9a5368c3e0523f91f08e7b1516549ce006f98.tar.gz
jquery-ui-6de9a5368c3e0523f91f08e7b1516549ce006f98.zip
Dialog: allow setting position with ui.position arguments. Fixes #5459 - Dialog: expose .position() API
Diffstat (limited to 'tests/unit/dialog')
-rw-r--r--tests/unit/dialog/dialog_options.js103
1 files changed, 101 insertions, 2 deletions
diff --git a/tests/unit/dialog/dialog_options.js b/tests/unit/dialog/dialog_options.js
index 28b3812b5..b5eda1fcf 100644
--- a/tests/unit/dialog/dialog_options.js
+++ b/tests/unit/dialog/dialog_options.js
@@ -244,11 +244,110 @@ test("position, default center on window", function() {
var el = $('<div></div>').dialog();
var offset = el.parent().offset();
// use .position() instead to avoid replicating center-logic?
- same(offset.left, Math.floor($(window).width() / 2 - el.parent().width() / 2));
- same(offset.top, Math.floor($(window).height() / 2 - el.parent().height() / 2));
+ same(offset.left, Math.floor($(window).width() / 2 - dialog.outerWidth() / 2) + $(window).scrollLeft());
+ same(offset.top, Math.floor($(window).height() / 2 - dialog.outerHeight() / 2) + $(window).scrollTop());
el.remove();
});
+test("position, top on window", function() {
+ var el = $('<div></div>').dialog({ position: "top" });
+ var dialog = el.closest('.ui-dialog');
+ var offset = dialog.offset();
+ same(offset.left, Math.floor($(window).width() / 2 - dialog.outerWidth() / 2));
+ same(offset.top, $(window).scrollTop());
+ el.remove();
+});
+
+test("position, left on window", function() {
+ var el = $('<div></div>').dialog({ position: "left" });
+ var dialog = el.closest('.ui-dialog');
+ var offset = dialog.offset();
+ same(offset.left, 0);
+ same(offset.top, Math.floor($(window).height() / 2 - dialog.outerHeight() / 2) + $(window).scrollTop());
+ el.remove();
+});
+
+test("position, right bottom on window", function() {
+ var el = $('<div></div>').dialog({ position: "right bottom" });
+ var dialog = el.closest('.ui-dialog');
+ var offset = dialog.offset();
+ same(offset.left, $(window).width() - dialog.outerWidth());
+ same(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop());
+ el.remove();
+});
+
+test("position, right bottom on window w/array", function() {
+ var el = $('<div></div>').dialog({ position: ["right", "bottom"] });
+ var dialog = el.closest('.ui-dialog');
+ var offset = dialog.offset();
+ same(offset.left, $(window).width() - dialog.outerWidth());
+ same(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop());
+ el.remove();
+});
+
+test("position, offset from top left w/array", function() {
+ var el = $('<div></div>').dialog({ position: [10, 10] });
+ var dialog = el.closest('.ui-dialog');
+ var offset = dialog.offset();
+ same(offset.left, 10);
+ same(offset.top, 10 + $(window).scrollTop());
+ el.remove();
+});
+
+test("position, right bottom at right bottom via ui.position args", function() {
+ var el = $('<div></div>').dialog({
+ position: {
+ my: "right bottom",
+ at: "right bottom"
+ }
+ });
+
+ var dialog = el.closest('.ui-dialog');
+ var offset = dialog.offset();
+
+ same(offset.left, $(window).width() - dialog.outerWidth());
+ same(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop());
+ el.remove();
+});
+
+test("position, at another element", function() {
+ var parent = $('<div></div>').css({
+ position: 'absolute',
+ top: 400,
+ left: 600,
+ height: 10,
+ width: 10
+ });
+
+ var el = $('<div></div>').dialog({
+ position: {
+ my: "left top",
+ at: "top left",
+ of: parent
+ }
+ });
+
+ var dialog = el.closest('.ui-dialog');
+ var offset = dialog.offset();
+ var parentOffset = parent.offset();
+
+ same(offset.left, parentOffset.left);
+ same(offset.top, parentOffset.top);
+
+ el.dialog('option', 'position', {
+ my: "left top",
+ at: "right bottom",
+ of: parent
+ });
+
+ same(offset.left, parentOffset.left + parent.outerWidth());
+ same(offset.top, parentOffset.top + parent.outerHeight());
+
+ el.remove();
+ parent.remove();
+});
+
+
test("position, others", function() {
ok(false, 'missing test - untested code is broken code');
});