Dev: remove unnecessary simulated drag delegation in test suite

This commit is contained in:
Mike Sherov 2012-12-08 21:27:37 -05:00
parent 5dee8dee30
commit 9f76446775
12 changed files with 291 additions and 184 deletions

View File

@ -3,10 +3,9 @@ TestHelpers.dialog = {
var d = el.dialog('widget'); var d = el.dialog('widget');
//this mouseover is to work around a limitation in resizable //this mouseover is to work around a limitation in resizable
//TODO: fix resizable so handle doesn't require mouseover in order to be used //TODO: fix resizable so handle doesn't require mouseover in order to be used
$(handle, d).simulate("mouseover"); $( handle, d ).simulate("mouseover").simulate( "drag", {
$(handle, d).simulate("drag", { dx: dx,
dx: dx || 0, dy: dy
dy: dy || 0
}); });
}, },
testDrag: function(el, dx, dy, expectedDX, expectedDY, msg) { testDrag: function(el, dx, dy, expectedDX, expectedDY, msg) {

View File

@ -22,7 +22,10 @@ test("element types", function() {
(typeName === 'table' && el.append("<tr><td>content</td></tr>")); (typeName === 'table' && el.append("<tr><td>content</td></tr>"));
el.draggable({ cancel: '' }); el.draggable({ cancel: '' });
offsetBefore = el.offset(); offsetBefore = el.offset();
TestHelpers.draggable.drag(el, 50, 50); el.simulate( "drag", {
dx: 50,
dy: 50
});
offsetAfter = el.offset(); 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 // there are some rounding errors in FF, Chrome, and IE9, so we can't say equal, we have to settle for close enough
closeEnough(offsetBefore.left, offsetAfter.left - 50, 1, "dragged[50, 50] " + "<" + typeName + ">"); closeEnough(offsetBefore.left, offsetAfter.left - 50, 1, "dragged[50, 50] " + "<" + typeName + ">");
@ -55,21 +58,15 @@ test("resizable handle with complex markup (#8756 / #8757)", function() {
.append($('<div>')) .append($('<div>'))
); );
var handle = '.ui-resizable-w div', var handle = $('.ui-resizable-w div'),
target = $('#draggable1').draggable().resizable({ handles: 'all' }), target = $('#draggable1').draggable().resizable({ handles: 'all' });
drag = function(el, dx) {
$(el)
.simulate("mouseover")
.simulate("drag", {
dx: dx || 0,
speed: 'sync'
});
};
drag(handle, -50); // todo: fix resizable so it doesn't require a mouseover
handle.simulate("mouseover").simulate( "drag", { dx: -50 } );
equal( target.width(), 250, "compare width" ); equal( target.width(), 250, "compare width" );
drag(handle, 50); // todo: fix resizable so it doesn't require a mouseover
handle.simulate("mouseover").simulate( "drag", { dx: 50 } );
equal( target.width(), 200, "compare width" ); equal( target.width(), 200, "compare width" );
}); });

View File

@ -18,7 +18,10 @@ test("callbacks occurrence count", function() {
stop: function() { stop++; } stop: function() { stop++; }
}); });
TestHelpers.draggable.drag(el, 10, 10); el.simulate( "drag", {
dx: 10,
dy: 10
});
equal(start, 1, "start callback should happen exactly once"); equal(start, 1, "start callback should happen exactly once");
equal(dragc, 3, "drag callback should happen exactly once per mousemove"); equal(dragc, 3, "drag callback should happen exactly once per mousemove");
@ -39,7 +42,10 @@ test("stopping the start callback", function() {
stop: function() { stop++; } stop: function() { stop++; }
}); });
TestHelpers.draggable.drag(el, 10, 10); el.simulate( "drag", {
dx: 10,
dy: 10
});
equal(start, 1, "start callback should happen exactly once"); equal(start, 1, "start callback should happen exactly once");
equal(dragc, 0, "drag callback should not happen at all"); equal(dragc, 0, "drag callback should not happen at all");
@ -60,7 +66,10 @@ test("stopping the drag callback", function() {
stop: function() { stop++; } stop: function() { stop++; }
}); });
TestHelpers.draggable.drag(el, 10, 10); el.simulate( "drag", {
dx: 10,
dy: 10
});
equal(start, 1, "start callback should happen exactly once"); equal(start, 1, "start callback should happen exactly once");
equal(dragc, 1, "drag callback should happen exactly once"); equal(dragc, 1, "drag callback should happen exactly once");
@ -77,7 +86,10 @@ test("stopping the stop callback", function() {
stop: function() { return false; } stop: function() { return false; }
}); });
TestHelpers.draggable.drag(el, 10, 10); el.simulate( "drag", {
dx: 10,
dy: 10
});
ok($("#draggable2").data('ui-draggable').helper, "the clone should not be deleted if the stop callback is stopped"); ok($("#draggable2").data('ui-draggable').helper, "the clone should not be deleted if the stop callback is stopped");

