Tests: Lint.

This commit is contained in:
Scott González 2012-04-19 10:27:06 -04:00
parent 58a120bb4b
commit 0a5a9090f8
11 changed files with 154 additions and 146 deletions

View File

@ -350,27 +350,46 @@ grunt.initConfig({
accordion_state: true, accordion_state: true,
asyncTest: true, asyncTest: true,
commonWidgetTests: true, commonWidgetTests: true,
container: true,
deepEqual: true, deepEqual: true,
d1: true,
d2: true,
dlg: true, dlg: true,
domEqual: true, domEqual: true,
drag: true, drag: true,
dragged: true,
el: true, el: true,
equal: true, equal: true,
expect: true, expect: true,
Globalize: true, Globalize: true,
heightAfter: true,
isNotOpen: true,
isOpen: true,
menu_click: true, menu_click: true,
menu_log: true, menu_log: true,
modal: true,
module: true, module: true,
moved: true,
notEqual: true, notEqual: true,
offsetAfter: true,
offsetBefore: true,
ok: true, ok: true,
QUnit: true, QUnit: true,
restoreScroll: true,
shouldBeDroppable: true,
shouldmove: true,
shouldNotBeDroppable: true,
shouldnotmove: true,
shouldnotresize: true,
shouldresize: true,
spinner_simulateKeyDownUp: true, spinner_simulateKeyDownUp: true,
start: true, start: true,
strictEqual: true, strictEqual: true,
stop: true, stop: true,
tabs_state: true, tabs_state: true,
tabs_disabled: true, tabs_disabled: true,
test: true test: true,
widthAfter: true
} }
} }
}; };

View File

