aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/draggable
diff options
context:
space:
mode:
authorFelix Nagel <info@felixnagel.com>2013-03-19 19:59:31 +0100
committerFelix Nagel <info@felixnagel.com>2013-03-19 19:59:31 +0100
commit1ce8d87f8bee3b1ec8698e0e2b8ead726d0d4ca2 (patch)
tree77edf8d66ab74aa11b86c286ba2a528b4d3c36de /tests/unit/draggable
parent5a9a80f86cc7844e7357af834c61cc14431110d1 (diff)
parent1c1f7c6184ba6f6a13e93960ea77c293f9d4308e (diff)
downloadjquery-ui-1ce8d87f8bee3b1ec8698e0e2b8ead726d0d4ca2.tar.gz
jquery-ui-1ce8d87f8bee3b1ec8698e0e2b8ead726d0d4ca2.zip
Merge branch 'master' into selectmenu
Diffstat (limited to 'tests/unit/draggable')
-rw-r--r--tests/unit/draggable/draggable.html2
-rw-r--r--tests/unit/draggable/draggable_events.js2
-rw-r--r--tests/unit/draggable/draggable_methods.js14
-rw-r--r--tests/unit/draggable/draggable_options.js163
-rw-r--r--tests/unit/draggable/draggable_test_helpers.js4
5 files changed, 150 insertions, 35 deletions
diff --git a/tests/unit/draggable/draggable.html b/tests/unit/draggable/draggable.html
index 6380f3e85..3d1d3326e 100644
--- a/tests/unit/draggable/draggable.html
+++ b/tests/unit/draggable/draggable.html
@@ -48,7 +48,7 @@
<div id="qunit-fixture">
<div id="main"></div>
<div id="draggable1" style="background: green; width: 200px; height: 100px;">Relative</div>
- <div id="draggable2" style="background: green; width: 200px; height: 100px; position: absolute; top: 10px; left: 10px;"><span>Absolute</span></div>
+ <div id="draggable2" style="background: green; width: 200px; height: 100px; position: absolute; top: 10px; left: 10px;"><span><em>Absolute</em></span></div>
<div id="droppable" style="background: green; width: 200px; height: 100px; position: absolute; top: 110px; left: 110px;"><span>Absolute</span></div>
<div style="width: 1px; height: 1000px;"></div>
<div style="position: absolute; width: 1px; height: 2000px;"></div>
diff --git a/tests/unit/draggable/draggable_events.js b/tests/unit/draggable/draggable_events.js
index 199561be3..bbaaaeb15 100644
--- a/tests/unit/draggable/draggable_events.js
+++ b/tests/unit/draggable/draggable_events.js
@@ -117,7 +117,7 @@ test( "stopping the stop callback", function() {
dy: 10
});
- ok( element.data("ui-draggable").helper, "the clone should not be deleted if the stop callback is stopped" );
+ ok( element.draggable( "instance" ).helper, "the clone should not be deleted if the stop callback is stopped" );
});
diff --git a/tests/unit/draggable/draggable_methods.js b/tests/unit/draggable/draggable_methods.js
index 901c261d6..63a19e26d 100644
--- a/tests/unit/draggable/draggable_methods.js
+++ b/tests/unit/draggable/draggable_methods.js
@@ -74,16 +74,16 @@ test( "enable", function() {
});
test( "disable", function() {
- expect( 7 );
+ expect( 10 );
- element = $("#draggable2").draggable({ disabled: false });
+ element = $( "#draggable2" ).draggable({ disabled: false });
TestHelpers.draggable.shouldMove( element, ".draggable({ disabled: false })" );
- element.draggable("disable");
+ element.draggable( "disable" );
TestHelpers.draggable.shouldNotMove( element, ".draggable('disable')" );
equal( element.draggable( "option", "disabled" ), true, "disabled option getter" );
- element.draggable("destroy");
+ element.draggable( "destroy" );
element.draggable({ disabled: false });
TestHelpers.draggable.shouldMove( element, ".draggable({ disabled: false })" );
@@ -91,8 +91,12 @@ test( "disable", function() {
equal( element.draggable( "option", "disabled" ), true, "disabled option setter" );
TestHelpers.draggable.shouldNotMove( element, ".draggable('option', 'disabled', true)" );
+ ok( !element.draggable( "widget" ).hasClass( "ui-state-disabled" ), "element does not get ui-state-disabled" );
+ ok( !element.draggable( "widget" ).attr( "aria-disabled" ), "element does not get aria-disabled" );
+ ok( element.draggable( "widget" ).hasClass( "ui-draggable-disabled" ), "element gets ui-draggable-disabled" );
+
var expected = element.draggable(),
- actual = expected.draggable("disable");
+ actual = expected.draggable( "disable" );
equal( actual, expected, "disable is chainable" );
});
diff --git a/tests/unit/draggable/draggable_options.js b/tests/unit/draggable/draggable_options.js
index ccbe7224a..f4fca0b2e 100644
--- a/tests/unit/draggable/draggable_options.js
+++ b/tests/unit/draggable/draggable_options.js
@@ -346,6 +346,37 @@ test( "{ containment: 'parent' }, absolute", function() {
deepEqual( offsetAfter, expected, "compare offset to parent" );
});
+test( "containment, account for border", function() {
+ expect( 2 );
+
+ var el = $("#draggable1").appendTo("#main"),
+ parent = el.parent().css({
+ height: "100px",
+ width: "100px",
+ borderStyle: "solid",
+ borderWidth: "5px 10px 15px 20px"
+ }),
+ parentBottom = parent.offset().top + parent.outerHeight(),
+ parentRight = parent.offset().left + parent.outerWidth(),
+ parentBorderBottom = TestHelpers.draggable.border( parent, "bottom" ),
+ parentBorderRight = TestHelpers.draggable.border( parent, "right" );
+
+ el.css({
+ height: "5px",
+ width: "5px"
+ }).draggable({ containment: "parent" });
+
+ el.simulate( "drag", {
+ dx: 100,
+ dy: 100
+ });
+
+ equal( el.offset().top, parentBottom - parentBorderBottom - el.height(),
+ "The draggable should be on top of its parent's bottom border" );
+ equal( el.offset().left, parentRight - parentBorderRight - el.width(),
+ "The draggable should be to the right of its parent's right border" );
+});
+
test( "containment, default, switching after initialization", function() {
expect( 2 );
@@ -572,39 +603,15 @@ test( "grid, switching after initialization", function() {
});
test( "{ handle: 'span' }", function() {
- expect( 2 );
+ expect( 3 );
var element = $( "#draggable2" ).draggable({ handle: "span" });
TestHelpers.draggable.testDrag( element, "#draggable2 span", 50, 50, 50, 50, "drag span" );
+ TestHelpers.draggable.testDrag( element, "#draggable2 span em", 50, 50, 50, 50, "drag span child" );
TestHelpers.draggable.shouldNotMove( element, "drag element" );
});
-/*
-test( "{ handle: Selectors }, matching parent selector", function() {
-
- expect( 4 );
-
- var element = $( "#draggable2" ).draggable({ handle: "span a" });
-
- $( "#qunit-fixture" ).append( "<span id='wrapping'><a></a></span>" );
-
- element.find( "span" ).append( "<a>" );
-
- $( "#wrapping a" ).append( element );
-
- TestHelpers.draggable.testDrag( element, "#draggable2 span a", 50, 50, 50, 50, "drag span child" );
- TestHelpers.draggable.shouldNotMove( $( "#wrapping a" ) );
-
- $( "#draggable2" ).draggable( "option", "handle", "span > a" );
- $( "#draggable2" ).find( "a" ).append( "<a>" );
-
- TestHelpers.draggable.testDrag( element, $( "#draggable2 span a" ).first(), 50, 50, 50, 50, "drag span child" );
- TestHelpers.draggable.shouldNotMove( $( "#draggable2 span a" ).last() );
-
-});
-*/
-
test( "handle, default, switching after initialization", function() {
expect( 6 );
@@ -1096,6 +1103,40 @@ test( "scroll, scrollSensitivity, and scrollSpeed", function() {
TestHelpers.draggable.restoreScroll( document );
});
+test( "#6817: auto scroll goes double distance when dragging", function() {
+ expect( 2 );
+
+ var offsetBefore,
+ distance = 10,
+ viewportHeight = $( window ).height(),
+ element = $( "#draggable1" ).draggable({
+ scroll: true,
+ stop: function( e, ui ) {
+ equal( ui.offset.top, newY, "offset of item matches pointer position after scroll" );
+ equal( ui.offset.top - offsetBefore.top, distance, "offset of item only moves expected distance after scroll" );
+ }
+ }),
+ scrollSensitivity = element.draggable( "option", "scrollSensitivity" ),
+ oldY = viewportHeight - scrollSensitivity,
+ newY = oldY + distance;
+
+ element.offset({
+ top: oldY,
+ left: 1
+ });
+
+ offsetBefore = element.offset();
+
+ element.simulate( "drag", {
+ handle: "corner",
+ dx: 1,
+ y: newY,
+ moves: 1
+ });
+
+ TestHelpers.draggable.restoreScroll( document );
+});
+
test( "snap, snapMode, and snapTolerance", function() {
expect( 9 );
@@ -1216,6 +1257,76 @@ test( "snap, snapMode, and snapTolerance", function() {
deepEqual( element.offset(), { top: newY, left: newX }, "doesn't snap on the inner snapTolerance area when snapMode is outer" );
});
+test( "#8459: element can snap to an element that was removed during drag", function() {
+ expect( 1 );
+
+ var newX, newY,
+ snapTolerance = 15,
+ element = $( "#draggable1" ).draggable({
+ snap: true,
+ snapMode: "both",
+ snapTolerance: snapTolerance,
+ start: function() {
+ element2.remove();
+ }
+ }),
+ element2 = $( "#draggable2" ).draggable();
+
+ element.offset({
+ top: 1,
+ left: 1
+ });
+
+ newX = element2.offset().left - element.outerWidth() - snapTolerance + 1;
+ newY = element2.offset().top;
+
+ element.simulate( "drag", {
+ handle: "corner",
+ x: newX,
+ y: newY,
+ moves: 1
+ });
+
+ deepEqual( element.offset(), { top: newY, left: newX }, "doesn't snap to a removed element" );
+});
+
+test( "#8165: Snapping large rectangles to small rectangles doesn't snap properly", function() {
+ expect( 1 );
+
+ var snapTolerance = 20,
+ y = 1,
+ element = $( "#draggable1" )
+ .css({
+ width: "50px",
+ height: "200px"
+ }).offset({
+ top: y,
+ left: 1
+ }),
+ element2 = $( "#draggable2" )
+ .css({
+ width: "50px",
+ height: "50px"
+ }).offset({
+ top: y + snapTolerance + 1,
+ left: 200
+ }),
+ newX = element2.offset().left - element.outerWidth() - snapTolerance + 1;
+
+ $( "#draggable1, #draggable2" ).draggable({
+ snap: true,
+ snapTolerance: snapTolerance
+ });
+
+ element.simulate( "drag", {
+ handle: "corner",
+ x: newX,
+ moves: 1
+ });
+
+ notDeepEqual( element.offset(), { top: y, left: newX }, "snaps even if only a side (not a corner) is inside the snapTolerance" );
+});
+
test( "stack", function() {
expect( 2 );
diff --git a/tests/unit/draggable/draggable_test_helpers.js b/tests/unit/draggable/draggable_test_helpers.js
index e1c79c6cc..44e37c559 100644
--- a/tests/unit/draggable/draggable_test_helpers.js
+++ b/tests/unit/draggable/draggable_test_helpers.js
@@ -60,7 +60,7 @@ TestHelpers.draggable = {
},
trackMouseCss : function( el ) {
- el.on( "drag", function() {
+ el.bind( "drag", function() {
el.data( "last_dragged_cursor", $("body").css("cursor") );
});
},
@@ -69,7 +69,7 @@ TestHelpers.draggable = {
// appendTo ignored without being clone
el.draggable( "option", "helper", "clone" );
- el.on( "drag", function(e,ui) {
+ el.bind( "drag", function(e,ui) {
// Get what parent is at time of drag
el.data( "last_dragged_parent", ui.helper.parent()[0] );
});