Skip to content
Permalink
Browse files

Dev: clean up dialog test suite with new helper methods. Fixes #8803 …

…- Dev: re-enable the dialog test suite
  • Loading branch information
mikesherov committed Nov 9, 2012
1 parent fd48568 commit 543abc9b1ff6cafdea7cd1be5835f04104cdb8da
@@ -14,7 +14,7 @@ var versions = {
"Button": "button/button.html",
"Core": "core/core.html",
//"Datepicker": "datepicker/datepicker.html",
//"Dialog": "dialog/dialog.html",
"Dialog": "dialog/dialog.html",
"Draggable": "draggable/draggable.html",
"Droppable": "droppable/droppable.html",
"Effects": "effects/effects.html",
@@ -14,6 +14,7 @@
"unused": true,
"predef": [
"asyncTest",
"closeEnough",
"deepEqual",
"domEqual",
"equal",
@@ -21,7 +21,7 @@
"button/button.html",
"core/core.html",
//"datepicker/datepicker.html",
//"dialog/dialog.html",
"dialog/dialog.html",
"draggable/draggable.html",
"droppable/droppable.html",
"effects/effects.html",
@@ -208,17 +208,17 @@ test("maxHeight", function() {

var el = $('<div></div>').dialog({ maxHeight: 200 });
TestHelpers.dialog.drag(el, '.ui-resizable-s', 1000, 1000);
equal(el.dialog('widget').height(), 200, "maxHeight");
closeEnough(el.dialog('widget').height(), 200, 1, "maxHeight");
el.remove();

el = $('<div></div>').dialog({ maxHeight: 200 });
TestHelpers.dialog.drag(el, '.ui-resizable-n', -1000, -1000);
equal(el.dialog('widget').height(), 200, "maxHeight");
closeEnough(el.dialog('widget').height(), 200, 1, "maxHeight");
el.remove();

el = $('<div></div>').dialog({ maxHeight: 200 }).dialog('option', 'maxHeight', 300);
TestHelpers.dialog.drag(el, '.ui-resizable-s', 1000, 1000);
equal(el.dialog('widget').height(), 300, "maxHeight");
closeEnough(el.dialog('widget').height(), 300, 1, "maxHeight");
el.remove();
});

@@ -227,17 +227,17 @@ test("maxWidth", function() {

var el = $('<div></div>').dialog({ maxWidth: 200 });
TestHelpers.dialog.drag(el, '.ui-resizable-e', 1000, 1000);
equal(el.dialog('widget').width(), 200, "maxWidth");
closeEnough(el.dialog('widget').width(), 200, 1, "maxWidth");
el.remove();

el = $('<div></div>').dialog({ maxWidth: 200 });
TestHelpers.dialog.drag(el, '.ui-resizable-w', -1000, -1000);
equal(el.dialog('widget').width(), 200, "maxWidth");
closeEnough(el.dialog('widget').width(), 200, 1, "maxWidth");
el.remove();

el = $('<div></div>').dialog({ maxWidth: 200 }).dialog('option', 'maxWidth', 300);
TestHelpers.dialog.drag(el, '.ui-resizable-w', -1000, -1000);
equal(el.dialog('widget').width(), 300, "maxWidth");
closeEnough(el.dialog('widget').width(), 300, 1, "maxWidth");
el.remove();
});

@@ -246,17 +246,17 @@ test("minHeight", function() {

var el = $('<div></div>').dialog({ minHeight: 10 });
TestHelpers.dialog.drag(el, '.ui-resizable-s', -1000, -1000);
equal(el.dialog('widget').height(), 10, "minHeight");
closeEnough(el.dialog('widget').height(), 10, 1, "minHeight");
el.remove();

el = $('<div></div>').dialog({ minHeight: 10 });
TestHelpers.dialog.drag(el, '.ui-resizable-n', 1000, 1000);
equal(el.dialog('widget').height(), 10, "minHeight");
closeEnough(el.dialog('widget').height(), 10, 1, "minHeight");
el.remove();

el = $('<div></div>').dialog({ minHeight: 10 }).dialog('option', 'minHeight', 30);
TestHelpers.dialog.drag(el, '.ui-resizable-n', 1000, 1000);
equal(el.dialog('widget').height(), 30, "minHeight");
closeEnough(el.dialog('widget').height(), 30, 1, "minHeight");
el.remove();
});

@@ -265,17 +265,17 @@ test("minWidth", function() {

var el = $('<div></div>').dialog({ minWidth: 10 });
TestHelpers.dialog.drag(el, '.ui-resizable-e', -1000, -1000);
equal(el.dialog('widget').width(), 10, "minWidth");
closeEnough(el.dialog('widget').width(), 10, 1, "minWidth");
el.remove();

el = $('<div></div>').dialog({ minWidth: 10 });
TestHelpers.dialog.drag(el, '.ui-resizable-w', 1000, 1000);
equal(el.dialog('widget').width(), 10, "minWidth");
closeEnough(el.dialog('widget').width(), 10, 1, "minWidth");
el.remove();

el = $('<div></div>').dialog({ minWidth: 30 }).dialog('option', 'minWidth', 30);
TestHelpers.dialog.drag(el, '.ui-resizable-w', 1000, 1000);
equal(el.dialog('widget').width(), 30, "minWidth");
closeEnough(el.dialog('widget').width(), 30, 1, "minWidth");
el.remove();
});

@@ -284,8 +284,8 @@ test("position, default center on window", function() {
var el = $('<div></div>').dialog(),
dialog = el.dialog('widget'),
offset = dialog.offset();
deepEqual(offset.left, Math.round($(window).width() / 2 - dialog.outerWidth() / 2) + $(window).scrollLeft());
deepEqual(offset.top, Math.round($(window).height() / 2 - dialog.outerHeight() / 2) + $(window).scrollTop());
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);
el.remove();
});

@@ -294,8 +294,8 @@ test("position, top on window", function() {
var el = $('<div></div>').dialog({ position: "top" }),
dialog = el.dialog('widget'),
offset = dialog.offset();
deepEqual(offset.left, Math.round($(window).width() / 2 - dialog.outerWidth() / 2) + $(window).scrollLeft());
deepEqual(offset.top, $(window).scrollTop());
closeEnough(offset.left, Math.round($(window).width() / 2 - dialog.outerWidth() / 2) + $(window).scrollLeft(), 1);
closeEnough(offset.top, $(window).scrollTop(), 1);
el.remove();
});

@@ -304,54 +304,59 @@ test("position, left on window", function() {
var el = $('<div></div>').dialog({ position: "left" }),
dialog = el.dialog('widget'),
offset = dialog.offset();
deepEqual(offset.left, 0);
deepEqual(offset.top, Math.round($(window).height() / 2 - dialog.outerHeight() / 2) + $(window).scrollTop());
closeEnough(offset.left, 0, 1);
closeEnough(offset.top, Math.round($(window).height() / 2 - dialog.outerHeight() / 2) + $(window).scrollTop(), 1);
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();
deepEqual(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft());
deepEqual(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop());
el.remove();
});
// todo: figure out these fails in IE7
if ( !$.ui.ie ) {

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 w/array", function() {
expect( 2 );
var el = $('<div></div>').dialog({ position: ["right", "bottom"] }),
dialog = el.dialog('widget'),
offset = dialog.offset();
deepEqual(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft());
deepEqual(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop());
el.remove();
});
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 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();

