From 9f764467751c1c5bdefa28421807eafc9868b37f Mon Sep 17 00:00:00 2001 From: Mike Sherov Date: Sat, 8 Dec 2012 21:27:37 -0500 Subject: [PATCH] Dev: remove unnecessary simulated drag delegation in test suite --- tests/unit/dialog/dialog_test_helpers.js | 7 +- tests/unit/draggable/draggable_core.js | 23 +-- tests/unit/draggable/draggable_events.js | 20 +- tests/unit/draggable/draggable_options.js | 144 +++++++++----- .../unit/draggable/draggable_test_helpers.js | 11 +- .../unit/resizable/resizable_test_helpers.js | 17 +- tests/unit/selectable/selectable_events.js | 30 +-- tests/unit/selectable/selectable_methods.js | 21 +- tests/unit/selectable/selectable_options.js | 22 ++- .../selectable/selectable_test_helpers.js | 8 - tests/unit/sortable/sortable_events.js | 180 +++++++++++------- tests/unit/sortable/sortable_test_helpers.js | 10 +- 12 files changed, 300 insertions(+), 193 deletions(-) delete mode 100644 tests/unit/selectable/selectable_test_helpers.js diff --git a/tests/unit/dialog/dialog_test_helpers.js b/tests/unit/dialog/dialog_test_helpers.js index bbf43f48f..ef0b9b6fa 100644 --- a/tests/unit/dialog/dialog_test_helpers.js +++ b/tests/unit/dialog/dialog_test_helpers.js @@ -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) { diff --git a/tests/unit/draggable/draggable_core.js b/tests/unit/draggable/draggable_core.js index 66628465b..2bfccbfa6 100644 --- a/tests/unit/draggable/draggable_core.js +++ b/tests/unit/draggable/draggable_core.js @@ -22,7 +22,10 @@ test("element types", function() { (typeName === 'table' && el.append("content")); 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($('
')) ); - 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" ); }); diff --git a/tests/unit/draggable/draggable_events.js b/tests/unit/draggable/draggable_events.js index 5eab97713..07a53e22e 100644 --- a/tests/unit/draggable/draggable_events.js +++ b/tests/unit/draggable/draggable_events.js @@ -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"); diff --git a/tests/unit/draggable/draggable_options.js b/tests/unit/draggable/draggable_options.js index 3f4592d31..d9a7038f7 100644 --- a/tests/unit/draggable/draggable_options.js +++ b/tests/unit/draggable/draggable_options.js @@ -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"); }); diff --git a/tests/unit/draggable/draggable_test_helpers.js b/tests/unit/draggable/draggable_test_helpers.js index 7057df1f8..9a6355b2e 100644 --- a/tests/unit/draggable/draggable_test_helpers.js +++ b/tests/unit/draggable/draggable_test_helpers.js @@ -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 }, diff --git a/tests/unit/resizable/resizable_test_helpers.js b/tests/unit/resizable/resizable_test_helpers.js index fe6c84900..88f2bc57b 100644 --- a/tests/unit/resizable/resizable_test_helpers.js +++ b/tests/unit/resizable/resizable_test_helpers.js @@ -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 }); } }; \ No newline at end of file diff --git a/tests/unit/selectable/selectable_events.js b/tests/unit/selectable/selectable_events.js index 331bae146..984fd1862 100644 --- a/tests/unit/selectable/selectable_events.js +++ b/tests/unit/selectable/selectable_events.js @@ -1,32 +1,38 @@ /* * selectable_events.js */ -(function($) { +(function( $ ) { module("selectable: events"); -test("start", function() { - expect(2); +test( "start", function() { + expect( 2 ); var el = $("#selectable1"); el.selectable({ start: function() { - ok(true, "drag fired start callback"); - equal(this, el[0], "context of callback"); + ok( true, "drag fired start callback" ); + equal( this, el[0], "context of callback" ); } }); - el.simulate("drag", 20, 20); + el.simulate( "drag", { + dx: 20, + dy: 20 + }); }); -test("stop", function() { - expect(2); +test( "stop", function() { + expect( 2 ); var el = $("#selectable1"); el.selectable({ start: function() { - ok(true, "drag fired stop callback"); - equal(this, el[0], "context of callback"); + ok( true, "drag fired stop callback" ); + equal( this, el[0], "context of callback" ); } }); - el.simulate("drag", 20, 20); + el.simulate( "drag", { + dx: 20, + dy: 20 + }); }); -})(jQuery); +})( jQuery ); diff --git a/tests/unit/selectable/selectable_methods.js b/tests/unit/selectable/selectable_methods.js index aa8924176..d894a13e4 100644 --- a/tests/unit/selectable/selectable_methods.js +++ b/tests/unit/selectable/selectable_methods.js @@ -53,10 +53,16 @@ test("enable", function() { disabled: true, start: function() { fired = true; } }); - el.simulate("drag", 20, 20); + el.simulate( "drag", { + dx: 20, + dy: 20 + }); equal(fired, false, "start fired"); el.selectable("enable"); - el.simulate("drag", 20, 20); + el.simulate( "drag", { + dx: 20, + dy: 20 + }); equal(fired, true, "start fired"); el.selectable("destroy"); @@ -75,11 +81,18 @@ test("disable", function() { disabled: false, start: function() { fired = true; } }); - el.simulate("drag", 20, 20); + el.simulate( "drag", { + dx: 20, + dy: 20 + }); equal(fired, true, "start fired"); el.selectable("disable"); fired = false; - el.simulate("drag", 20, 20); + + el.simulate( "drag", { + dx: 20, + dy: 20 + }); equal(fired, false, "start fired"); el.selectable("destroy"); diff --git a/tests/unit/selectable/selectable_options.js b/tests/unit/selectable/selectable_options.js index 50e047427..a2455fdca 100644 --- a/tests/unit/selectable/selectable_options.js +++ b/tests/unit/selectable/selectable_options.js @@ -15,7 +15,10 @@ test("autoRefresh", function() { el = $("#selectable1").selectable({ autoRefresh: false, selected: selected }); sel.hide(); - TestHelpers.selectable.drag(el, 1000, 1000); + el.simulate( "drag", { + dx: 1000, + dy: 1000 + }); equal(actual, sel.length); el.selectable("destroy"); @@ -23,11 +26,19 @@ test("autoRefresh", function() { sel.show(); el = $("#selectable1").selectable({ autoRefresh: true, selected: selected }); sel.hide(); - TestHelpers.selectable.drag(el, 1000, 1000); + el.simulate( "drag", { + dx: 1000, + dy: 1000 + }); equal(actual, 0); + sel.show(); - TestHelpers.selectable.drag( sel[ 0 ], 1000, 1000 ); + $( sel[ 0 ] ).simulate( "drag", { + dx: 1000, + dy: 1000 + }); equal(actual, sel.length); + el.selectable("destroy"); sel.show(); }); @@ -42,7 +53,10 @@ test("filter", function() { 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"); equal(actual, 1); el.selectable("destroy"); diff --git a/tests/unit/selectable/selectable_test_helpers.js b/tests/unit/selectable/selectable_test_helpers.js deleted file mode 100644 index 6f87efbb3..000000000 --- a/tests/unit/selectable/selectable_test_helpers.js +++ /dev/null @@ -1,8 +0,0 @@ -TestHelpers.selectable = { - drag: function( el, dx, dy ) { - $( el ).simulate( "drag", { - dx: dx || 0, - dy: dy || 0 - }); - } -}; \ No newline at end of file diff --git a/tests/unit/sortable/sortable_events.js b/tests/unit/sortable/sortable_events.js index 4245d64fa..b9ee078f5 100644 --- a/tests/unit/sortable/sortable_events.js +++ b/tests/unit/sortable/sortable_events.js @@ -9,9 +9,13 @@ test("start", function() { expect( 7 ); var hash; - $("#sortable") - .sortable({ start: function(e, ui) { hash = ui; } }) - .find('li:eq(0)').simulate("drag", { dx: 0, dy: 10 }); + $("#sortable").sortable({ + start: function( e, ui ) { + hash = ui; + } + }).find("li:eq(0)").simulate( "drag", { + dy: 10 + }); ok(hash, 'start event triggered'); ok(hash.helper, 'UI hash includes: helper'); @@ -30,9 +34,13 @@ test("sort", function() { expect( 7 ); var hash; - $("#sortable") - .sortable({ sort: function(e, ui) { hash = ui; } }) - .find('li:eq(0)').simulate("drag", { dx: 0, dy: 10 }); + $("#sortable").sortable({ + sort: function( e, ui ) { + hash = ui; + } + }).find("li:eq(0)").simulate( "drag", { + dy: 10 + }); ok(hash, 'sort event triggered'); ok(hash.helper, 'UI hash includes: helper'); @@ -48,15 +56,24 @@ test("change", function() { expect( 8 ); var hash; - $("#sortable") - .sortable({ change: function(e, ui) { hash = ui; } }) - .find('li:eq(0)').simulate("drag", { dx: 1, dy: 1 }); + $("#sortable").sortable({ + change: function( e, ui ) { + hash = ui; + } + }).find("li:eq(0)").simulate( "drag", { + dx: 1, + dy: 1 + }); ok(!hash, '1px drag, change event should not be triggered'); - $("#sortable") - .sortable({ change: function(e, ui) { hash = ui; } }) - .find('li:eq(0)').simulate("drag", { dx: 0, dy: 22 }); + $("#sortable").sortable({ + change: function( e, ui ) { + hash = ui; + } + }).find("li:eq(0)").simulate( "drag", { + dy: 22 + }); ok(hash, 'change event triggered'); ok(hash.helper, 'UI hash includes: helper'); @@ -72,9 +89,13 @@ test("beforeStop", function() { expect( 7 ); var hash; - $("#sortable") - .sortable({ beforeStop: function(e, ui) { hash = ui; } }) - .find('li:eq(0)').simulate("drag", { dx: 0, dy: 20 }); + $("#sortable").sortable({ + beforeStop: function( e, ui ) { + hash = ui; + } + }).find("li:eq(0)").simulate( "drag", { + dy: 20 + }); ok(hash, 'beforeStop event triggered'); ok(hash.helper, 'UI hash includes: helper'); @@ -90,9 +111,13 @@ test("stop", function() { expect( 7 ); var hash; - $("#sortable") - .sortable({ stop: function(e, ui) { hash = ui; } }) - .find('li:eq(0)').simulate("drag", { dx: 0, dy: 20 }); + $("#sortable").sortable({ + stop: function( e, ui ) { + hash = ui; + } + }).find("li:eq(0)").simulate( "drag", { + dy: 20 + }); ok(hash, 'stop event triggered'); ok(!hash.helper, 'UI should not include: helper'); @@ -108,15 +133,24 @@ test("update", function() { expect( 8 ); var hash; - $("#sortable") - .sortable({ update: function(e, ui) { hash = ui; } }) - .find('li:eq(0)').simulate("drag", { dx: 1, dy: 1 }); + $("#sortable").sortable({ + update: function( e, ui ) { + hash = ui; + } + }).find("li:eq(0)").simulate( "drag", { + dx: 1, + dy: 1 + }); ok(!hash, '1px drag, update event should not be triggered'); - $("#sortable") - .sortable({ update: function(e, ui) { hash = ui; } }) - .find('li:eq(0)').simulate("drag", { dx: 0, dy: 22 }); + $("#sortable").sortable({ + update: function( e, ui ) { + hash = ui; + } + }).find("li:eq(0)").simulate( "drag", { + dy: 22 + }); ok(hash, 'update event triggered'); ok(!hash.helper, 'UI hash should not include: helper'); @@ -129,14 +163,14 @@ test("update", function() { }); test("#3019: Stop fires too early", function() { - expect(2); + expect(2); var helper = null, - el = $("#sortable").sortable({ - stop: function(event, ui) { - helper = ui.helper; - } - }); + el = $("#sortable").sortable({ + stop: function(event, ui) { + helper = ui.helper; + } + }); TestHelpers.sortable.sort($("li", el)[0], 0, 44, 2, 'Dragging the sortable'); 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 () { - expect( 10 ); - - var fired = {}, - hasFired = function (type) { return (type in fired) && (true === fired[type]); }; - - $('#sortable').clone().attr('id', 'sortable2').insertAfter('#sortable'); - - $('#qunit-fixture ul').sortable({ - connectWith: '#qunit-fixture ul', - change: function () { - fired.change = true; - }, - receive: function () { - fired.receive = true; - }, - remove: function () { - fired.remove = true; - } - }); - - $('#qunit-fixture ul').bind('click.ui-sortable-test', function () { - fired.click = true; - }); - - $('#sortable li:eq(0)').simulate('click'); - ok(!hasFired('change'), 'Click only, change event should not have fired'); - ok(hasFired('click'), 'Click event should have fired'); - - // Drag an item within the first list - fired = {}; - $('#sortable li:eq(0)').simulate('drag', { dx: 0, dy: 40 }); - ok(hasFired('change'), '40px drag, change event should have fired'); - ok(!hasFired('receive'), 'Receive event should not have fired'); - ok(!hasFired('remove'), 'Remove 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 - fired = {}; - $('#sortable li:eq(0)').simulate('drag', { dx: 0, dy: 150 }); - ok(hasFired('change'), '150px drag, change event should have fired'); - ok(hasFired('receive'), 'Receive event should have fired'); - ok(hasFired('remove'), 'Remove event should have fired'); - ok(!hasFired('click'), 'Click event should not have fired'); + expect( 10 ); + + var fired = {}, + hasFired = function (type) { return (type in fired) && (true === fired[type]); }; + + $('#sortable').clone().attr('id', 'sortable2').insertAfter('#sortable'); + + $('#qunit-fixture ul').sortable({ + connectWith: '#qunit-fixture ul', + change: function () { + fired.change = true; + }, + receive: function () { + fired.receive = true; + }, + remove: function () { + fired.remove = true; + } + }); + + $('#qunit-fixture ul').bind('click.ui-sortable-test', function () { + fired.click = true; + }); + + $('#sortable li:eq(0)').simulate('click'); + ok(!hasFired('change'), 'Click only, change event should not have fired'); + ok(hasFired('click'), 'Click event should have fired'); + + // Drag an item within the first list + fired = {}; + $('#sortable li:eq(0)').simulate('drag', { dx: 0, dy: 40 }); + ok(hasFired('change'), '40px drag, change event should have fired'); + ok(!hasFired('receive'), 'Receive event should not have fired'); + ok(!hasFired('remove'), 'Remove 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 + fired = {}; + $('#sortable li:eq(0)').simulate('drag', { dx: 0, dy: 150 }); + ok(hasFired('change'), '150px drag, change event should have fired'); + ok(hasFired('receive'), 'Receive event should have fired'); + ok(hasFired('remove'), 'Remove event should have fired'); + ok(!hasFired('click'), 'Click event should not have fired'); }); /* diff --git a/tests/unit/sortable/sortable_test_helpers.js b/tests/unit/sortable/sortable_test_helpers.js index 7569b5797..12e4829ea 100644 --- a/tests/unit/sortable/sortable_test_helpers.js +++ b/tests/unit/sortable/sortable_test_helpers.js @@ -1,9 +1,9 @@ TestHelpers.sortable = { - sort: function(handle, dx, dy, index, msg) { - $(handle).simulate("drag", { - dx: dx || 0, - dy: dy || 0 + sort: function( handle, dx, dy, index, msg ) { + $( handle ).simulate( "drag", { + dx: dx, + dy: dy }); - equal($(handle).parent().children().index(handle), index, msg); + equal( $( handle ).parent().children().index( handle ), index, msg ); } }; \ No newline at end of file -- 2.39.5