Skip to content
Permalink
Browse files

Dialog: Fixed tests for position option.

  • Loading branch information...
scottgonzalez committed Jul 16, 2010
1 parent 0536811 commit 2366a81740cab689161d4072ee2f5bf1cd9fcf65
Showing with 22 additions and 26 deletions.
  1. +22 −26 tests/unit/dialog/dialog_options.js
@@ -242,25 +242,25 @@ test("modal", function() {

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?
var dialog = el.dialog('widget');
var offset = dialog.offset();
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 dialog = el.dialog('widget');
var offset = dialog.offset();
same(offset.left, Math.floor($(window).width() / 2 - dialog.outerWidth() / 2));
same(offset.left, Math.floor($(window).width() / 2 - dialog.outerWidth() / 2) + $(window).scrollLeft());
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 dialog = el.dialog('widget');
var offset = dialog.offset();
same(offset.left, 0);
same(offset.top, Math.floor($(window).height() / 2 - dialog.outerHeight() / 2) + $(window).scrollTop());
@@ -269,27 +269,27 @@ test("position, left on window", function() {

test("position, right bottom on window", function() {
var el = $('<div></div>').dialog({ position: "right bottom" });
var dialog = el.closest('.ui-dialog');
var dialog = el.dialog('widget');
var offset = dialog.offset();
same(offset.left, $(window).width() - dialog.outerWidth());
same(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft());
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 dialog = el.dialog('widget');
var offset = dialog.offset();
same(offset.left, $(window).width() - dialog.outerWidth());
same(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft());
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 dialog = el.dialog('widget');
var offset = dialog.offset();
same(offset.left, 10);
same(offset.left, 10 + $(window).scrollLeft());
same(offset.top, 10 + $(window).scrollTop());
el.remove();
});
@@ -302,10 +302,10 @@ test("position, right bottom at right bottom via ui.position args", function() {
}
});

var dialog = el.closest('.ui-dialog');
var dialog = el.dialog('widget');
var offset = dialog.offset();

same(offset.left, $(window).width() - dialog.outerWidth());
same(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft());
same(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop());
el.remove();
});
@@ -317,41 +317,37 @@ test("position, at another element", function() {
left: 600,
height: 10,
width: 10
});
}).appendTo('body');

var el = $('<div></div>').dialog({
position: {
my: "left top",
at: "top left",
at: "left top",
of: parent
}
});

var dialog = el.closest('.ui-dialog');
var dialog = el.dialog('widget');
var offset = dialog.offset();
var parentOffset = parent.offset();

same(offset.left, parentOffset.left);
same(offset.top, parentOffset.top);
same(offset.left, 600);
same(offset.top, 400);

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());
var offset = dialog.offset();

same(offset.left, 610);
same(offset.top, 410);

el.remove();
parent.remove();
});


test("position, others", function() {
ok(false, 'missing test - untested code is broken code');
});

test("resizable", function() {
expect(4);

0 comments on commit 2366a81

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