Skip to content

Commit 6d88d26

Browse files
committed
Dialog Tests: Fix test fails due to window measurements in FF and IE7
1 parent 48d7d53 commit 6d88d26

File tree

3 files changed

+78
-57
lines changed

3 files changed

+78
-57
lines changed

tests/unit/dialog/dialog_deprecated.js

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,36 @@
11
module("dialog (deprecated): position option with string and array");
22

3-
if ( !$.ui.ie ) {
4-
test("position, right bottom on window w/array", function() {
5-
expect( 2 );
6-
var el = $('<div></div>').dialog({ position: ["right", "bottom"] }),
7-
dialog = el.dialog('widget'),
8-
offset = dialog.offset();
9-
closeEnough(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft(), 1);
10-
closeEnough(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop(), 1);
11-
el.remove();
12-
});
3+
test( "position, right bottom on window w/array", function() {
4+
expect( 2 );
5+
6+
// dialogs alter the window width and height in FF and IE7
7+
// so we collect that information before creating the dialog
8+
// Support: FF, IE7
9+
var winWidth = $( window ).width(),
10+
winHeight = $( window ).height(),
11+
el = $("<div></div>").dialog({ position: [ "right", "bottom" ] }),
12+
dialog = el.dialog("widget"),
13+
offset = dialog.offset();
14+
closeEnough( offset.left, winWidth - dialog.outerWidth() + $( window ).scrollLeft(), 1, "offset left of right bottom on window w/array" );
15+
closeEnough( offset.top, winHeight - dialog.outerHeight() + $( window ).scrollTop(), 1, "offset top of right bottom on window w/array" );
16+
el.remove();
17+
});
1318

14-
test("position, right bottom on window", function() {
15-
expect( 2 );
16-
var el = $('<div></div>').dialog({ position: "right bottom" }),
17-
dialog = el.dialog('widget'),
18-
offset = dialog.offset();
19-
closeEnough(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft(), 1);
20-
closeEnough(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop(), 1);
21-
el.remove();
22-
});
23-
}
19+
test( "position, right bottom on window", function() {
20+
expect( 2 );
21+
22+
// dialogs alter the window width and height in FF and IE7
23+
// so we collect that information before creating the dialog
24+
// Support: FF, IE7
25+
var winWidth = $( window ).width(),
26+
winHeight = $( window ).height(),
27+
el = $("<div></div>").dialog({ position: "right bottom" }),
28+
dialog = el.dialog("widget"),
29+
offset = dialog.offset();
30+
closeEnough( offset.left, winWidth - dialog.outerWidth() + $( window ).scrollLeft(), 1, "offset left of right bottom on window" );
31+
closeEnough( offset.top, winHeight - dialog.outerHeight() + $( window ).scrollTop(), 1, "offset top of right bottom on window" );
32+
el.remove();
33+
});
2434

