diff options
author | Mike Sherov <mike.sherov@gmail.com> | 2012-12-22 15:46:57 -0500 |
---|---|---|
committer | Mike Sherov <mike.sherov@gmail.com> | 2012-12-22 15:46:57 -0500 |
commit | 6d88d264be5800badd9fc083ccc238ca187bd953 (patch) | |
tree | 05f8d1a93a253b1a57e519c7dbdbc3208a529726 | |
parent | 48d7d53f7b04e202e32a47aa0665f83a1179b723 (diff) | |
download | jquery-ui-6d88d264be5800badd9fc083ccc238ca187bd953.tar.gz jquery-ui-6d88d264be5800badd9fc083ccc238ca187bd953.zip |
Dialog Tests: Fix test fails due to window measurements in FF and IE7
-rw-r--r-- | tests/unit/dialog/dialog_deprecated.js | 50 | ||||
-rw-r--r-- | tests/unit/dialog/dialog_options.js | 77 | ||||
-rw-r--r-- | tests/unit/dialog/dialog_test_helpers.js | 8 |
3 files changed, 78 insertions, 57 deletions
diff --git a/tests/unit/dialog/dialog_deprecated.js b/tests/unit/dialog/dialog_deprecated.js index fcbd22faa..918190791 100644 --- a/tests/unit/dialog/dialog_deprecated.js +++ b/tests/unit/dialog/dialog_deprecated.js @@ -1,26 +1,36 @@ module("dialog (deprecated): position option with string and array"); -if ( !$.ui.ie ) { - test("position, right bottom on window w/array", function() { - expect( 2 ); - var el = $('<div></div>').dialog({ position: ["right", "bottom"] }), - dialog = el.dialog('widget'), - offset = dialog.offset(); - closeEnough(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft(), 1); - closeEnough(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop(), 1); - el.remove(); - }); +test( "position, right bottom on window w/array", function() { + expect( 2 ); + + // dialogs alter the window width and height in FF and IE7 + // so we collect that information before creating the dialog + // Support: FF, IE7 + var winWidth = $( window ).width(), + winHeight = $( window ).height(), + el = $("<div></div>").dialog({ position: [ "right", "bottom" ] }), + dialog = el.dialog("widget"), + offset = dialog.offset(); + closeEnough( offset.left, winWidth - dialog.outerWidth() + $( window ).scrollLeft(), 1, "offset left of right bottom on window w/array" ); + closeEnough( offset.top, winHeight - dialog.outerHeight() + $( window ).scrollTop(), 1, "offset top of right bottom on window w/array" ); + el.remove(); +}); - test("position, right bottom on window", function() { - expect( 2 ); - var el = $('<div></div>').dialog({ position: "right bottom" }), - dialog = el.dialog('widget'), - offset = dialog.offset(); - closeEnough(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft(), 1); - closeEnough(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop(), 1); - el.remove(); - }); -} +test( "position, right bottom on window", function() { + expect( 2 ); + + // dialogs alter the window width and height in FF and IE7 + // so we collect that information before creating the dialog + // Support: FF, IE7 + var winWidth = $( window ).width(), + winHeight = $( window ).height(), + el = $("<div></div>").dialog({ position: "right bottom" }), + dialog = el.dialog("widget"), + offset = dialog.offset(); + closeEnough( offset.left, winWidth - dialog.outerWidth() + $( window ).scrollLeft(), 1, "offset left of right bottom on window" ); + closeEnough( offset.top, winHeight - dialog.outerHeight() + $( window ).scrollTop(), 1, "offset top of right bottom on window" ); + el.remove(); +}); test("position, offset from top left w/array", function() { expect( 2 ); diff --git a/tests/unit/dialog/dialog_options.js b/tests/unit/dialog/dialog_options.js index 2ccbed573..dff3ffaae 100644 --- a/tests/unit/dialog/dialog_options.js +++ b/tests/unit/dialog/dialog_options.js @@ -338,36 +338,45 @@ test("minWidth", function() { el.remove(); }); -test("position, default center on window", function() { +test( "position, default center on window", function() { expect( 2 ); - var el = $('<div></div>').dialog(), - dialog = el.dialog('widget'), + + // dialogs alter the window width and height in FF and IE7 + // so we collect that information before creating the dialog + // Support: FF, IE7 + var winWidth = $( window ).width(), + winHeight = $( window ).height(), + el = $("<div></div>").dialog(), + dialog = el.dialog("widget"), offset = dialog.offset(); - closeEnough(offset.left, Math.round($(window).width() / 2 - dialog.outerWidth() / 2) + $(window).scrollLeft(), 1); - closeEnough(offset.top, Math.round($(window).height() / 2 - dialog.outerHeight() / 2) + $(window).scrollTop(), 1); + closeEnough( offset.left, Math.round( winWidth / 2 - dialog.outerWidth() / 2 ) + $( window ).scrollLeft(), 1, "dialog left position of center on window on initilization" ); + closeEnough( offset.top, Math.round( winHeight / 2 - dialog.outerHeight() / 2 ) + $( window ).scrollTop(), 1, "dialog top position of center on window on initilization" ); el.remove(); }); -// todo: figure out these fails in IE7 -if ( !$.ui.ie ) { - test("position, right bottom at right bottom via ui.position args", function() { - expect( 2 ); - var el = $('<div></div>').dialog({ - position: { - my: "right bottom", - at: "right bottom" - } - }), - dialog = el.dialog('widget'), - offset = dialog.offset(); +test( "position, right bottom at right bottom via ui.position args", function() { + expect( 2 ); - closeEnough(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft(), 1); - closeEnough(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop(), 1); - el.remove(); - }); -} + // dialogs alter the window width and height in FF and IE7 + // so we collect that information before creating the dialog + // Support: FF, IE7 + var winWidth = $( window ).width(), + winHeight = $( window ).height(), + el = $("<div></div>").dialog({ + position: { + my: "right bottom", + at: "right bottom" + } + }), + dialog = el.dialog("widget"), + offset = dialog.offset(); + + closeEnough( offset.left, winWidth - dialog.outerWidth() + $( window ).scrollLeft(), 1, "dialog left position of right bottom at right bottom on initilization" ); + closeEnough( offset.top, winHeight - dialog.outerHeight() + $( window ).scrollTop(), 1, "dialog top position of right bottom at right bottom on initilization" ); + el.remove(); +}); -test("position, at another element", function() { +test( "position, at another element", function() { expect( 4 ); var parent = $('<div></div>').css({ position: 'absolute', @@ -375,32 +384,34 @@ test("position, at another element", function() { left: 600, height: 10, width: 10 - }).appendTo('body'), + }).appendTo("body"), - el = $('<div></div>').dialog({ + el = $("<div></div>").dialog({ position: { my: "left top", at: "left top", - of: parent + of: parent, + collision: "none" } }), - dialog = el.dialog('widget'), + dialog = el.dialog("widget"), offset = dialog.offset(); - deepEqual(offset.left, 600); - deepEqual(offset.top, 400); + closeEnough( offset.left, 600, 1, "dialog left position at another element on initilization" ); + closeEnough( offset.top, 400, 1, "dialog top position at another element on initilization" ); - el.dialog('option', 'position', { + el.dialog("option", "position", { my: "left top", at: "right bottom", - of: parent + of: parent, + collision: "none" }); offset = dialog.offset(); - deepEqual(offset.left, 610); - deepEqual(offset.top, 410); + closeEnough( offset.left, 610, 1, "dialog left position at another element via setting option" ); + closeEnough( offset.top, 410, 1, "dialog top position at another element via setting option" ); el.remove(); parent.remove(); diff --git a/tests/unit/dialog/dialog_test_helpers.js b/tests/unit/dialog/dialog_test_helpers.js index ef0b9b6fa..e104ed63f 100644 --- a/tests/unit/dialog/dialog_test_helpers.js +++ b/tests/unit/dialog/dialog_test_helpers.js @@ -9,7 +9,7 @@ TestHelpers.dialog = { }); }, testDrag: function(el, dx, dy, expectedDX, expectedDY, msg) { - var actual, expected, offsetAfter, + var actualDX, actualDY, offsetAfter, d = el.dialog('widget'), handle = $(".ui-dialog-titlebar", d), offsetBefore = d.offset(); @@ -20,9 +20,9 @@ TestHelpers.dialog = { msg = msg ? msg + "." : ""; - actual = { left: Math.round(offsetAfter.left), top: Math.round(offsetAfter.top) }, - expected = { left: Math.round(offsetBefore.left + expectedDX), top: Math.round(offsetBefore.top + expectedDY) }; - deepEqual(actual, expected, 'dragged[' + expectedDX + ', ' + expectedDY + '] ' + msg); + actualDX = offsetAfter.left - offsetBefore.left; + actualDY = offsetAfter.top - offsetBefore.top; + ok( expectedDX - actualDX <= 1 && expectedDY - actualDY <= 1, 'dragged[' + expectedDX + ', ' + expectedDY + '] ' + msg); }, shouldResize: function(el, dw, dh, msg) { var heightAfter, widthAfter, actual, expected, |