diff options
author | Mike Sherov <mike.sherov@gmail.com> | 2013-01-12 00:33:45 -0500 |
---|---|---|
committer | Mike Sherov <mike.sherov@gmail.com> | 2013-03-04 01:05:11 -0500 |
commit | c278a4461b399c5b84abf4e03c1d902bfd130441 (patch) | |
tree | 7982633aec7b9c658a72de0524dbd1848a676add /tests/unit/draggable/draggable_events.js | |
parent | 6d3a1e1fe8cc21f385456ea26075f3909136a589 (diff) | |
download | jquery-ui-c278a4461b399c5b84abf4e03c1d902bfd130441.tar.gz jquery-ui-c278a4461b399c5b84abf4e03c1d902bfd130441.zip |
Draggable Tests: Add test coverage for supported options
Diffstat (limited to 'tests/unit/draggable/draggable_events.js')
-rw-r--r-- | tests/unit/draggable/draggable_events.js | 134 |
1 files changed, 80 insertions, 54 deletions
diff --git a/tests/unit/draggable/draggable_events.js b/tests/unit/draggable/draggable_events.js index f4ab3a8ea..199561be3 100644 --- a/tests/unit/draggable/draggable_events.js +++ b/tests/unit/draggable/draggable_events.js @@ -1,99 +1,125 @@ /* * draggable_events.js */ -(function($) { +(function( $ ) { -module("draggable: events"); +var element; -test("callbacks occurrence count", function() { +module( "draggable: events", { + setup: function() { + element = $("<div>").appendTo("#qunit-fixture"); + }, + teardown: function() { + element.draggable("destroy"); + } +}); - expect(3); +test( "callbacks occurrence count", function() { + expect( 3 ); var start = 0, stop = 0, - dragc = 0, - el = $("#draggable2").draggable({ - start: function() { start++; }, - drag: function() { dragc++; }, - stop: function() { stop++; } - }); - - el.simulate( "drag", { + dragc = 0; + + element.draggable({ + start: function() { + start++; + }, + drag: function() { + dragc++; + }, + stop: function() { + stop++; + } + }); + + element.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"); - equal(stop, 1, "stop 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( stop, 1, "stop callback should happen exactly once" ); }); -test("stopping the start callback", function() { - - expect(3); +test( "stopping the start callback", function() { + expect( 3 ); var start = 0, stop = 0, - dragc = 0, - el = $("#draggable2").draggable({ - start: function() { start++; return false; }, - drag: function() { dragc++; }, - stop: function() { stop++; } - }); - - el.simulate( "drag", { + dragc = 0; + + element.draggable({ + start: function() { + start++; + return false; + }, + drag: function() { + dragc++; + }, + stop: function() { + stop++; + } + }); + + element.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"); - equal(stop, 0, "stop callback should not happen if there wasnt even a start"); - + equal( start, 1, "start callback should happen exactly once" ); + equal( dragc, 0, "drag callback should not happen at all" ); + equal( stop, 0, "stop callback should not happen if there wasnt even a start" ); }); -test("stopping the drag callback", function() { - - expect(3); +test( "stopping the drag callback", function() { + expect( 2 ); var start = 0, stop = 0, - dragc = 0, - el = $("#draggable2").draggable({ - start: function() { start++;}, - drag: function() { dragc++; return false; }, - stop: function() { stop++; } - }); - - el.simulate( "drag", { + dragc = 0; + + element.draggable({ + start: function() { + start++; + }, + drag: function() { + dragc++; + return false; + }, + stop: function() { + stop++; + } + }); + + element.simulate( "drag", { dx: 10, dy: 10 }); - equal(start, 1, "start callback should happen exactly once"); - equal(dragc, 1, "drag callback should happen exactly once"); - equal(stop, 1, "stop callback should happen, as we need to actively stop the drag"); - + equal( start, 1, "start callback should happen exactly once" ); + equal( stop, 1, "stop callback should happen, as we need to actively stop the drag" ); }); -test("stopping the stop callback", function() { - - expect(1); +test( "stopping the stop callback", function() { + expect( 1 ); - var el = $("#draggable2").draggable({ + element.draggable({ helper: "clone", - stop: function() { return false; } + stop: function() { + return false; + } }); - el.simulate( "drag", { + element.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( element.data("ui-draggable").helper, "the clone should not be deleted if the stop callback is stopped" ); }); -})(jQuery); +})( jQuery ); |