2535
test("position, offset from top left w/array", function() {
2636
expect( 2 );

tests/unit/dialog/dialog_options.js

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -338,69 +338,80 @@ test("minWidth", function() {
338338
el.remove();
339339
});
340340

341-
test("position, default center on window", function() {
341+
test( "position, default center on window", function() {
342342
expect( 2 );
343-
var el = $('<div></div>').dialog(),
344-
dialog = el.dialog('widget'),
343+
344+
// dialogs alter the window width and height in FF and IE7
345+
// so we collect that information before creating the dialog
346+
// Support: FF, IE7
347+
var winWidth = $( window ).width(),
348+
winHeight = $( window ).height(),
349+
el = $("<div></div>").dialog(),
350+
dialog = el.dialog("widget"),
345351
offset = dialog.offset();
346-
closeEnough(offset.left, Math.round($(window).width() / 2 - dialog.outerWidth() / 2) + $(window).scrollLeft(), 1);
347-
closeEnough(offset.top, Math.round($(window).height() / 2 - dialog.outerHeight() / 2) + $(window).scrollTop(), 1);
352+
closeEnough( offset.left, Math.round( winWidth / 2 - dialog.outerWidth() / 2 ) + $( window ).scrollLeft(), 1, "dialog left position of center on window on initilization" );
353+
closeEnough( offset.top, Math.round( winHeight / 2 - dialog.outerHeight() / 2 ) + $( window ).scrollTop(), 1, "dialog top position of center on window on initilization" );
348354
el.remove();
349355
});
350356

351-
// todo: figure out these fails in IE7
352-
if ( !$.ui.ie ) {
353-
test("position, right bottom at right bottom via ui.position args", function() {
354-
expect( 2 );
355-
var el = $('<div></div>').dialog({
356-
position: {
357-
my: "right bottom",
358-
at: "right bottom"
359-
}
360-
}),
361-
dialog = el.dialog('widget'),
362-
offset = dialog.offset();
357+
test( "position, right bottom at right bottom via ui.position args", function() {
358+
expect( 2 );
363359

364-
closeEnough(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft(), 1);
365-
closeEnough(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop(), 1);
366-
el.remove();
367-
});
368-
}
360+
// dialogs alter the window width and height in FF and IE7
361+
// so we collect that information before creating the dialog
362+
// Support: FF, IE7
363+
var winWidth = $( window ).width(),
364+
winHeight = $( window ).height(),
365+
el = $("<div></div>").dialog({
366+
position: {
367+
my: "right bottom",
368+
at: "right bottom"
369+
}
370+
}),
371+
dialog = el.dialog("widget"),
372+
offset = dialog.offset();
373+
374+
closeEnough( offset.left, winWidth - dialog.outerWidth() + $( window ).scrollLeft(), 1, "dialog left position of right bottom at right bottom on initilization" );
375+
closeEnough( offset.top, winHeight - dialog.outerHeight() + $( window ).scrollTop(), 1, "dialog top position of right bottom at right bottom on initilization" );
376+
el.remove();
377+
});
369378

370-
test("position, at another element", function() {
379+
test( "position, at another element", function() {
371380
expect( 4 );
372381
var parent = $('<div></div>').css({
373382
position: 'absolute',
374383
top: 400,
375384
left: 600,
376385
height: 10,
377386
width: 10
378-
}).appendTo('body'),
387+
}).appendTo("body"),
379388

380-
el = $('<div></div>').dialog({
389+
el = $("<div></div>").dialog({
381390
position: {
382391
my: "left top",
383392
at: "left top",
384-
of: parent
393+
of: parent,
394+
collision: "none"
385395
}
386396
}),
387397

388-
dialog = el.dialog('widget'),
398+
dialog = el.dialog("widget"),
389399
offset = dialog.offset();
390400

391-
deepEqual(offset.left, 600);
392-
deepEqual(offset.top, 400);
401+
closeEnough( offset.left, 600, 1, "dialog left position at another element on initilization" );
402+
closeEnough( offset.top, 400, 1, "dialog top position at another element on initilization" );
393403

394-
el.dialog('option', 'position', {
404+
el.dialog("option", "position", {
395405
my: "left top",
396406
at: "right bottom",
397-
of: parent
407+
of: parent,
408+
collision: "none"
398409
});
399410

400411
offset = dialog.offset();
401412

402-
deepEqual(offset.left, 610);
403-
deepEqual(offset.top, 410);
413+
closeEnough( offset.left, 610, 1, "dialog left position at another element via setting option" );
414+
closeEnough( offset.top, 410, 1, "dialog top position at another element via setting option" );
404415

405416
el.remove();
406417
parent.remove();

tests/unit/dialog/dialog_test_helpers.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ TestHelpers.dialog = {
99
});
1010
},
1111
testDrag: function(el, dx, dy, expectedDX, expectedDY, msg) {
12-
var actual, expected, offsetAfter,
12+
var actualDX, actualDY, offsetAfter,
1313
d = el.dialog('widget'),
1414
handle = $(".ui-dialog-titlebar", d),
1515
offsetBefore = d.offset();
@@ -20,9 +20,9 @@ TestHelpers.dialog = {
2020

2121
msg = msg ? msg + "." : "";
2222

23-
actual = { left: Math.round(offsetAfter.left), top: Math.round(offsetAfter.top) },
24-
expected = { left: Math.round(offsetBefore.left + expectedDX), top: Math.round(offsetBefore.top + expectedDY) };
25-
deepEqual(actual, expected, 'dragged[' + expectedDX + ', ' + expectedDY + '] ' + msg);
23+
actualDX = offsetAfter.left - offsetBefore.left;
24+
actualDY = offsetAfter.top - offsetBefore.top;
25+
ok( expectedDX - actualDX <= 1 && expectedDY - actualDY <= 1, 'dragged[' + expectedDX + ', ' + expectedDY + '] ' + msg);
2626
},
2727
shouldResize: function(el, dw, dh, msg) {
2828
var heightAfter, widthAfter, actual, expected,

0 commit comments

Comments
 (0)