@ -40,8 +40,8 @@ function drag(handle, dx, dy) {
function moved(dx, dy, msg) { function moved(dx, dy, msg) {
msg = msg ? msg + "." : ""; msg = msg ? msg + "." : "";
var actual = { left: Math.round(offsetAfter.left), top: Math.round(offsetAfter.top) }; var actual = { left: Math.round(offsetAfter.left), top: Math.round(offsetAfter.top) },
var expected = { left: Math.round(offsetBefore.left + dx), top: Math.round(offsetBefore.top + dy) }; expected = { left: Math.round(offsetBefore.left + dx), top: Math.round(offsetBefore.top + dy) };
deepEqual(actual, expected, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ' + msg); deepEqual(actual, expected, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ' + msg);
} }
@ -59,8 +59,8 @@ function shouldnotmove(why) {
function resized(dw, dh, msg) { function resized(dw, dh, msg) {
msg = msg ? msg + "." : ""; msg = msg ? msg + "." : "";
var actual = { width: widthAfter, height: heightAfter }; var actual = { width: widthAfter, height: heightAfter },
var expected = { width: widthBefore + dw, height: heightBefore + dh }; expected = { width: widthBefore + dw, height: heightBefore + dh };
deepEqual(actual, expected, 'resized[' + dragged.dx + ', ' + dragged.dy + '] ' + msg); deepEqual(actual, expected, 'resized[' + dragged.dx + ', ' + dragged.dy + '] ' + msg);
} }

View File

@ -63,7 +63,8 @@ test("dragStart", function() {
test("drag", function() { test("drag", function() {
expect(9); expect(9);
var hasDragged = false; var handle,
hasDragged = false;
el = $('<div></div>').dialog({ el = $('<div></div>').dialog({
drag: function(ev, ui) { drag: function(ev, ui) {
@ -83,7 +84,7 @@ test("drag", function() {
ok(ui.position !== undefined, "ui.position in callback"); ok(ui.position !== undefined, "ui.position in callback");
ok(ui.offset !== undefined, "ui.offset in callback"); ok(ui.offset !== undefined, "ui.offset in callback");
}); });
var handle = $(".ui-dialog-titlebar", dlg()); handle = $(".ui-dialog-titlebar", dlg());
drag(handle, 50, 50); drag(handle, 50, 50);
el.remove(); el.remove();
}); });
@ -138,7 +139,8 @@ test("resizeStart", function() {
test("resize", function() { test("resize", function() {
expect(13); expect(13);
var hasResized = false; var handle,
hasResized = false;
el = $('<div></div>').dialog({ el = $('<div></div>').dialog({
resize: function(ev, ui) { resize: function(ev, ui) {
@ -162,7 +164,7 @@ test("resize", function() {
ok(ui.position !== undefined, "ui.position in callback"); ok(ui.position !== undefined, "ui.position in callback");
ok(ui.size !== undefined, "ui.size in callback"); ok(ui.size !== undefined, "ui.size in callback");
}); });
var handle = $(".ui-resizable-se", dlg()); handle = $(".ui-resizable-se", dlg());
drag(handle, 50, 50); drag(handle, 50, 50);
el.remove(); el.remove();
}); });

View File

@ -98,14 +98,17 @@ test("isOpen", function() {
}); });
test("moveToTop", function() { test("moveToTop", function() {
var expected = $('<div></div>').dialog(), var d1, d2, dlg1, dlg2,
expected = $('<div></div>').dialog(),
actual = expected.dialog('moveToTop'); actual = expected.dialog('moveToTop');
equal(actual, expected, 'moveToTop is chainable'); equal(actual, expected, 'moveToTop is chainable');
var d1 = $('<div></div>').dialog(), dlg1 = d1.parents('.ui-dialog'); d1 = $('<div></div>').dialog();
dlg1 = d1.parents('.ui-dialog');
d1.dialog('close'); d1.dialog('close');
d1.dialog('open'); d1.dialog('open');
var d2 = $('<div></div>').dialog(), dlg2 = d2.parents('.ui-dialog'); d2 = $('<div></div>').dialog();
dlg2 = d2.parents('.ui-dialog');
d2.dialog('close'); d2.dialog('close');
d2.dialog('open'); d2.dialog('open');
ok(dlg1.css('zIndex') < dlg2.css('zIndex'), 'dialog 1 under dialog 2 before moveToTop method called'); ok(dlg1.css('zIndex') < dlg2.css('zIndex'), 'dialog 1 under dialog 2 before moveToTop method called');

View File

@ -20,7 +20,8 @@ test("autoOpen", function() {
test("buttons", function() { test("buttons", function() {
expect(21); expect(21);
var buttons = { var btn, i, newButtons,
buttons = {
"Ok": function(ev, ui) { "Ok": function(ev, ui) {
ok(true, "button click fires callback"); ok(true, "button click fires callback");
equal(this, el[0], "context of callback"); equal(this, el[0], "context of callback");
@ -34,10 +35,10 @@ test("buttons", function() {
}; };
el = $('<div></div>').dialog({ buttons: buttons }); el = $('<div></div>').dialog({ buttons: buttons });
var btn = $("button", dlg()); btn = $("button", dlg());
equal(btn.length, 2, "number of buttons"); equal(btn.length, 2, "number of buttons");
var i = 0; i = 0;
$.each(buttons, function(key, val) { $.each(buttons, function(key, val) {
equal(btn.eq(i).text(), key, "text of button " + (i+1)); equal(btn.eq(i).text(), key, "text of button " + (i+1));
i++; i++;
@ -48,7 +49,7 @@ test("buttons", function() {
btn.trigger("click"); btn.trigger("click");
var newButtons = { newButtons = {
"Close": function(ev, ui) { "Close": function(ev, ui) {
ok(true, "button click fires callback"); ok(true, "button click fires callback");
equal(this, el[0], "context of callback"); equal(this, el[0], "context of callback");
@ -275,54 +276,54 @@ test("minWidth", function() {
}); });
test("position, default center on window", function() { test("position, default center on window", function() {
var el = $('<div></div>').dialog(); var el = $('<div></div>').dialog(),
var dialog = el.dialog('widget'); dialog = el.dialog('widget'),
var offset = dialog.offset(); offset = dialog.offset();
deepEqual(offset.left, Math.round($(window).width() / 2 - dialog.outerWidth() / 2) + $(window).scrollLeft()); 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()); deepEqual(offset.top, Math.round($(window).height() / 2 - dialog.outerHeight() / 2) + $(window).scrollTop());
el.remove(); el.remove();
}); });
test("position, top on window", function() { test("position, top on window", function() {
var el = $('<div></div>').dialog({ position: "top" }); var el = $('<div></div>').dialog({ position: "top" }),
var dialog = el.dialog('widget'); dialog = el.dialog('widget'),
var offset = dialog.offset(); offset = dialog.offset();
deepEqual(offset.left, Math.round($(window).width() / 2 - dialog.outerWidth() / 2) + $(window).scrollLeft()); deepEqual(offset.left, Math.round($(window).width() / 2 - dialog.outerWidth() / 2) + $(window).scrollLeft());
deepEqual(offset.top, $(window).scrollTop()); deepEqual(offset.top, $(window).scrollTop());
el.remove(); el.remove();
}); });
test("position, left on window", function() { test("position, left on window", function() {
var el = $('<div></div>').dialog({ position: "left" }); var el = $('<div></div>').dialog({ position: "left" }),
var dialog = el.dialog('widget'); dialog = el.dialog('widget'),
var offset = dialog.offset(); offset = dialog.offset();
deepEqual(offset.left, 0); deepEqual(offset.left, 0);
deepEqual(offset.top, Math.round($(window).height() / 2 - dialog.outerHeight() / 2) + $(window).scrollTop()); deepEqual(offset.top, Math.round($(window).height() / 2 - dialog.outerHeight() / 2) + $(window).scrollTop());
el.remove(); el.remove();
}); });
test("position, right bottom on window", function() { test("position, right bottom on window", function() {
var el = $('<div></div>').dialog({ position: "right bottom" }); var el = $('<div></div>').dialog({ position: "right bottom" }),
var dialog = el.dialog('widget'); dialog = el.dialog('widget'),
var offset = dialog.offset(); offset = dialog.offset();
deepEqual(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft()); deepEqual(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft());
deepEqual(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop()); deepEqual(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop());
el.remove(); el.remove();
}); });
test("position, right bottom on window w/array", function() { test("position, right bottom on window w/array", function() {
var el = $('<div></div>').dialog({ position: ["right", "bottom"] }); var el = $('<div></div>').dialog({ position: ["right", "bottom"] }),
var dialog = el.dialog('widget'); dialog = el.dialog('widget'),
var offset = dialog.offset(); offset = dialog.offset();
deepEqual(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft()); deepEqual(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft());
deepEqual(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop()); deepEqual(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop());
el.remove(); el.remove();
}); });
test("position, offset from top left w/array", function() { test("position, offset from top left w/array", function() {
var el = $('<div></div>').dialog({ position: [10, 10] }); var el = $('<div></div>').dialog({ position: [10, 10] }),
var dialog = el.dialog('widget'); dialog = el.dialog('widget'),
var offset = dialog.offset(); offset = dialog.offset();
deepEqual(offset.left, 10 + $(window).scrollLeft()); deepEqual(offset.left, 10 + $(window).scrollLeft());
deepEqual(offset.top, 10 + $(window).scrollTop()); deepEqual(offset.top, 10 + $(window).scrollTop());
el.remove(); el.remove();
@ -334,10 +335,9 @@ test("position, right bottom at right bottom via ui.position args", function() {
my: "right bottom", my: "right bottom",
at: "right bottom" at: "right bottom"
} }
}); }),
dialog = el.dialog('widget'),
var dialog = el.dialog('widget'); offset = dialog.offset();
var offset = dialog.offset();
deepEqual(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft()); deepEqual(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft());
deepEqual(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop()); deepEqual(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop());
@ -351,18 +351,18 @@ test("position, at another element", function() {
left: 600, left: 600,
height: 10, height: 10,
width: 10 width: 10
}).appendTo('body'); }).appendTo('body'),
var el = $('<div></div>').dialog({ el = $('<div></div>').dialog({
position: { position: {
my: "left top", my: "left top",
at: "left top", at: "left top",
of: parent of: parent
} }
}); }),
var dialog = el.dialog('widget'); dialog = el.dialog('widget'),
var offset = dialog.offset(); offset = dialog.offset();
deepEqual(offset.left, 600); deepEqual(offset.left, 600);
deepEqual(offset.top, 400); deepEqual(offset.top, 400);
@ -373,7 +373,7 @@ test("position, at another element", function() {
of: parent of: parent
}); });
var offset = dialog.offset(); offset = dialog.offset();
deepEqual(offset.left, 610); deepEqual(offset.left, 610);
deepEqual(offset.top, 410); deepEqual(offset.top, 410);

View File

@ -12,12 +12,6 @@ asyncTest( "#3123: Prevent tabbing out of modal dialogs", function() {
inputs = el.find( "input" ), inputs = el.find( "input" ),
widget = el.dialog( "widget" ); widget = el.dialog( "widget" );
inputs.eq( 1 ).focus();
equal( document.activeElement, inputs[1], "Focus set on second input" );
inputs.eq( 1 ).simulate( "keydown", { keyCode: $.ui.keyCode.TAB });
setTimeout( checkTab, 2 );
function checkTab() { function checkTab() {
ok( $.contains( widget, document.activeElement ), "Tab key event moved focus within the modal" ); ok( $.contains( widget, document.activeElement ), "Tab key event moved focus within the modal" );
@ -32,14 +26,21 @@ asyncTest( "#3123: Prevent tabbing out of modal dialogs", function() {
el.remove(); el.remove();
start(); start();
} }
inputs.eq( 1 ).focus();
equal( document.activeElement, inputs[1], "Focus set on second input" );
inputs.eq( 1 ).simulate( "keydown", { keyCode: $.ui.keyCode.TAB });
setTimeout( checkTab, 2 );
}); });
test("#4826: setting resizable false toggles resizable on dialog", function() { test("#4826: setting resizable false toggles resizable on dialog", function() {
expect(6); expect(6);
var i;
el = $('<div></div>').dialog({ resizable: false }); el = $('<div></div>').dialog({ resizable: false });
shouldnotresize("[default]"); shouldnotresize("[default]");
for (var i=0; i<2; i++) { for (i=0; i<2; i++) {
el.dialog('close').dialog('open'); el.dialog('close').dialog('open');
shouldnotresize('initialized with resizable false toggle ('+ (i+1) +')'); shouldnotresize('initialized with resizable false toggle ('+ (i+1) +')');
} }
@ -47,7 +48,7 @@ test("#4826: setting resizable false toggles resizable on dialog", function() {
el = $('<div></div>').dialog({ resizable: true }); el = $('<div></div>').dialog({ resizable: true });
shouldresize("[default]"); shouldresize("[default]");
for (var i=0; i<2; i++) { for (i=0; i<2; i++) {
el.dialog('close').dialog('option', 'resizable', false).dialog('open'); el.dialog('close').dialog('option', 'resizable', false).dialog('open');
shouldnotresize('set option resizable false toggle ('+ (i+1) +')'); shouldnotresize('set option resizable false toggle ('+ (i+1) +')');
} }
@ -108,7 +109,7 @@ test("#6137: dialog('open') causes form elements to reset on IE7", function() {
test("#6645: Missing element not found check in overlay", function(){ test("#6645: Missing element not found check in overlay", function(){
expect(2); expect(2);
d1 = $('<div title="dialog 1">Dialog 1</div>').dialog({modal: true}); d1 = $('<div title="dialog 1">Dialog 1</div>').dialog({modal: true});
d2 = $('<div title="dialog 2">Dialog 2</div>').dialog({modal: true, close: function(){ d2.remove()}}); d2 = $('<div title="dialog 2">Dialog 2</div>').dialog({modal: true, close: function(){ d2.remove(); }});
equal($.ui.dialog.overlay.instances.length, 2, 'two overlays created'); equal($.ui.dialog.overlay.instances.length, 2, 'two overlays created');
d2.dialog('close'); d2.dialog('close');
equal($.ui.dialog.overlay.instances.length, 1, 'one overlay remains after closing the 2nd overlay'); equal($.ui.dialog.overlay.instances.length, 1, 'one overlay remains after closing the 2nd overlay');
@ -119,7 +120,7 @@ test("#6966: Escape key closes all dialogs, not the top one", function(){
expect(8); expect(8);
// test with close function removing dialog // test with close function removing dialog
d1 = $('<div title="dialog 1">Dialog 1</div>').dialog({modal: true}); d1 = $('<div title="dialog 1">Dialog 1</div>').dialog({modal: true});
d2 = $('<div title="dialog 2">Dialog 2</div>').dialog({modal: true, close: function(){ d2.remove()}}); d2 = $('<div title="dialog 2">Dialog 2</div>').dialog({modal: true, close: function(){ d2.remove(); }});
ok(d1.dialog("isOpen"), 'first dialog is open'); ok(d1.dialog("isOpen"), 'first dialog is open');
ok(d2.dialog("isOpen"), 'second dialog is open'); ok(d2.dialog("isOpen"), 'second dialog is open');
d2.simulate("keydown", {keyCode: $.ui.keyCode.ESCAPE}); d2.simulate("keydown", {keyCode: $.ui.keyCode.ESCAPE});

View File

@ -4,7 +4,7 @@
var el, offsetBefore, offsetAfter, dragged; var el, offsetBefore, offsetAfter, dragged;
var drag = function(handle, dx, dy) { function drag(handle, dx, dy) {
var element = el.data("draggable").element; var element = el.data("draggable").element;
offsetBefore = el.offset(); offsetBefore = el.offset();
$(handle).simulate("drag", { $(handle).simulate("drag", {
@ -15,10 +15,10 @@ var drag = function(handle, dx, dy) {
offsetAfter = el.offset(); offsetAfter = el.offset();
} }
var moved = function (dx, dy, msg) { function moved(dx, dy, msg) {
msg = msg ? msg + "." : ""; msg = msg ? msg + "." : "";
var actual = { left: offsetAfter.left, top: offsetAfter.top }; var actual = { left: offsetAfter.left, top: offsetAfter.top },
var expected = { left: offsetBefore.left + dx, top: offsetBefore.top + dy }; expected = { left: offsetBefore.left + dx, top: offsetBefore.top + dy };
deepEqual(actual, expected, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ' + msg); deepEqual(actual, expected, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ' + msg);
} }
@ -35,15 +35,15 @@ function restoreScroll(what) {
module("draggable"); module("draggable");
test("element types", function() { test("element types", function() {
var typeNames = ('p,h1,h2,h3,h4,h5,h6,blockquote,ol,ul,dl,div,form' var typeNames = ('p,h1,h2,h3,h4,h5,h6,blockquote,ol,ul,dl,div,form' +
+ ',table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr' ',table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr' +
+ ',acronym,code,samp,kbd,var,img,object,hr' ',acronym,code,samp,kbd,var,img,object,hr' +
+ ',input,button,label,select,iframe').split(','); ',input,button,label,select,iframe').split(',');
$.each(typeNames, function(i) { $.each(typeNames, function(i) {
var typeName = typeNames[i]; var typeName = typeNames[i];
el = $(document.createElement(typeName)).appendTo('body'); el = $(document.createElement(typeName)).appendTo('body');
(typeName == 'table' && el.append("<tr><td>content</td></tr>")); (typeName === 'table' && el.append("<tr><td>content</td></tr>"));
el.draggable({ cancel: '' }); el.draggable({ cancel: '' });
drag(el, 50, 50); drag(el, 50, 50);
moved(50, 50, "&lt;" + typeName + "&gt;"); moved(50, 50, "&lt;" + typeName + "&gt;");

View File

@ -17,15 +17,16 @@ function setScroll(what) {
} }
} }
var border = function(el, side) { return parseInt(el.css('border-' + side + '-width')); } function border(el, side) {
return parseInt(el.css('border-' + side + '-width'), 10);
var margin = function(el, side) { return parseInt(el.css('margin-' + side)); } }
function margin(el, side) {
return parseInt(el.css('margin-' + side), 10);
}
module("draggable: options"); module("draggable: options");
test("{ addClasses: true }, default", function() { test("{ addClasses: true }, default", function() {
equal(draggable_defaults.addClasses, true);
el = $("<div></div>").draggable({ addClasses: true }); el = $("<div></div>").draggable({ addClasses: true });
ok(el.is(".ui-draggable"), "'ui-draggable' class added"); ok(el.is(".ui-draggable"), "'ui-draggable' class added");
@ -40,8 +41,6 @@ test("{ addClasses: false }", function() {
}); });
test("{ appendTo: 'parent' }, default", function() { test("{ appendTo: 'parent' }, default", function() {
equal(draggable_defaults.appendTo, "parent");
el = $("#draggable2").draggable({ appendTo: 'parent' }); el = $("#draggable2").draggable({ appendTo: 'parent' });
drag(el, 50, 50); drag(el, 50, 50);
moved(50, 50); moved(50, 50);
@ -73,8 +72,6 @@ test("{ appendTo: Selector }", function() {
}); });
test("{ axis: false }, default", function() { test("{ axis: false }, default", function() {
equal(draggable_defaults.axis, false);
el = $("#draggable2").draggable({ axis: false }); el = $("#draggable2").draggable({ axis: false });
drag(el, 50, 50); drag(el, 50, 50);
moved(50, 50); moved(50, 50);
@ -106,12 +103,10 @@ test("{ axis: ? }, unexpected", function() {
drag(el, 50, 50); drag(el, 50, 50);
moved(50, 50, "axis: " + key); moved(50, 50, "axis: " + key);
el.draggable("destroy"); el.draggable("destroy");
}) });
}); });
test("{ cancel: ':input,option' }, default", function() { test("{ cancel: ':input,option' }, default", function() {
equal(draggable_defaults.cancel, ":input,option");
$('<div id="draggable-option-cancel-default"><input type="text"></div>').appendTo('#main'); $('<div id="draggable-option-cancel-default"><input type="text"></div>').appendTo('#main');
el = $("#draggable-option-cancel-default").draggable({ cancel: ":input,option" }); el = $("#draggable-option-cancel-default").draggable({ cancel: ":input,option" });
@ -155,12 +150,10 @@ test("{ cancel: ? }, unexpected", function() {
var expected = [50, 50]; var expected = [50, 50];
moved(expected[0], expected[1], "cancel: " + key); moved(expected[0], expected[1], "cancel: " + key);
el.draggable("destroy"); el.draggable("destroy");
}) });
}); });
test("{ containment: false }, default", function() { test("{ containment: false }, default", function() {
equal(draggable_defaults.containment, false);
ok(false, 'missing test - untested code is broken code'); ok(false, 'missing test - untested code is broken code');
}); });
@ -170,23 +163,25 @@ test("{ containment: Element }", function() {
test("{ containment: 'parent' }, relative", function() { test("{ containment: 'parent' }, relative", function() {
el = $("#draggable1").draggable({ containment: 'parent' }); el = $("#draggable1").draggable({ containment: 'parent' });
var p = el.parent(), po = p.offset(); var p = el.parent(),
drag(el, -100, -100); po = p.offset(),
var expected = { expected = {
left: po.left + border(p, 'left') + margin(el, 'left'), left: po.left + border(p, 'left') + margin(el, 'left'),
top: po.top + border(p, 'top') + margin(el, 'top') top: po.top + border(p, 'top') + margin(el, 'top')
} };
drag(el, -100, -100);
deepEqual(offsetAfter, expected, 'compare offset to parent'); deepEqual(offsetAfter, expected, 'compare offset to parent');
}); });
test("{ containment: 'parent' }, absolute", function() { test("{ containment: 'parent' }, absolute", function() {
el = $("#draggable2").draggable({ containment: 'parent' }); el = $("#draggable2").draggable({ containment: 'parent' });
var p = el.parent(), po = p.offset(); var p = el.parent(),
drag(el, -100, -100); po = p.offset(),
var expected = { expected = {
left: po.left + border(p, 'left') + margin(el, 'left'), left: po.left + border(p, 'left') + margin(el, 'left'),
top: po.top + border(p, 'top') + margin(el, 'top') top: po.top + border(p, 'top') + margin(el, 'top')
} };
drag(el, -100, -100);
deepEqual(offsetAfter, expected, 'compare offset to parent'); deepEqual(offsetAfter, expected, 'compare offset to parent');
}); });
@ -207,11 +202,9 @@ test("{ containment: [x1, y1, x2, y2] }", function() {
}); });
test("{ cursor: 'auto' }, default", function() { test("{ cursor: 'auto' }, default", function() {
equal(draggable_defaults.cursor, 'auto');
function getCursor() { return $("#draggable2").css("cursor"); } function getCursor() { return $("#draggable2").css("cursor"); }
expect(3); expect(2);
var expected = "auto", actual, before, after; var expected = "auto", actual, before, after;
@ -256,8 +249,6 @@ test("{ cursor: 'move' }", function() {
}); });
test("{ cursorAt: false}, default", function() { test("{ cursorAt: false}, default", function() {
equal(draggable_defaults.cursorAt, false);
ok(false, 'missing test - untested code is broken code'); ok(false, 'missing test - untested code is broken code');
}); });
@ -611,8 +602,8 @@ test("{ helper: 'original' }, fixed, with scroll offset on root and parent", fun
test("{ helper: 'clone' }, absolute", function() { test("{ helper: 'clone' }, absolute", function() {
var helperOffset = null; var helperOffset = null,
var origOffset = $("#draggable1").offset(); origOffset = $("#draggable1").offset();
el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) { el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) {
helperOffset = ui.helper.offset(); helperOffset = ui.helper.offset();
@ -626,8 +617,8 @@ test("{ helper: 'clone' }, absolute", function() {
test("{ helper: 'clone' }, absolute with scroll offset on parent", function() { test("{ helper: 'clone' }, absolute with scroll offset on parent", function() {
setScroll(); setScroll();
var helperOffset = null; var helperOffset = null,
var origOffset = null; origOffset = null;
el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) { el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) {
helperOffset = ui.helper.offset(); helperOffset = ui.helper.offset();
@ -655,8 +646,8 @@ test("{ helper: 'clone' }, absolute with scroll offset on parent", function() {
test("{ helper: 'clone' }, absolute with scroll offset on root", function() { test("{ helper: 'clone' }, absolute with scroll offset on root", function() {
setScroll('root'); setScroll('root');
var helperOffset = null; var helperOffset = null,
var origOffset = null; origOffset = null;
el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) { el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) {
helperOffset = ui.helper.offset(); helperOffset = ui.helper.offset();
@ -685,25 +676,25 @@ test("{ helper: 'clone' }, absolute with scroll offset on root and parent", func
setScroll('root'); setScroll('root');
setScroll(); setScroll();
var helperOffset = null; var helperOffset = null,
var origOffset = null; origOffset = null;
el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) { el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) {
helperOffset = ui.helper.offset(); helperOffset = ui.helper.offset();
} }); } });
$("#main").css('position', 'relative'); $("#main").css('position', 'relative');
origOffset = $("#draggable1").offset() origOffset = $("#draggable1").offset();
drag(el, 1, 1); drag(el, 1, 1);
deepEqual({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] '); deepEqual({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ');
$("#main").css('position', 'static'); $("#main").css('position', 'static');
origOffset = $("#draggable1").offset() origOffset = $("#draggable1").offset();
drag(el, 1, 1); drag(el, 1, 1);
deepEqual({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] '); deepEqual({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ');
$("#main").css('position', 'absolute'); $("#main").css('position', 'absolute');
origOffset = $("#draggable1").offset() origOffset = $("#draggable1").offset();
drag(el, 1, 1); drag(el, 1, 1);
deepEqual({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] '); deepEqual({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ');
@ -734,9 +725,9 @@ test("{ zIndex: 10 }", function() {
expect(1); expect(1);
var expected = 10, actual; var actual,
expected = 10,
var zIndex = null; zIndex = null;
el = $("#draggable2").draggable({ el = $("#draggable2").draggable({
zIndex: expected, zIndex: expected,
start: function(event, ui) { start: function(event, ui) {

View File

@ -17,15 +17,15 @@ function shouldNotBeDroppable() {
module("droppable: core"); module("droppable: core");
test("element types", function() { test("element types", function() {
var typeNames = ('p,h1,h2,h3,h4,h5,h6,blockquote,ol,ul,dl,div,form' var typeNames = ('p,h1,h2,h3,h4,h5,h6,blockquote,ol,ul,dl,div,form' +
+ ',table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr' ',table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr' +
+ ',acronym,code,samp,kbd,var,img,object,hr' ',acronym,code,samp,kbd,var,img,object,hr' +
+ ',input,button,label,select,iframe').split(','); ',input,button,label,select,iframe').split(',');
$.each(typeNames, function(i) { $.each(typeNames, function(i) {
var typeName = typeNames[i]; var typeName = typeNames[i];
el = $(document.createElement(typeName)).appendTo('body'); el = $(document.createElement(typeName)).appendTo('body');
(typeName == 'table' && el.append("<tr><td>content</td></tr>")); (typeName === 'table' && el.append("<tr><td>content</td></tr>"));
el.droppable(); el.droppable();
shouldBeDroppable(); shouldBeDroppable();
el.droppable("destroy"); el.droppable("destroy");

View File

@ -1,9 +1,6 @@
/* commonWidgetTests( "droppable", {
* droppable_defaults.js defaults: {
*/ accept: "*",
var droppable_defaults = {
accept: '*',
activeClass: false, activeClass: false,
addClasses: true, addClasses: true,
disabled: false, disabled: false,
@ -11,6 +8,5 @@ var droppable_defaults = {
hoverClass: false, hoverClass: false,
scope: "default", scope: "default",
tolerance: "intersect" tolerance: "intersect"
}; }
});
commonWidgetTests('droppable', { defaults: droppable_defaults });

View File

@ -6,8 +6,6 @@
module("droppable: options"); module("droppable: options");
test("{ accept '*' }, default ", function() { test("{ accept '*' }, default ", function() {
equal(droppable_defaults.accept, '*');
ok(false, 'missing test - untested code is broken code'); ok(false, 'missing test - untested code is broken code');
}); });
@ -24,8 +22,6 @@ test("activeClass", function() {
}); });
test("{ addClasses: true }, default", function() { test("{ addClasses: true }, default", function() {
equal(droppable_defaults.addClasses, true);
el = $("<div></div>").droppable({ addClasses: true }); el = $("<div></div>").droppable({ addClasses: true });
ok(el.is(".ui-droppable"), "'ui-droppable' class added"); ok(el.is(".ui-droppable"), "'ui-droppable' class added");
el.droppable("destroy"); el.droppable("destroy");