]> source.dussan.org Git - jquery-ui.git/commitdiff
Dialog Tests: Fix test fails due to window measurements in FF and IE7
authorMike Sherov <mike.sherov@gmail.com>
Sat, 22 Dec 2012 20:46:57 +0000 (15:46 -0500)
committerMike Sherov <mike.sherov@gmail.com>
Sat, 22 Dec 2012 20:46:57 +0000 (15:46 -0500)
tests/unit/dialog/dialog_deprecated.js
tests/unit/dialog/dialog_options.js
tests/unit/dialog/dialog_test_helpers.js

index fcbd22faa677d63cf71384d89f4f774eafea90a3..9181907917c589e1dcb7d29a003b7673f856e5ff 100644 (file)
@@ -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 );
index 2ccbed57303e9a658b9f3efa459969c071e67ef7..dff3ffaae9f2fad77dbc4751a05b6580154bafaf 100644 (file)
@@ -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();
index ef0b9b6fadd96f5f8eb0aa4b43567e04748a828c..e104ed63fa347194ab86a476cbb12d56c45e96bd 100644 (file)
@@ -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,