diff options
Diffstat (limited to 'tests/unit/draggable')
-rw-r--r-- | tests/unit/draggable/draggable_options.js | 40 | ||||
-rw-r--r-- | tests/unit/draggable/draggable_test_helpers.js | 26 |
2 files changed, 38 insertions, 28 deletions
diff --git a/tests/unit/draggable/draggable_options.js b/tests/unit/draggable/draggable_options.js index 0e728f8dc..eba6c4731 100644 --- a/tests/unit/draggable/draggable_options.js +++ b/tests/unit/draggable/draggable_options.js @@ -85,7 +85,7 @@ test( "{ appendTo: Selector }", function() { test( "appendTo, default, switching after initialization", function() { expect( 2 ); - var element = $( "#draggable1" ).draggable({ helper : "clone" }); + var element = $( "#draggable1" ).draggable({ helper: "clone" }); TestHelpers.draggable.trackAppendedParent( element ); @@ -140,7 +140,7 @@ test( "{ axis: ? }, unexpected", function() { test( "axis, default, switching after initialization", function() { expect( 6 ); - var element = $( "#draggable1" ).draggable({ axis : false }); + var element = $( "#draggable1" ).draggable({ axis: false }); // Any Direction TestHelpers.draggable.shouldMove( element, "axis: default" ); @@ -504,12 +504,12 @@ test( "cursorAt", function() { var deltaX = -3, deltaY = -3, tests = { - "false": { cursorAt : false }, - "{ left: -5, top: -5 }": { x: -5, y: -5, cursorAt : { left: -5, top: -5 } }, - "[ 10, 20 ]": { x: 10, y: 20, cursorAt : [ 10, 20 ] }, - "'10 20'": { x: 10, y: 20, cursorAt : "10 20" }, - "{ left: 20, top: 40 }": { x: 20, y: 40, cursorAt : { left: 20, top: 40 } }, - "{ right: 10, bottom: 20 }": { x: 10, y: 20, cursorAt : { right: 10, bottom: 20 } } + "false": { cursorAt: false }, + "{ left: -5, top: -5 }": { x: -5, y: -5, cursorAt: { left: -5, top: -5 } }, + "[ 10, 20 ]": { x: 10, y: 20, cursorAt: [ 10, 20 ] }, + "'10 20'": { x: 10, y: 20, cursorAt: "10 20" }, + "{ left: 20, top: 40 }": { x: 20, y: 40, cursorAt: { left: 20, top: 40 } }, + "{ right: 10, bottom: 20 }": { x: 10, y: 20, cursorAt: { right: 10, bottom: 20 } } }; $.each( tests, function( testName, testData ) { @@ -517,10 +517,10 @@ test( "cursorAt", function() { var element = $( "#draggable" + ( i + 1 ) ).draggable({ cursorAt: testData.cursorAt, drag: function( event, ui ) { - if( !testData.cursorAt ) { + if ( !testData.cursorAt ) { equal( ui.position.left - ui.originalPosition.left, deltaX, testName + " " + position + " left" ); equal( ui.position.top - ui.originalPosition.top, deltaY, testName + " " + position + " top" ); - } else if( testData.cursorAt.right ) { + } else if ( testData.cursorAt.right ) { equal( ui.helper.width() - ( event.clientX - ui.offset.left ), testData.x - TestHelpers.draggable.unreliableOffset, testName + " " + position + " left" ); equal( ui.helper.height() - ( event.clientY - ui.offset.top ), testData.y - TestHelpers.draggable.unreliableOffset, testName + " " +position + " top" ); } else { @@ -545,12 +545,12 @@ test( "cursorAt, switching after initialization", function() { var deltaX = -3, deltaY = -3, tests = { - "false": { cursorAt : false }, - "{ left: -5, top: -5 }": { x: -5, y: -5, cursorAt : { left: -5, top: -5 } }, - "[ 10, 20 ]": { x: 10, y: 20, cursorAt : [ 10, 20 ] }, - "'10 20'": { x: 10, y: 20, cursorAt : "10 20" }, - "{ left: 20, top: 40 }": { x: 20, y: 40, cursorAt : { left: 20, top: 40 } }, - "{ right: 10, bottom: 20 }": { x: 10, y: 20, cursorAt : { right: 10, bottom: 20 } } + "false": { cursorAt: false }, + "{ left: -5, top: -5 }": { x: -5, y: -5, cursorAt: { left: -5, top: -5 } }, + "[ 10, 20 ]": { x: 10, y: 20, cursorAt: [ 10, 20 ] }, + "'10 20'": { x: 10, y: 20, cursorAt: "10 20" }, + "{ left: 20, top: 40 }": { x: 20, y: 40, cursorAt: { left: 20, top: 40 } }, + "{ right: 10, bottom: 20 }": { x: 10, y: 20, cursorAt: { right: 10, bottom: 20 } } }; $.each( tests, function( testName, testData ) { @@ -559,10 +559,10 @@ test( "cursorAt, switching after initialization", function() { element.draggable({ drag: function( event, ui ) { - if( !testData.cursorAt ) { + if ( !testData.cursorAt ) { equal( ui.position.left - ui.originalPosition.left, deltaX, testName + " " + position + " left" ); equal( ui.position.top - ui.originalPosition.top, deltaY, testName + " " + position + " top" ); - } else if( testData.cursorAt.right ) { + } else if ( testData.cursorAt.right ) { equal( ui.helper.width() - ( event.clientX - ui.offset.left ), testData.x - TestHelpers.draggable.unreliableOffset, testName + " " + position + " left" ); equal( ui.helper.height() - ( event.clientY - ui.offset.top ), testData.y - TestHelpers.draggable.unreliableOffset, testName + " " +position + " top" ); } else { @@ -672,7 +672,7 @@ test( "helper, default, switching after initialization", function() { }); /* jshint loopfunc: true */ -(function(){ +(function() { var k, l, m, scrollElements = { "no elements": [], @@ -689,7 +689,7 @@ test( "helper, default, switching after initialization", function() { for ( m = 0 ; m < helpers.length; m++ ) { for ( l = 0; l < positions.length; l++ ) { for ( k in scrollElements ) { - (function( position, helper, scrollElements, scrollElementsTitle ){ + (function( position, helper, scrollElements, scrollElementsTitle ) { test( "{ helper: '" + helper + "' }, " + position + ", with scroll offset on " + scrollElementsTitle, function() { expect( scrollPositions.length * 2 ); diff --git a/tests/unit/draggable/draggable_test_helpers.js b/tests/unit/draggable/draggable_test_helpers.js index 0b533a4e1..38da30806 100644 --- a/tests/unit/draggable/draggable_test_helpers.js +++ b/tests/unit/draggable/draggable_test_helpers.js @@ -2,7 +2,7 @@ TestHelpers.draggable = { // TODO: remove the unreliable offset hacks unreliableOffset: $.ui.ie && ( !document.documentMode || document.documentMode < 8 ) ? 2 : 0, // Support: Opera 12.10, Safari 5.1, jQuery <1.8 - unreliableContains: (function(){ + unreliableContains: (function() { var element = $( "<div>" ); return $.contains( element[ 0 ].ownerDocument, element[ 0 ] ); })(), @@ -12,7 +12,7 @@ TestHelpers.draggable = { $( el ).one( "dragstop", function( event, ui ) { var positionExpected = { left: ui.originalPosition.left + expectedDX, top: ui.originalPosition.top + expectedDY }; deepEqual( ui.position, positionExpected, "position dragged[" + dx + ", " + dy + "] " + msg ); - } ); + }); }, testDragOffset: function( el, dx, dy, expectedDX, expectedDY, msg ) { msg = msg ? msg + "." : ""; @@ -21,8 +21,18 @@ TestHelpers.draggable = { offsetExpected = { left: offsetBefore.left + expectedDX, top: offsetBefore.top + expectedDY }; $( el ).one( "dragstop", function( event, ui ) { + deepEqual( ui.offset, offsetExpected, "offset dragged[" + dx + ", " + dy + "] " + msg ); + }); + }, + testDragHelperOffset: function( el, dx, dy, expectedDX, expectedDY, msg ) { + msg = msg ? msg + "." : ""; + + var offsetBefore = el.offset(), + offsetExpected = { left: offsetBefore.left + expectedDX, top: offsetBefore.top + expectedDY }; + + $( el ).one( "dragstop", function( event, ui ) { deepEqual( ui.helper.offset(), offsetExpected, "offset dragged[" + dx + ", " + dy + "] " + msg ); - } ); + }); }, testDrag: function( el, handle, dx, dy, expectedDX, expectedDY, msg ) { TestHelpers.draggable.testDragPosition( el, dx, dy, expectedDX, expectedDY, msg ); @@ -55,14 +65,14 @@ TestHelpers.draggable = { handle = handle || el; $( el ).bind( "dragstop", function() { ok( false, "should not drag " + msg ); - } ); + }); $( handle ).simulate( "drag", { dx: 100, dy: 100 }); $( el ).unbind( "dragstop" ); }, - setScrollable: function ( what, isScrollable ) { + setScrollable: function( what, isScrollable ) { var overflow = isScrollable ? "scroll" : "hidden"; $( what ).css({ overflow: overflow, overflowX: overflow, overflowY: overflow }); }, @@ -90,12 +100,12 @@ TestHelpers.draggable = { dy: y }); }, - trackMouseCss : function( el ) { + trackMouseCss: function( el ) { el.bind( "drag", function() { el.data( "last_dragged_cursor", $( "body" ).css( "cursor" ) ); }); }, - trackAppendedParent : function( el ) { + trackAppendedParent: function( el ) { // TODO: appendTo is currently ignored if helper is original (see #7044) el.draggable( "option", "helper", "clone" ); @@ -104,4 +114,4 @@ TestHelpers.draggable = { el.data( "last_dragged_parent", ui.helper.parent()[ 0 ] ); }); } -};
\ No newline at end of file +}; |