closeEnough(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft(), 1);
closeEnough(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop(), 1);
el.remove();
});

}

test("position, offset from top left w/array", function() {
expect( 2 );
var el = $('<div></div>').dialog({ position: [10, 10] }),
dialog = el.dialog('widget'),
offset = dialog.offset();
deepEqual(offset.left, 10 + $(window).scrollLeft());
deepEqual(offset.top, 10 + $(window).scrollTop());
el.remove();
});

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();

deepEqual(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft());
deepEqual(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop());
closeEnough(offset.left, 10 + $(window).scrollLeft(), 1);
closeEnough(offset.top, 10 + $(window).scrollTop(), 1);
el.remove();
});

@@ -448,13 +453,13 @@ test("width", function() {
expect(3);

var el = $('<div></div>').dialog();
equal(el.dialog('widget').width(), 300, "default width");
closeEnough(el.dialog('widget').width(), 300, 1, "default width");
el.remove();

el = $('<div></div>').dialog({width: 437 });
equal(el.dialog('widget').width(), 437, "explicit width");
closeEnough(el.dialog('widget').width(), 437, 1, "explicit width");
el.dialog('option', 'width', 438);
equal(el.dialog('widget').width(), 438, 'explicit width after init');
closeEnough(el.dialog('widget').width(), 438, 1, 'explicit width after init');
el.remove();
});

@@ -12,7 +12,7 @@ test("element types", function() {
',acronym,code,samp,kbd,var,img,hr' +
',input,button,label,select,iframe').split(',');

expect( typeNames.length );
expect( typeNames.length * 2 );

$.each(typeNames, function(i) {
var offsetBefore, offsetAfter,
@@ -25,7 +25,8 @@ test("element types", function() {
TestHelpers.draggable.drag(el, 50, 50);
offsetAfter = el.offset();
// there are some rounding errors in FF, Chrome, and IE9, so we can't say equal, we have to settle for close enough
ok( offsetAfter.left - offsetBefore.left - 50 <= 1 && offsetAfter.top - offsetBefore.top - 50 <= 1, "dragged[50, 50] " + "&lt;" + typeName + "&gt;" );
closeEnough(offsetBefore.left, offsetAfter.left - 50, 1, "dragged[50, 50] " + "<" + typeName + ">");
closeEnough(offsetBefore.top, offsetAfter.top - 50, 1, "dragged[50, 50] " + "<" + typeName + ">");
el.draggable("destroy");
el.remove();
});
@@ -169,6 +169,14 @@ TestHelpers.commonWidgetTests = function( widget, settings ) {
});
};

/*
* Taken from https://github.com/jquery/qunit/tree/master/addons/close-enough
*/
window.closeEnough = function( actual, expected, maxDifference, message ) {
var passes = (actual === expected) || Math.abs(actual - expected) <= maxDifference;
QUnit.push(passes, actual, expected, message);
};

/*
* Experimental assertion for comparing DOM objects.
*

0 comments on commit 543abc9

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