mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Draggable: Added tests for containment and cursor.
This commit is contained in:
parent
c9001874dc
commit
e85402f553
@ -64,7 +64,7 @@ test("{ appendTo: 'parent' }, default", function() {
|
|||||||
equal( el.draggable( "option", "appendTo" ), "parent" );
|
equal( el.draggable( "option", "appendTo" ), "parent" );
|
||||||
|
|
||||||
TestHelpers.draggable.move(el, 1, 1);
|
TestHelpers.draggable.move(el, 1, 1);
|
||||||
equal( el.data("last_parent"), $("#qunit-fixture")[0] );
|
equal( el.data("last_dragged_parent"), $("#qunit-fixture")[0] );
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ test("{ appendTo: Element }", function() {
|
|||||||
TestHelpers.draggable.trackAppendedParent(el);
|
TestHelpers.draggable.trackAppendedParent(el);
|
||||||
|
|
||||||
TestHelpers.draggable.move(el, 1, 1);
|
TestHelpers.draggable.move(el, 1, 1);
|
||||||
equal( el.data("last_parent"), appendTo );
|
equal( el.data("last_dragged_parent"), appendTo );
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ test("{ appendTo: jQuery }", function() {
|
|||||||
TestHelpers.draggable.trackAppendedParent(el);
|
TestHelpers.draggable.trackAppendedParent(el);
|
||||||
|
|
||||||
TestHelpers.draggable.move(el, 1, 1);
|
TestHelpers.draggable.move(el, 1, 1);
|
||||||
equal( el.data("last_parent"), appendTo[0] );
|
equal( el.data("last_dragged_parent"), appendTo[0] );
|
||||||
|
|
||||||
});
|
});
|
||||||
test("{ appendTo: Selector }", function() {
|
test("{ appendTo: Selector }", function() {
|
||||||
@ -106,12 +106,12 @@ test("{ appendTo: Selector }", function() {
|
|||||||
TestHelpers.draggable.trackAppendedParent(el);
|
TestHelpers.draggable.trackAppendedParent(el);
|
||||||
|
|
||||||
TestHelpers.draggable.move(el, 1, 1);
|
TestHelpers.draggable.move(el, 1, 1);
|
||||||
equal( el.data("last_parent"), $(appendTo)[0] );
|
equal( el.data("last_dragged_parent"), $(appendTo)[0] );
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
test("{ appendTo: 'parent' }, switching after initialization", function() {
|
test("appendTo, default, switching after initialization", function() {
|
||||||
|
|
||||||
expect(2);
|
expect(2);
|
||||||
|
|
||||||
@ -121,12 +121,12 @@ test("{ appendTo: 'parent' }, switching after initialization", function() {
|
|||||||
|
|
||||||
// Move and make sure el was appended to fixture
|
// Move and make sure el was appended to fixture
|
||||||
TestHelpers.draggable.move(el, 1, 1);
|
TestHelpers.draggable.move(el, 1, 1);
|
||||||
equal( el.data("last_parent"), $("#qunit-fixture")[0] );
|
equal( el.data("last_dragged_parent"), $("#qunit-fixture")[0] );
|
||||||
|
|
||||||
// Move and make sure el was appended to main
|
// Move and make sure el was appended to main
|
||||||
el.draggable( "option", "appendTo", $("#main") );
|
el.draggable( "option", "appendTo", $("#main") );
|
||||||
TestHelpers.draggable.move(el, 2, 2);
|
TestHelpers.draggable.move(el, 2, 2);
|
||||||
equal( el.data("last_parent"), $("#main")[0] );
|
equal( el.data("last_dragged_parent"), $("#main")[0] );
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -168,7 +168,7 @@ test("{ axis: ? }, unexpected", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test("{ axis: false }, switching after initialization", function() {
|
test("axis, default, switching after initialization", function() {
|
||||||
|
|
||||||
expect(3);
|
expect(3);
|
||||||
|
|
||||||
@ -235,6 +235,24 @@ test( "{ cancel: ? }, unexpected", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("cancel, default, switching after initialization", function() {
|
||||||
|
expect( 3 );
|
||||||
|
|
||||||
|
$("<div id='draggable-option-cancel-default'><input type='text'></div>").appendTo("#main");
|
||||||
|
|
||||||
|
var input = $("#draggable-option-cancel-default input"),
|
||||||
|
el = $("#draggable-option-cancel-default").draggable();
|
||||||
|
|
||||||
|
TestHelpers.draggable.testDrag(el, input, 50, 50, 0, 0);
|
||||||
|
|
||||||
|
el.draggable('option', 'cancel', 'textarea' );
|
||||||
|
TestHelpers.draggable.testDrag(el, input, 50, 50, 50, 50);
|
||||||
|
|
||||||
|
el.draggable('option', 'cancel', 'input' );
|
||||||
|
TestHelpers.draggable.testDrag(el, input, 50, 50, 0, 0);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
test("{ containment: false }, default", function() {
|
test("{ containment: false }, default", function() {
|
||||||
expect( 1 );
|
expect( 1 );
|
||||||
@ -289,6 +307,26 @@ test("{ containment: 'parent' }, absolute", function() {
|
|||||||
deepEqual(offsetAfter, expected, "compare offset to parent");
|
deepEqual(offsetAfter, expected, "compare offset to parent");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("containment, default, switching after initialization", function() {
|
||||||
|
expect( 2 );
|
||||||
|
|
||||||
|
var offsetAfter,
|
||||||
|
el = $("#draggable1").draggable({ containment: false });
|
||||||
|
|
||||||
|
TestHelpers.draggable.testDrag(el, el, -100, -100, -100, -100);
|
||||||
|
|
||||||
|
el.draggable( "option", "containment", "parent" )
|
||||||
|
.css({top:0,left:0})
|
||||||
|
.appendTo( $("#main") );
|
||||||
|
|
||||||
|
TestHelpers.draggable.testDrag(el, el, -100, -100, 0, 0);
|
||||||
|
|
||||||
|
// TODO: Switching back to false does not update to false
|
||||||
|
// el.draggable( "option", "containment", false );
|
||||||
|
// TestHelpers.draggable.testDrag(el, el, -100, -100, -100, -100);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
test("{ containment: 'document' }", function() {
|
test("{ containment: 'document' }", function() {
|
||||||
expect( 1 );
|
expect( 1 );
|
||||||
@ -368,6 +406,27 @@ test("{ cursor: 'move' }", function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("cursor, default, switching after initialization", function() {
|
||||||
|
|
||||||
|
expect(3);
|
||||||
|
|
||||||
|
var el = $("#draggable1").draggable();
|
||||||
|
|
||||||
|
TestHelpers.draggable.trackMouseCss( el );
|
||||||
|
|
||||||
|
TestHelpers.draggable.move( el, 1, 1 );
|
||||||
|
equal( el.data("last_dragged_cursor"), "auto" );
|
||||||
|
|
||||||
|
el.draggable( "option", "cursor", "move" );
|
||||||
|
TestHelpers.draggable.move( el, 1, 1 );
|
||||||
|
equal( el.data("last_dragged_cursor"), "move" );
|
||||||
|
|
||||||
|
el.draggable( "option", "cursor", "ns-resize" );
|
||||||
|
TestHelpers.draggable.move( el, 1, 1 );
|
||||||
|
equal( el.data("last_dragged_cursor"), "ns-resize" );
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
test( "cursorAt", function() {
|
test( "cursorAt", function() {
|
||||||
expect( 24 );
|
expect( 24 );
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ TestHelpers.draggable = {
|
|||||||
});
|
});
|
||||||
offsetAfter = el.offset();
|
offsetAfter = el.offset();
|
||||||
|
|
||||||
actual = { left: offsetAfter.left, top: offsetAfter.top },
|
actual = { left: offsetAfter.left, top: offsetAfter.top };
|
||||||
expected = { left: offsetBefore.left + expectedDX, top: offsetBefore.top + expectedDY };
|
expected = { left: offsetBefore.left + expectedDX, top: offsetBefore.top + expectedDY };
|
||||||
|
|
||||||
msg = msg ? msg + "." : "";
|
msg = msg ? msg + "." : "";
|
||||||
@ -59,6 +59,11 @@ TestHelpers.draggable = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
},
|
},
|
||||||
|
trackMouseCss : function( el ) {
|
||||||
|
el.on( "drag", function(e,ui) {
|
||||||
|
el.data( "last_dragged_cursor", $("body").css("cursor") );
|
||||||
|
});
|
||||||
|
},
|
||||||
trackAppendedParent : function( el ) {
|
trackAppendedParent : function( el ) {
|
||||||
|
|
||||||
// appendTo ignored without being clone
|
// appendTo ignored without being clone
|
||||||
@ -66,7 +71,7 @@ TestHelpers.draggable = {
|
|||||||
|
|
||||||
el.on( "drag", function(e,ui) {
|
el.on( "drag", function(e,ui) {
|
||||||
// Get what parent is at time of drag
|
// Get what parent is at time of drag
|
||||||
el.data( "last_parent", ui.helper.parent()[0] );
|
el.data( "last_dragged_parent", ui.helper.parent()[0] );
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user