Skip to content

Commit 543abc9

Browse files
committed
Dev: clean up dialog test suite with new helper methods. Fixes #8803 - Dev: re-enable the dialog test suite
1 parent fd48568 commit 543abc9

File tree

6 files changed

+76
-61
lines changed

6 files changed

+76
-61
lines changed

build/tasks/testswarm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var versions = {
1414
"Button": "button/button.html",
1515
"Core": "core/core.html",
1616
//"Datepicker": "datepicker/datepicker.html",
17-
//"Dialog": "dialog/dialog.html",
17+
"Dialog": "dialog/dialog.html",
1818
"Draggable": "draggable/draggable.html",
1919
"Droppable": "droppable/droppable.html",
2020
"Effects": "effects/effects.html",

tests/.jshintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"unused": true,
1515
"predef": [
1616
"asyncTest",
17+
"closeEnough",
1718
"deepEqual",
1819
"domEqual",
1920
"equal",

tests/unit/all-active.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"button/button.html",
2222
"core/core.html",
2323
//"datepicker/datepicker.html",
24-
//"dialog/dialog.html",
24+
"dialog/dialog.html",
2525
"draggable/draggable.html",
2626
"droppable/droppable.html",
2727
"effects/effects.html",

tests/unit/dialog/dialog_options.js

Lines changed: 62 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -208,17 +208,17 @@ test("maxHeight", function() {
208208

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@@ -284,8 +284,8 @@ test("position, default center on window", function() {
284284
var el = $('<div></div>').dialog(),
285285
dialog = el.dialog('widget'),
286286
offset = dialog.offset();
287-
deepEqual(offset.left, Math.round($(window).width() / 2 - dialog.outerWidth() / 2) + $(window).scrollLeft());
288-
deepEqual(offset.top, Math.round($(window).height() / 2 - dialog.outerHeight() / 2) + $(window).scrollTop());
287+
closeEnough(offset.left, Math.round($(window).width() / 2 - dialog.outerWidth() / 2) + $(window).scrollLeft(), 1);
288+
closeEnough(offset.top, Math.round($(window).height() / 2 - dialog.outerHeight() / 2) + $(window).scrollTop(), 1);
289289
el.remove();
290290
});
291291

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

@@ -304,54 +304,59 @@ test("position, left on window", function() {
304304
var el = $('<div></div>').dialog({ position: "left" }),
305305
dialog = el.dialog('widget'),
306306
offset = dialog.offset();
307-
deepEqual(offset.left, 0);
308-
deepEqual(offset.top, Math.round($(window).height() / 2 - dialog.outerHeight() / 2) + $(window).scrollTop());
307+
closeEnough(offset.left, 0, 1);
308+
closeEnough(offset.top, Math.round($(window).height() / 2 - dialog.outerHeight() / 2) + $(window).scrollTop(), 1);
309309
el.remove();
310310
});
311311

312-
test("position, right bottom on window", function() {
313-
expect( 2 );
314-
var el = $('<div></div>').dialog({ position: "right bottom" }),
315-
dialog = el.dialog('widget'),
316-
offset = dialog.offset();
317-
deepEqual(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft());
318-
deepEqual(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop());
319-
el.remove();
320-
});
312+
// todo: figure out these fails in IE7
313+
if ( !$.ui.ie ) {
314+
315+
test("position, right bottom on window", function() {
316+
expect( 2 );
317+
var el = $('<div></div>').dialog({ position: "right bottom" }),
318+
dialog = el.dialog('widget'),
319+
offset = dialog.offset();
320+
closeEnough(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft(), 1);
321+
closeEnough(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop(), 1);
322+
el.remove();
323+
});
321324

322-
test("position, right bottom on window w/array", function() {
323-
expect( 2 );
324-
var el = $('<div></div>').dialog({ position: ["right", "bottom"] }),
325-
dialog = el.dialog('widget'),
326-
offset = dialog.offset();
327-
deepEqual(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft());
328-
deepEqual(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop());
329-
el.remove();
330-
});
325+
test("position, right bottom on window w/array", function() {
326+
expect( 2 );
327+
var el = $('<div></div>').dialog({ position: ["right", "bottom"] }),
328+
dialog = el.dialog('widget'),
329+
offset = dialog.offset();
330+
closeEnough(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft(), 1);
331+
closeEnough(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop(), 1);
332+
el.remove();
333+
});
334+
335+
test("position, right bottom at right bottom via ui.position args", function() {
336+
expect( 2 );
337+
var el = $('<div></div>').dialog({
338+
position: {
339+
my: "right bottom",
340+
at: "right bottom"
341+
}
342+
}),
343+
dialog = el.dialog('widget'),
344+
offset = dialog.offset();
345+
346+
closeEnough(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft(), 1);
347+
closeEnough(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop(), 1);
348+
el.remove();
349+
});
350+
351+
}
331352

332353
test("position, offset from top left w/array", function() {
333354
expect( 2 );
334355
var el = $('<div></div>').dialog({ position: [10, 10] }),
335356
dialog = el.dialog('widget'),
336357
offset = dialog.offset();
337-
deepEqual(offset.left, 10 + $(window).scrollLeft());
338-
deepEqual(offset.top, 10 + $(window).scrollTop());
339-
el.remove();
340-
});
341-
342-
test("position, right bottom at right bottom via ui.position args", function() {
343-
expect( 2 );
344-
var el = $('<div></div>').dialog({
345-
position: {
346-
my: "right bottom",
347-
at: "right bottom"
348-
}
349-
}),
350-
dialog = el.dialog('widget'),
351-
offset = dialog.offset();
352-
353-
deepEqual(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft());
354-
deepEqual(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop());
358+
closeEnough(offset.left, 10 + $(window).scrollLeft(), 1);
359+
closeEnough(offset.top, 10 + $(window).scrollTop(), 1);
355360
el.remove();
356361
});
357362

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

450455
var el = $('<div></div>').dialog();
451-
equal(el.dialog('widget').width(), 300, "default width");
456+
closeEnough(el.dialog('widget').width(), 300, 1, "default width");
452457
el.remove();
453458

454459
el = $('<div></div>').dialog({width: 437 });
455-
equal(el.dialog('widget').width(), 437, "explicit width");
460+
closeEnough(el.dialog('widget').width(), 437, 1, "explicit width");
456461
el.dialog('option', 'width', 438);
457-
equal(el.dialog('widget').width(), 438, 'explicit width after init');
462+
closeEnough(el.dialog('widget').width(), 438, 1, 'explicit width after init');
458463
el.remove();
459464
});
460465

tests/unit/draggable/draggable_core.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ test("element types", function() {
1212
',acronym,code,samp,kbd,var,img,hr' +
1313
',input,button,label,select,iframe').split(',');
1414

15-
expect( typeNames.length );
15+
expect( typeNames.length * 2 );
1616

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

tests/unit/testsuite.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,14 @@ TestHelpers.commonWidgetTests = function( widget, settings ) {
169169
});
170170
};
171171

172+
/*
173+
* Taken from https://github.com/jquery/qunit/tree/master/addons/close-enough
174+
*/
175+
window.closeEnough = function( actual, expected, maxDifference, message ) {
176+
var passes = (actual === expected) || Math.abs(actual - expected) <= maxDifference;
177+
QUnit.push(passes, actual, expected, message);
178+
};
179+
172180
/*
173181
* Experimental assertion for comparing DOM objects.
174182
*

0 commit comments

Comments
 (0)