View File

@ -162,7 +162,11 @@ test("{ containment: 'parent' }, relative", function() {
left: po.left + TestHelpers.draggable.border(p, 'left') + TestHelpers.draggable.margin(el, 'left'), left: po.left + TestHelpers.draggable.border(p, 'left') + TestHelpers.draggable.margin(el, 'left'),
top: po.top + TestHelpers.draggable.border(p, 'top') + TestHelpers.draggable.margin(el, 'top') top: po.top + TestHelpers.draggable.border(p, 'top') + TestHelpers.draggable.margin(el, 'top')
}; };
TestHelpers.draggable.drag(el, -100, -100);
el.simulate( "drag", {
dx: -100,
dy: -100
});
offsetAfter = el.offset(); offsetAfter = el.offset();
deepEqual(offsetAfter, expected, 'compare offset to parent'); deepEqual(offsetAfter, expected, 'compare offset to parent');
}); });
@ -178,7 +182,11 @@ test("{ containment: 'parent' }, absolute", function() {
left: po.left + TestHelpers.draggable.border(p, 'left') + TestHelpers.draggable.margin(el, 'left'), left: po.left + TestHelpers.draggable.border(p, 'left') + TestHelpers.draggable.margin(el, 'left'),
top: po.top + TestHelpers.draggable.border(p, 'top') + TestHelpers.draggable.margin(el, 'top') top: po.top + TestHelpers.draggable.border(p, 'top') + TestHelpers.draggable.margin(el, 'top')
}; };
TestHelpers.draggable.drag(el, -100, -100);
el.simulate( "drag", {
dx: -100,
dy: -100
});
offsetAfter = el.offset(); offsetAfter = el.offset();
deepEqual(offsetAfter, expected, 'compare offset to parent'); deepEqual(offsetAfter, expected, 'compare offset to parent');
}); });
@ -214,17 +222,20 @@ test("{ cursor: 'auto' }, default", function() {
expect(2); expect(2);
var expected = "auto", actual, before, after; var actual, before, after,
expected = "auto",
$("#draggable2").draggable({ el = $("#draggable2").draggable({
cursor: expected, cursor: expected,
start: function() { start: function() {
actual = getCursor(); actual = getCursor();
} }
}); });
before = getCursor(); before = getCursor();
TestHelpers.draggable.drag("#draggable2", -1, -1); el.simulate( "drag", {
dx: -1,
dy: -1
});
after = getCursor(); after = getCursor();
equal(actual, expected, "start callback: cursor '" + expected + "'"); equal(actual, expected, "start callback: cursor '" + expected + "'");
@ -238,17 +249,20 @@ test("{ cursor: 'move' }", function() {
expect(2); expect(2);
var expected = "move", actual, before, after; var actual, before, after,
expected = "move",
$("#draggable2").draggable({ el = $("#draggable2").draggable({
cursor: expected, cursor: expected,
start: function() { start: function() {
actual = getCursor(); actual = getCursor();
} }
}); });
before = getCursor(); before = getCursor();
TestHelpers.draggable.drag("#draggable2", -1, -1); el.simulate( "drag", {
dx: -1,
dy: -1
});
after = getCursor(); after = getCursor();
equal(actual, expected, "start callback: cursor '" + expected + "'"); equal(actual, expected, "start callback: cursor '" + expected + "'");
@ -648,7 +662,10 @@ test("{ helper: 'clone' }, absolute", function() {
helperOffset = ui.helper.offset(); helperOffset = ui.helper.offset();
} }); } });
TestHelpers.draggable.drag(el, 1, 1); el.simulate( "drag", {
dx: 1,
dy: 1
});
deepEqual({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[1, 1] '); deepEqual({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[1, 1] ');
}); });
@ -666,17 +683,26 @@ test("{ helper: 'clone' }, absolute with scroll offset on parent", function() {
$("#main").css('position', 'relative'); $("#main").css('position', 'relative');
origOffset = $("#draggable1").offset(); origOffset = $("#draggable1").offset();
TestHelpers.draggable.drag(el, 1, 1); el.simulate( "drag", {
dx: 1,
dy: 1
});
deepEqual({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[1, 1] '); deepEqual({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[1, 1] ');
$("#main").css('position', 'static'); $("#main").css('position', 'static');
origOffset = $("#draggable1").offset(); origOffset = $("#draggable1").offset();
TestHelpers.draggable.drag(el, 1, 1); el.simulate( "drag", {
dx: 1,
dy: 1
});
deepEqual({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[1, 1] '); deepEqual({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[1, 1] ');
$("#main").css('position', 'absolute'); $("#main").css('position', 'absolute');
origOffset = $("#draggable1").offset(); origOffset = $("#draggable1").offset();
TestHelpers.draggable.drag(el, 1, 1); el.simulate( "drag", {
dx: 1,
dy: 1
});
deepEqual({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[1, 1] '); deepEqual({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[1, 1] ');
TestHelpers.draggable.restoreScroll(); TestHelpers.draggable.restoreScroll();
@ -696,17 +722,26 @@ test("{ helper: 'clone' }, absolute with scroll offset on root", function() {
$("#main").css('position', 'relative'); $("#main").css('position', 'relative');
origOffset = $("#draggable1").offset(); origOffset = $("#draggable1").offset();
TestHelpers.draggable.drag(el, 1, 1); el.simulate( "drag", {
dx: 1,
dy: 1
});
deepEqual({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[1, 1] '); deepEqual({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[1, 1] ');
$("#main").css('position', 'static'); $("#main").css('position', 'static');
origOffset = $("#draggable1").offset(); origOffset = $("#draggable1").offset();
TestHelpers.draggable.drag(el, 1, 1); el.simulate( "drag", {
dx: 1,
dy: 1
});
deepEqual({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[1, 1] '); deepEqual({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[1, 1] ');
$("#main").css('position', 'absolute'); $("#main").css('position', 'absolute');
origOffset = $("#draggable1").offset(); origOffset = $("#draggable1").offset();
TestHelpers.draggable.drag(el, 1, 1); el.simulate( "drag", {
dx: 1,
dy: 1
});
deepEqual({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[1, 1] '); deepEqual({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[1, 1] ');
TestHelpers.draggable.restoreScroll('root'); TestHelpers.draggable.restoreScroll('root');
@ -728,17 +763,26 @@ test("{ helper: 'clone' }, absolute with scroll offset on root and parent", func
$("#main").css('position', 'relative'); $("#main").css('position', 'relative');
origOffset = $("#draggable1").offset(); origOffset = $("#draggable1").offset();
TestHelpers.draggable.drag(el, 1, 1); el.simulate( "drag", {
dx: 1,
dy: 1
});
deepEqual({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[1, 1] '); deepEqual({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[1, 1] ');
$("#main").css('position', 'static'); $("#main").css('position', 'static');
origOffset = $("#draggable1").offset(); origOffset = $("#draggable1").offset();
TestHelpers.draggable.drag(el, 1, 1); el.simulate( "drag", {
dx: 1,
dy: 1
});
deepEqual({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[1, 1] '); deepEqual({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[1, 1] ');
$("#main").css('position', 'absolute'); $("#main").css('position', 'absolute');
origOffset = $("#draggable1").offset(); origOffset = $("#draggable1").offset();
TestHelpers.draggable.drag(el, 1, 1); el.simulate( "drag", {
dx: 1,
dy: 1
});
deepEqual({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[1, 1] '); deepEqual({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[1, 1] ');
TestHelpers.draggable.restoreScroll('root'); TestHelpers.draggable.restoreScroll('root');
@ -750,17 +794,19 @@ test("{ opacity: 0.5 }", function() {
expect(1); expect(1);
var opacity = null; var opacity = null,
el = $("#draggable2").draggable({
opacity: 0.5,
start: function() {
opacity = $(this).css("opacity");
}
});
$("#draggable2").draggable({ el.simulate( "drag", {
opacity: 0.5, dx: -1,
start: function() { dy: -1
opacity = $(this).css("opacity");
}
}); });
TestHelpers.draggable.drag("#draggable2", -1, -1);
equal(opacity, 0.5, "start callback: opacity is"); equal(opacity, 0.5, "start callback: opacity is");
}); });
@ -770,17 +816,19 @@ test("{ zIndex: 10 }", function() {
expect(1); expect(1);
var actual, var actual,
expected = 10; expected = 10,
el = $("#draggable2").draggable({
zIndex: expected,
start: function() {
actual = $(this).css("zIndex");
}
});
$("#draggable2").draggable({ el.simulate( "drag", {
zIndex: expected, dx: -1,
start: function() { dy: -1
actual = $(this).css("zIndex");
}
}); });
TestHelpers.draggable.drag("#draggable2", -1, -1);
equal(actual, expected, "start callback: zIndex is"); equal(actual, expected, "start callback: zIndex is");
}); });

View File

@ -1,17 +1,14 @@
TestHelpers.draggable = { TestHelpers.draggable = {
// todo: remove the unreliable offset hacks // todo: remove the unreliable offset hacks
unreliableOffset: $.ui.ie && ( !document.documentMode || document.documentMode < 8 ) ? 2 : 0, unreliableOffset: $.ui.ie && ( !document.documentMode || document.documentMode < 8 ) ? 2 : 0,
drag: function(handle, dx, dy) {
$(handle).simulate("drag", {
dx: dx || 0,
dy: dy || 0
});
},
testDrag: function(el, handle, dx, dy, expectedDX, expectedDY, msg) { testDrag: function(el, handle, dx, dy, expectedDX, expectedDY, msg) {
var offsetAfter, actual, expected, var offsetAfter, actual, expected,
offsetBefore = el.offset(); offsetBefore = el.offset();
TestHelpers.draggable.drag(handle, dx, dy); $( handle ).simulate( "drag", {
dx: dx,
dy: dy
});
offsetAfter = el.offset(); offsetAfter = el.offset();
actual = { left: offsetAfter.left, top: offsetAfter.top }, actual = { left: offsetAfter.left, top: offsetAfter.top },

View File

@ -1,15 +1,10 @@
TestHelpers.resizable = { TestHelpers.resizable = {
drag: function(el, dx, dy, complete) { drag: function( el, dx, dy ) {
// this mouseover is to work around a limitation in resizable
// speed = sync -> Drag syncrhonously. // TODO: fix resizable so handle doesn't require mouseover in order to be used
// speed = fast|slow -> Drag asyncrhonously - animated. $( el ).simulate("mouseover").simulate( "drag", {
dx: dx,
//this mouseover is to work around a limitation in resizable dy: dy
//TODO: fix resizable so handle doesn't require mouseover in order to be used
$(el).simulate("mouseover");
return $(el).simulate("drag", {
dx: dx||0, dy: dy||0, speed: 'sync', complete: complete
}); });
} }
}; };

View File

@ -1,32 +1,38 @@
/* /*
* selectable_events.js * selectable_events.js
*/ */
(function($) { (function( $ ) {
module("selectable: events"); module("selectable: events");
test("start", function() { test( "start", function() {
expect(2); expect( 2 );
var el = $("#selectable1"); var el = $("#selectable1");
el.selectable({ el.selectable({
start: function() { start: function() {
ok(true, "drag fired start callback"); ok( true, "drag fired start callback" );
equal(this, el[0], "context of callback"); equal( this, el[0], "context of callback" );
} }
}); });
el.simulate("drag", 20, 20); el.simulate( "drag", {
dx: 20,
dy: 20
});
}); });
test("stop", function() { test( "stop", function() {
expect(2); expect( 2 );
var el = $("#selectable1"); var el = $("#selectable1");
el.selectable({ el.selectable({
start: function() { start: function() {
ok(true, "drag fired stop callback"); ok( true, "drag fired stop callback" );
equal(this, el[0], "context of callback"); equal( this, el[0], "context of callback" );
} }
}); });
el.simulate("drag", 20, 20); el.simulate( "drag", {
dx: 20,
dy: 20
});
}); });
})(jQuery); })( jQuery );

View File

@ -53,10 +53,16 @@ test("enable", function() {
disabled: true, disabled: true,
start: function() { fired = true; } start: function() { fired = true; }
}); });
el.simulate("drag", 20, 20); el.simulate( "drag", {
dx: 20,
dy: 20
});
equal(fired, false, "start fired"); equal(fired, false, "start fired");
el.selectable("enable"); el.selectable("enable");
el.simulate("drag", 20, 20); el.simulate( "drag", {
dx: 20,
dy: 20
});
equal(fired, true, "start fired"); equal(fired, true, "start fired");
el.selectable("destroy"); el.selectable("destroy");
@ -75,11 +81,18 @@ test("disable", function() {
disabled: false, disabled: false,
start: function() { fired = true; } start: function() { fired = true; }
}); });
el.simulate("drag", 20, 20); el.simulate( "drag", {
dx: 20,
dy: 20
});
equal(fired, true, "start fired"); equal(fired, true, "start fired");
el.selectable("disable"); el.selectable("disable");
fired = false; fired = false;
el.simulate("drag", 20, 20);
el.simulate( "drag", {
dx: 20,
dy: 20
});
equal(fired, false, "start fired"); equal(fired, false, "start fired");
el.selectable("destroy"); el.selectable("destroy");

View File

@ -15,7 +15,10 @@ test("autoRefresh", function() {
el = $("#selectable1").selectable({ autoRefresh: false, selected: selected }); el = $("#selectable1").selectable({ autoRefresh: false, selected: selected });
sel.hide(); sel.hide();
TestHelpers.selectable.drag(el, 1000, 1000); el.simulate( "drag", {
dx: 1000,
dy: 1000
});
equal(actual, sel.length); equal(actual, sel.length);
el.selectable("destroy"); el.selectable("destroy");
@ -23,11 +26,19 @@ test("autoRefresh", function() {
sel.show(); sel.show();
el = $("#selectable1").selectable({ autoRefresh: true, selected: selected }); el = $("#selectable1").selectable({ autoRefresh: true, selected: selected });
sel.hide(); sel.hide();
TestHelpers.selectable.drag(el, 1000, 1000); el.simulate( "drag", {
dx: 1000,
dy: 1000
});
equal(actual, 0); equal(actual, 0);
sel.show(); sel.show();
TestHelpers.selectable.drag( sel[ 0 ], 1000, 1000 ); $( sel[ 0 ] ).simulate( "drag", {
dx: 1000,
dy: 1000
});
equal(actual, sel.length); equal(actual, sel.length);
el.selectable("destroy"); el.selectable("destroy");
sel.show(); sel.show();
}); });
@ -42,7 +53,10 @@ test("filter", function() {
el = $("#selectable1").selectable({ filter: '.special', selected: selected }); el = $("#selectable1").selectable({ filter: '.special', selected: selected });
TestHelpers.selectable.drag(el, 1000, 1000); el.simulate( "drag", {
dx: 1000,
dy: 1000
});
ok(sel.length !== 1, "this test assumes more than 1 selectee"); ok(sel.length !== 1, "this test assumes more than 1 selectee");
equal(actual, 1); equal(actual, 1);
el.selectable("destroy"); el.selectable("destroy");

View File

@ -1,8 +0,0 @@
TestHelpers.selectable = {
drag: function( el, dx, dy ) {
$( el ).simulate( "drag", {
dx: dx || 0,
dy: dy || 0
});
}
};

View File

@ -9,9 +9,13 @@ test("start", function() {
expect( 7 ); expect( 7 );
var hash; var hash;
$("#sortable") $("#sortable").sortable({
.sortable({ start: function(e, ui) { hash = ui; } }) start: function( e, ui ) {
.find('li:eq(0)').simulate("drag", { dx: 0, dy: 10 }); hash = ui;
}
}).find("li:eq(0)").simulate( "drag", {
dy: 10
});
ok(hash, 'start event triggered'); ok(hash, 'start event triggered');
ok(hash.helper, 'UI hash includes: helper'); ok(hash.helper, 'UI hash includes: helper');
@ -30,9 +34,13 @@ test("sort", function() {
expect( 7 ); expect( 7 );
var hash; var hash;
$("#sortable") $("#sortable").sortable({
.sortable({ sort: function(e, ui) { hash = ui; } }) sort: function( e, ui ) {
.find('li:eq(0)').simulate("drag", { dx: 0, dy: 10 }); hash = ui;
}
}).find("li:eq(0)").simulate( "drag", {
dy: 10
});
ok(hash, 'sort event triggered'); ok(hash, 'sort event triggered');
ok(hash.helper, 'UI hash includes: helper'); ok(hash.helper, 'UI hash includes: helper');
@ -48,15 +56,24 @@ test("change", function() {
expect( 8 ); expect( 8 );
var hash; var hash;
$("#sortable") $("#sortable").sortable({
.sortable({ change: function(e, ui) { hash = ui; } }) change: function( e, ui ) {
.find('li:eq(0)').simulate("drag", { dx: 1, dy: 1 }); hash = ui;
}
}).find("li:eq(0)").simulate( "drag", {
dx: 1,
dy: 1
});
ok(!hash, '1px drag, change event should not be triggered'); ok(!hash, '1px drag, change event should not be triggered');
$("#sortable") $("#sortable").sortable({
.sortable({ change: function(e, ui) { hash = ui; } }) change: function( e, ui ) {
.find('li:eq(0)').simulate("drag", { dx: 0, dy: 22 }); hash = ui;
}
}).find("li:eq(0)").simulate( "drag", {
dy: 22
});
ok(hash, 'change event triggered'); ok(hash, 'change event triggered');
ok(hash.helper, 'UI hash includes: helper'); ok(hash.helper, 'UI hash includes: helper');
@ -72,9 +89,13 @@ test("beforeStop", function() {
expect( 7 ); expect( 7 );
var hash; var hash;
$("#sortable") $("#sortable").sortable({
.sortable({ beforeStop: function(e, ui) { hash = ui; } }) beforeStop: function( e, ui ) {
.find('li:eq(0)').simulate("drag", { dx: 0, dy: 20 }); hash = ui;
}
}).find("li:eq(0)").simulate( "drag", {
dy: 20
});
ok(hash, 'beforeStop event triggered'); ok(hash, 'beforeStop event triggered');
ok(hash.helper, 'UI hash includes: helper'); ok(hash.helper, 'UI hash includes: helper');
@ -90,9 +111,13 @@ test("stop", function() {
expect( 7 ); expect( 7 );
var hash; var hash;
$("#sortable") $("#sortable").sortable({
.sortable({ stop: function(e, ui) { hash = ui; } }) stop: function( e, ui ) {
.find('li:eq(0)').simulate("drag", { dx: 0, dy: 20 }); hash = ui;
}
}).find("li:eq(0)").simulate( "drag", {
dy: 20
});
ok(hash, 'stop event triggered'); ok(hash, 'stop event triggered');
ok(!hash.helper, 'UI should not include: helper'); ok(!hash.helper, 'UI should not include: helper');
@ -108,15 +133,24 @@ test("update", function() {
expect( 8 ); expect( 8 );
var hash; var hash;
$("#sortable") $("#sortable").sortable({
.sortable({ update: function(e, ui) { hash = ui; } }) update: function( e, ui ) {
.find('li:eq(0)').simulate("drag", { dx: 1, dy: 1 }); hash = ui;
}
}).find("li:eq(0)").simulate( "drag", {
dx: 1,
dy: 1
});
ok(!hash, '1px drag, update event should not be triggered'); ok(!hash, '1px drag, update event should not be triggered');
$("#sortable") $("#sortable").sortable({
.sortable({ update: function(e, ui) { hash = ui; } }) update: function( e, ui ) {
.find('li:eq(0)').simulate("drag", { dx: 0, dy: 22 }); hash = ui;
}
}).find("li:eq(0)").simulate( "drag", {
dy: 22
});
ok(hash, 'update event triggered'); ok(hash, 'update event triggered');
ok(!hash.helper, 'UI hash should not include: helper'); ok(!hash.helper, 'UI hash should not include: helper');
@ -129,14 +163,14 @@ test("update", function() {
}); });
test("#3019: Stop fires too early", function() { test("#3019: Stop fires too early", function() {
expect(2); expect(2);
var helper = null, var helper = null,
el = $("#sortable").sortable({ el = $("#sortable").sortable({
stop: function(event, ui) { stop: function(event, ui) {
helper = ui.helper; helper = ui.helper;
} }
}); });
TestHelpers.sortable.sort($("li", el)[0], 0, 44, 2, 'Dragging the sortable'); TestHelpers.sortable.sort($("li", el)[0], 0, 44, 2, 'Dragging the sortable');
equal(helper, null, "helper should be false"); equal(helper, null, "helper should be false");
@ -144,49 +178,49 @@ test("#3019: Stop fires too early", function() {
}); });
test('#4752: link event firing on sortable with connect list', function () { test('#4752: link event firing on sortable with connect list', function () {
expect( 10 ); expect( 10 );
var fired = {}, var fired = {},
hasFired = function (type) { return (type in fired) && (true === fired[type]); }; hasFired = function (type) { return (type in fired) && (true === fired[type]); };
$('#sortable').clone().attr('id', 'sortable2').insertAfter('#sortable'); $('#sortable').clone().attr('id', 'sortable2').insertAfter('#sortable');
$('#qunit-fixture ul').sortable({ $('#qunit-fixture ul').sortable({
connectWith: '#qunit-fixture ul', connectWith: '#qunit-fixture ul',
change: function () { change: function () {
fired.change = true; fired.change = true;
}, },
receive: function () { receive: function () {
fired.receive = true; fired.receive = true;
}, },
remove: function () { remove: function () {
fired.remove = true; fired.remove = true;
} }
}); });
$('#qunit-fixture ul').bind('click.ui-sortable-test', function () { $('#qunit-fixture ul').bind('click.ui-sortable-test', function () {
fired.click = true; fired.click = true;
}); });
$('#sortable li:eq(0)').simulate('click'); $('#sortable li:eq(0)').simulate('click');
ok(!hasFired('change'), 'Click only, change event should not have fired'); ok(!hasFired('change'), 'Click only, change event should not have fired');
ok(hasFired('click'), 'Click event should have fired'); ok(hasFired('click'), 'Click event should have fired');
// Drag an item within the first list // Drag an item within the first list
fired = {}; fired = {};
$('#sortable li:eq(0)').simulate('drag', { dx: 0, dy: 40 }); $('#sortable li:eq(0)').simulate('drag', { dx: 0, dy: 40 });
ok(hasFired('change'), '40px drag, change event should have fired'); ok(hasFired('change'), '40px drag, change event should have fired');
ok(!hasFired('receive'), 'Receive event should not have fired'); ok(!hasFired('receive'), 'Receive event should not have fired');
ok(!hasFired('remove'), 'Remove event should not have fired'); ok(!hasFired('remove'), 'Remove event should not have fired');
ok(!hasFired('click'), 'Click event should not have fired'); ok(!hasFired('click'), 'Click event should not have fired');
// Drag an item from the first list to the second, connected list // Drag an item from the first list to the second, connected list
fired = {}; fired = {};
$('#sortable li:eq(0)').simulate('drag', { dx: 0, dy: 150 }); $('#sortable li:eq(0)').simulate('drag', { dx: 0, dy: 150 });
ok(hasFired('change'), '150px drag, change event should have fired'); ok(hasFired('change'), '150px drag, change event should have fired');
ok(hasFired('receive'), 'Receive event should have fired'); ok(hasFired('receive'), 'Receive event should have fired');
ok(hasFired('remove'), 'Remove event should have fired'); ok(hasFired('remove'), 'Remove event should have fired');
ok(!hasFired('click'), 'Click event should not have fired'); ok(!hasFired('click'), 'Click event should not have fired');
}); });
/* /*

View File

@ -1,9 +1,9 @@
TestHelpers.sortable = { TestHelpers.sortable = {
sort: function(handle, dx, dy, index, msg) { sort: function( handle, dx, dy, index, msg ) {
$(handle).simulate("drag", { $( handle ).simulate( "drag", {
dx: dx || 0, dx: dx,
dy: dy || 0 dy: dy
}); });
equal($(handle).parent().children().index(handle), index, msg); equal( $( handle ).parent().children().index( handle ), index, msg );
} }
}; };