Skip to content
Permalink
Browse files

Dev: remove unnecessary simulated drag delegation in test suite

  • Loading branch information...
mikesherov committed Dec 9, 2012
1 parent 5dee8de commit 9f764467751c1c5bdefa28421807eafc9868b37f
@@ -3,10 +3,9 @@ TestHelpers.dialog = {
var d = el.dialog('widget');
//this mouseover is to work around a limitation in resizable
//TODO: fix resizable so handle doesn't require mouseover in order to be used
$(handle, d).simulate("mouseover");
$(handle, d).simulate("drag", {
dx: dx || 0,
dy: dy || 0
$( handle, d ).simulate("mouseover").simulate( "drag", {
dx: dx,
dy: dy
});
},
testDrag: function(el, dx, dy, expectedDX, expectedDY, msg) {
@@ -22,7 +22,10 @@ test("element types", function() {
(typeName === 'table' && el.append("<tr><td>content</td></tr>"));
el.draggable({ cancel: '' });
offsetBefore = el.offset();
TestHelpers.draggable.drag(el, 50, 50);
el.simulate( "drag", {
dx: 50,
dy: 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
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>'))
);

var handle = '.ui-resizable-w div',
target = $('#draggable1').draggable().resizable({ handles: 'all' }),
drag = function(el, dx) {
$(el)
.simulate("mouseover")
.simulate("drag", {
dx: dx || 0,
speed: 'sync'
});
};
var handle = $('.ui-resizable-w div'),
target = $('#draggable1').draggable().resizable({ handles: 'all' });

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

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" );
});

@@ -18,7 +18,10 @@ test("callbacks occurrence count", function() {
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(dragc, 3, "drag callback should happen exactly once per mousemove");
@@ -39,7 +42,10 @@ test("stopping the start callback", function() {
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(dragc, 0, "drag callback should not happen at all");
@@ -60,7 +66,10 @@ test("stopping the drag callback", function() {
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(dragc, 1, "drag callback should happen exactly once");
@@ -77,7 +86,10 @@ test("stopping the stop callback", function() {
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");

@@ -162,7 +162,11 @@ test("{ containment: 'parent' }, relative", function() {
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')
};
TestHelpers.draggable.drag(el, -100, -100);

el.simulate( "drag", {
dx: -100,
dy: -100
});
offsetAfter = el.offset();
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'),
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();
deepEqual(offsetAfter, expected, 'compare offset to parent');
});
@@ -214,17 +222,20 @@ test("{ cursor: 'auto' }, default", function() {

expect(2);

var expected = "auto", actual, before, after;

$("#draggable2").draggable({
cursor: expected,
start: function() {
actual = getCursor();
}
});
var actual, before, after,
expected = "auto",
el = $("#draggable2").draggable({
cursor: expected,
start: function() {
actual = getCursor();
}
});

before = getCursor();
TestHelpers.draggable.drag("#draggable2", -1, -1);
el.simulate( "drag", {
dx: -1,
dy: -1
});
after = getCursor();

equal(actual, expected, "start callback: cursor '" + expected + "'");
@@ -238,17 +249,20 @@ test("{ cursor: 'move' }", function() {

expect(2);

var expected = "move", actual, before, after;

$("#draggable2").draggable({
cursor: expected,
start: function() {
actual = getCursor();
}
});
var actual, before, after,
expected = "move",
el = $("#draggable2").draggable({
cursor: expected,
start: function() {
actual = getCursor();
}
});

before = getCursor();
TestHelpers.draggable.drag("#draggable2", -1, -1);
el.simulate( "drag", {
dx: -1,
dy: -1
});
after = getCursor();

equal(actual, expected, "start callback: cursor '" + expected + "'");
@@ -648,7 +662,10 @@ test("{ helper: 'clone' }, absolute", function() {
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] ');

});
@@ -666,17 +683,26 @@ test("{ helper: 'clone' }, absolute with scroll offset on parent", function() {

$("#main").css('position', 'relative');
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] ');

$("#main").css('position', 'static');
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] ');

$("#main").css('position', 'absolute');
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] ');

TestHelpers.draggable.restoreScroll();
@@ -696,17 +722,26 @@ test("{ helper: 'clone' }, absolute with scroll offset on root", function() {

$("#main").css('position', 'relative');
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] ');

$("#main").css('position', 'static');
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] ');

$("#main").css('position', 'absolute');
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] ');

TestHelpers.draggable.restoreScroll('root');
@@ -728,17 +763,26 @@ test("{ helper: 'clone' }, absolute with scroll offset on root and parent", func

$("#main").css('position', 'relative');
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] ');

$("#main").css('position', 'static');
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] ');

$("#main").css('position', 'absolute');
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] ');

TestHelpers.draggable.restoreScroll('root');
@@ -750,17 +794,19 @@ test("{ opacity: 0.5 }", function() {

expect(1);

var opacity = null;

$("#draggable2").draggable({
opacity: 0.5,
start: function() {
opacity = $(this).css("opacity");
}
var opacity = null,
el = $("#draggable2").draggable({
opacity: 0.5,
start: function() {
opacity = $(this).css("opacity");
}
});

el.simulate( "drag", {
dx: -1,
dy: -1
});

TestHelpers.draggable.drag("#draggable2", -1, -1);

equal(opacity, 0.5, "start callback: opacity is");

});
@@ -770,17 +816,19 @@ test("{ zIndex: 10 }", function() {
expect(1);

var actual,
expected = 10;

$("#draggable2").draggable({
zIndex: expected,
start: function() {
actual = $(this).css("zIndex");
}
expected = 10,
el = $("#draggable2").draggable({
zIndex: expected,
start: function() {
actual = $(this).css("zIndex");
}
});

el.simulate( "drag", {
dx: -1,
dy: -1
});

TestHelpers.draggable.drag("#draggable2", -1, -1);

equal(actual, expected, "start callback: zIndex is");

});
@@ -1,17 +1,14 @@
TestHelpers.draggable = {
// todo: remove the unreliable offset hacks
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) {
var offsetAfter, actual, expected,
offsetBefore = el.offset();

TestHelpers.draggable.drag(handle, dx, dy);
$( handle ).simulate( "drag", {
dx: dx,
dy: dy
});
offsetAfter = el.offset();

actual = { left: offsetAfter.left, top: offsetAfter.top },
@@ -1,15 +1,10 @@
TestHelpers.resizable = {
drag: function(el, dx, dy, complete) {

// speed = sync -> Drag syncrhonously.
// speed = fast|slow -> Drag asyncrhonously - animated.

//this mouseover is to work around a limitation in resizable
//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
drag: function( el, dx, dy ) {
// this mouseover is to work around a limitation in resizable
// TODO: fix resizable so handle doesn't require mouseover in order to be used
$( el ).simulate("mouseover").simulate( "drag", {
dx: dx,
dy: dy
});
}
};

0 comments on commit 9f76446

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