// TODO: This doesn't actually test whether append happened, possibly remove
test( "{ appendTo: 'parent' }, default, no clone", function() {
- expect( 2 );
+ expect( 4 );
var element = $( "#draggable2" ).draggable({ appendTo: "parent" });
TestHelpers.draggable.shouldMove( element, "absolute appendTo: parent" );
// TODO: This doesn't actually test whether append happened, possibly remove
test( "{ appendTo: Element }, no clone", function() {
- expect( 2 );
+ expect( 4 );
var element = $( "#draggable2" ).draggable({ appendTo: $( "#draggable2" ).parent()[ 0 ] });
TestHelpers.draggable.shouldMove( element, "absolute appendTo: Element" );
// TODO: This doesn't actually test whether append happened, possibly remove
test( "{ appendTo: Selector }, no clone", function() {
- expect( 2 );
+ expect( 4 );
var element = $( "#draggable2" ).draggable({ appendTo: "#main" });
TestHelpers.draggable.shouldMove( element, "absolute appendTo: Selector" );
});
test( "{ axis: false }, default", function() {
- expect( 1 );
+ expect( 2 );
var element = $( "#draggable2" ).draggable({ axis: false });
TestHelpers.draggable.shouldMove( element, "axis: false" );
});
test( "{ axis: 'x' }", function() {
- expect( 1 );
+ expect( 2 );
var element = $( "#draggable2" ).draggable({ axis: "x" });
TestHelpers.draggable.testDrag( element, element, 50, 50, 50, 0, "axis: x" );
});
test( "{ axis: 'y' }", function() {
- expect( 1 );
+ expect( 2 );
var element = $( "#draggable2" ).draggable({ axis: "y" });
TestHelpers.draggable.testDrag( element, element, 50, 50, 0, 50, "axis: y" );
});
"function() {}": function() {}
};
- expect( 6 );
+ expect( 12 );
$.each(unexpected, function(key, val) {
element = $( "#draggable2" ).draggable({ axis: val });
});
test( "axis, default, switching after initialization", function() {
- expect( 3 );
+ expect( 6 );
var element = $( "#draggable1" ).draggable({ axis : false });
});
test( "{ cancel: 'input,textarea,button,select,option' }, default", function() {
- expect( 2 );
+ expect( 3 );
$( "<div id='draggable-option-cancel-default'><input type='text'></div>" ).appendTo( "#main" );
element.draggable( "destroy" );
element = $( "#draggable-option-cancel-default" ).draggable({ cancel: "input,textarea,button,select,option" });
- TestHelpers.draggable.shouldNotMove( element, "cancel: default, input dragged", "#draggable-option-cancel-default input" );
+ TestHelpers.draggable.shouldNotDrag( element, "cancel: default, input dragged", "#draggable-option-cancel-default input" );
element.draggable( "destroy" );
});
test( "{ cancel: 'span' }", function() {
- expect( 2 );
+ expect( 3 );
var element = $( "#draggable2" ).draggable();
TestHelpers.draggable.shouldMove( element, "cancel: default, span dragged", "#draggable2 span" );
element.draggable( "destroy" );
element = $( "#draggable2" ).draggable({ cancel: "span" });
- TestHelpers.draggable.shouldNotMove( element, "cancel: span, span dragged","#draggable2 span" );
+ TestHelpers.draggable.shouldNotDrag( element, "cancel: span, span dragged","#draggable2 span" );
});
test( "{ cancel: ? }, unexpected", function() {
- expect( 6 );
+ expect( 12 );
var element,
unexpected = {
$( "#wrapping a" ).append( element );
TestHelpers.draggable.shouldMove( element, "drag span child", "#draggable2 span" );
- TestHelpers.draggable.shouldNotMove( $( "#draggable2 span a" ), "drag span a" );
- TestHelpers.draggable.shouldNotMove( $( "#wrapping a" ), "drag wrapping a" );
+ TestHelpers.draggable.shouldNotDrag( $( "#draggable2 span a" ), "drag span a" );
+ TestHelpers.draggable.shouldNotDrag( $( "#wrapping a" ), "drag wrapping a" );
$( "#draggable2" ).draggable( "option", "cancel", "span > a" );
$( "#draggable2" ).find( "a" ).append( "<a>" );
TestHelpers.draggable.shouldMove( element, "drag span child", $( "#draggable2 span a" ).last() );
- TestHelpers.draggable.shouldNotMove( $( "#draggable2 span a" ).first(), "drag span a first child" );
+ TestHelpers.draggable.shouldNotDrag( $( "#draggable2 span a" ).first(), "drag span a first child" );
});
*/
test( "cancelement, default, switching after initialization", function() {
- expect( 3 );
+ expect( 4 );
$( "<div id='draggable-option-cancel-default'><input type='text'></div>" ).appendTo( "#main" );
var input = $( "#draggable-option-cancel-default input" ),
element = $( "#draggable-option-cancel-default" ).draggable();
- TestHelpers.draggable.shouldNotMove( element, "cancel: default, input dragged", input );
+ TestHelpers.draggable.shouldNotDrag( element, "cancel: default, input dragged", input );
element.draggable( "option", "cancel", "textarea" );
TestHelpers.draggable.shouldMove( element, "cancel: textarea, input dragged", input );
element.draggable( "option", "cancel", "input" );
- TestHelpers.draggable.shouldNotMove( element, "cancel: input, input dragged", input );
+ TestHelpers.draggable.shouldNotDrag( element, "cancel: input, input dragged", input );
});
/*
});
test( "{ containment: [x1, y1, x2, y2] }", function() {
- expect( 1 );
+ expect( 2 );
var element = $( "#draggable1" ).draggable(),
eo = element.offset();
});
test( "containment, default, switching after initialization", function() {
- expect( 3 );
+ expect( 6 );
var element = $( "#draggable1" ).draggable({ containment: false });
});
test( "disabled", function() {
- expect( 3 );
+ expect( 5 );
var element = $( "#draggable1" ).draggable();
TestHelpers.draggable.shouldMove( element, "disabled: default" );
element.draggable( "option", "disabled", true );
- TestHelpers.draggable.shouldNotMove( element, "option: disabled true" );
+ TestHelpers.draggable.shouldNotDrag( element, "option: disabled true" );
element.draggable( "option", "disabled", false );
TestHelpers.draggable.shouldMove( element, "option: disabled false" );
});
test( "{ grid: [50, 50] }, relative", function() {
- expect( 2 );
+ expect( 4 );
var element = $( "#draggable1" ).draggable({ grid: [ 50, 50 ] });
TestHelpers.draggable.testDrag( element, element, 24, 24, 0, 0, "grid: [50, 50] relative" );
});
test( "{ grid: [50, 50] }, absolute", function() {
- expect( 2 );
+ expect( 4 );
var element = $( "#draggable2" ).draggable({ grid: [ 50, 50 ] });
TestHelpers.draggable.testDrag( element, element, 24, 24, 0, 0, "grid: [50, 50] absolute" );
});
test( "grid, switching after initialization", function() {
- expect( 4 );
+ expect( 8 );
var element = $( "#draggable1" ).draggable();
});
test( "{ handle: 'span' }", function() {
- expect( 3 );
+ expect( 5 );
var element = $( "#draggable2" ).draggable({ handle: "span" });
TestHelpers.draggable.shouldMove( element, "handle: span", "#draggable2 span");
TestHelpers.draggable.shouldMove( element, "handle: span child", "#draggable2 span em" );
- TestHelpers.draggable.shouldNotMove( element, "handle: span element" );
+ TestHelpers.draggable.shouldNotDrag( element, "handle: span element" );
});
test( "handle, default, switching after initialization", function() {
- expect( 6 );
+ expect( 11 );
var element = $( "#draggable2" ).draggable();
// Switch
element.draggable( "option", "handle", "span" );
- TestHelpers.draggable.shouldNotMove( element, "handle: span as option, element dragged" );
+ TestHelpers.draggable.shouldNotDrag( element, "handle: span as option, element dragged" );
TestHelpers.draggable.shouldMove( element, "handle: span as option, span dragged", "#draggable2 span" );
// And back
});
test( "helper, default, switching after initialization", function() {
- expect( 3 );
+ expect( 6 );
var element = $( "#draggable1" ).draggable();
TestHelpers.draggable.shouldMove( element, "helper: default" );
});
test( "{ helper: 'clone' }, relative", function() {
- expect( 1 );
+ expect( 2 );
var element = $( "#draggable1" ).draggable({ helper: "clone" });
TestHelpers.draggable.shouldNotMove( element, "helper: clone relative" );
});
test( "{ helper: 'clone' }, absolute", function() {
- expect( 1 );
+ expect( 2 );
var element = $( "#draggable2" ).draggable({ helper: "clone" });
TestHelpers.draggable.shouldNotMove( element, "helper: clone absolute" );
});
test( "{ helper: 'original' }, relative, with scroll offset on parent", function() {
- expect( 3 );
+ expect( 6 );
var element = $( "#draggable1" ).draggable({ helper: "original" });
});
test( "{ helper: 'original' }, relative, with scroll offset on root", function() {
- expect( 3 );
+ expect( 6 );
var element = $( "#draggable1" ).draggable({ helper: "original" });
});
test( "{ helper: 'original' }, relative, with scroll offset on root and parent", function() {
- expect( 3 );
+ expect( 6 );
var element = $( "#draggable1" ).draggable({ helper: "original" });
});
test( "{ helper: 'original' }, absolute, with scroll offset on parent", function() {
- expect( 3 );
+ expect( 6 );
var element = $( "#draggable1" ).css({ position: "absolute", top: 0, left: 0 }).draggable({ helper: "original" });
});
test( "{ helper: 'original' }, absolute, with scroll offset on root", function() {
- expect( 3 );
+ expect( 6 );
var element = $( "#draggable1" ).css({ position: "absolute", top: 0, left: 0 }).draggable({ helper: "original" });
});
test( "{ helper: 'original' }, absolute, with scroll offset on root and parent", function() {
- expect( 3 );
+ expect( 6 );
var element = $( "#draggable1" ).css({ position: "absolute", top: 0, left: 0 }).draggable({ helper: "original" });
});
test( "{ helper: 'original' }, fixed, with scroll offset on parent", function() {
- expect( 3 );
+ expect( 6 );
var element = $( "#draggable1" ).css({ position: "fixed", top: 0, left: 0 }).draggable({ helper: "original" });
});
test( "{ helper: 'original' }, fixed, with scroll offset on root", function() {
- expect( 3 );
+ expect( 6 );
var element = $( "#draggable1" ).css({ position: "fixed", top: 0, left: 0 }).draggable({ helper: "original" });
});
test( "{ helper: 'original' }, fixed, with scroll offset on root and parent", function() {
- expect( 3 );
+ expect( 6 );
var element = $( "#draggable1" ).css({ position: "fixed", top: 0, left: 0 }).draggable({ helper: "original" });
});
asyncTest( "revert and revertDuration", function() {
- expect( 4 );
+ expect( 7 );
var element = $( "#draggable2" ).draggable({
revert: true,
});
test( "revert: valid", function() {
- expect( 1 );
+ expect( 2 );
var element = $( "#draggable2" ).draggable({
revert: "valid",
});
test( "scope", function() {
- expect( 2 );
+ expect( 4 );
var element = $( "#draggable2" ).draggable({
scope: "tasks",
return $.contains( element[ 0 ].ownerDocument, element[ 0 ] );
})(),
testDrag: function( el, handle, dx, dy, expectedDX, expectedDY, msg ) {
- var offsetAfter, actual, expected,
- offsetBefore = el.offset();
+ msg = msg ? msg + "." : "";
+
+ var offsetActual,
+ offsetBefore = el.offset(),
+ offsetExpected = { left: offsetBefore.left + expectedDX, top: offsetBefore.top + expectedDY };
+
+ $( el ).one( "dragstop", function( event, ui ) {
+ var expectedPosition = { left: ui.originalPosition.left + expectedDX, top: ui.originalPosition.top + expectedDY };
+ // TODO: fix test bugs and actual bugs that cause this not to be true
+ // deepEqual( ui.position, expectedPosition, "position dragged[" + dx + ", " + dy + "] " + msg );
+ ok( true, "TODO: deepEqual( ui.position, expectedPosition, 'position dragged[" + dx + ", " + dy + "] " + msg + "');");
+ } );
$( handle ).simulate( "drag", {
dx: dx,
// so we can't faithfully test things that rely on a scroll event (which is async)
moves: 1
});
- offsetAfter = el.offset();
- actual = { left: offsetAfter.left, top: offsetAfter.top };
- expected = { left: offsetBefore.left + expectedDX, top: offsetBefore.top + expectedDY };
+ offsetActual = el.offset();
- msg = msg ? msg + "." : "";
- deepEqual( actual, expected, "dragged[" + dx + ", " + dy + "] " + msg );
+ deepEqual( offsetActual, offsetExpected, "offset dragged[" + dx + ", " + dy + "] " + msg );
},
shouldMove: function( el, why, handle ) {
handle = handle || el;
handle = handle || el;
TestHelpers.draggable.testDrag( el, handle, 50, 50, 0, 0, why );
},
+ shouldNotDrag: function( el, why, handle ) {
+ $( el ).bind( "dragstop", function() {
+ ok( false, "should not drag " + why );
+ } );
+ TestHelpers.draggable.shouldNotMove( el, why, handle );
+ $( el ).unbind( "dragstop" );
+ },
testScroll: function( el, position ) {
var oldPosition = $( "#main" ).css( "position" );
$( "#main" ).css( "position", position);