aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/draggable
diff options
context:
space:
mode:
authorMike Sherov <mike.sherov@gmail.com>2013-10-29 09:52:57 -0400
committerMike Sherov <mike.sherov@gmail.com>2013-10-29 13:25:57 -0400
commita3715a7c919d242e3ffcdddc2f1db61133d9f560 (patch)
tree60a4d7bed11e6ba3dc40079fb78d020f36c9dba9 /tests/unit/draggable
parent8b64322e982e97cdfd5cdd184c8993f7123d469e (diff)
downloadjquery-ui-a3715a7c919d242e3ffcdddc2f1db61133d9f560.tar.gz
jquery-ui-a3715a7c919d242e3ffcdddc2f1db61133d9f560.zip
Draggable Tests: Ensure all combinations of helper / draggable positions / scrollParents / parent positions are tested accurately.
Diffstat (limited to 'tests/unit/draggable')
-rw-r--r--tests/unit/draggable/draggable_options.js323
1 files changed, 49 insertions, 274 deletions
diff --git a/tests/unit/draggable/draggable_options.js b/tests/unit/draggable/draggable_options.js
index 4ac5ae2da..8c4685fa8 100644
--- a/tests/unit/draggable/draggable_options.js
+++ b/tests/unit/draggable/draggable_options.js
@@ -666,284 +666,59 @@ test( "helper, default, switching after initialization", function() {
TestHelpers.draggable.shouldMove( element, "helper: original" );
});
-test( "{ helper: 'clone' }, relative", function() {
- expect( 2 );
-
- var element = $( "#draggable1" ).draggable({ helper: "clone" });
- TestHelpers.draggable.shouldMove( element, "helper: clone relative" );
-});
-
-test( "{ helper: 'clone' }, absolute", function() {
- expect( 2 );
-
- var element = $( "#draggable2" ).draggable({ helper: "clone" });
- TestHelpers.draggable.shouldMove( element, "helper: clone absolute" );
-});
-
-test( "{ helper: 'original' }, relative, with scroll offset on parent", function() {
- expect( 6 );
-
- var element = $( "#draggable1" ).draggable({ helper: "original" });
-
- TestHelpers.draggable.setScroll( "#main" );
- TestHelpers.draggable.testScroll( element, "relative" );
-
- TestHelpers.draggable.setScroll( "#main" );
- TestHelpers.draggable.testScroll( element, "static" );
-
- TestHelpers.draggable.setScroll( "#main" );
- TestHelpers.draggable.testScroll( element, "absolute" );
-
- TestHelpers.draggable.restoreScroll( "#main" );
-});
-
-test( "{ helper: 'original' }, relative, with scroll offset on root", function() {
- expect( 6 );
-
- var element = $( "#draggable1" ).draggable({ helper: "original" });
-
- TestHelpers.draggable.setScroll( document );
- TestHelpers.draggable.testScroll( element, "relative" );
-
- TestHelpers.draggable.setScroll( document );
- TestHelpers.draggable.testScroll( element, "static" );
-
- TestHelpers.draggable.setScroll( document );
- TestHelpers.draggable.testScroll( element, "absolute" );
-
- TestHelpers.draggable.restoreScroll( document );
-});
-
-test( "{ helper: 'original' }, relative, with scroll offset on root and parent", function() {
- expect( 6 );
-
- var element = $( "#draggable1" ).draggable({ helper: "original" });
-
- TestHelpers.draggable.setScroll( "#main" );
- TestHelpers.draggable.setScroll( document );
- TestHelpers.draggable.testScroll( element, "relative" );
-
- TestHelpers.draggable.setScroll( "#main" );
- TestHelpers.draggable.setScroll( document );
- TestHelpers.draggable.testScroll( element, "static" );
-
- TestHelpers.draggable.setScroll( "#main" );
- TestHelpers.draggable.setScroll( document );
- TestHelpers.draggable.testScroll( element, "absolute" );
-
- TestHelpers.draggable.restoreScroll( "#main" );
- TestHelpers.draggable.restoreScroll( document );
-});
-
-test( "{ helper: 'original' }, absolute, with scroll offset on parent", function() {
- expect( 6 );
-
- var element = $( "#draggable1" ).css({ position: "absolute", top: 0, left: 0 }).draggable({ helper: "original" });
-
- TestHelpers.draggable.setScroll( "#main" );
- TestHelpers.draggable.testScroll( element, "relative" );
-
- TestHelpers.draggable.setScroll( "#main" );
- TestHelpers.draggable.testScroll( element, "static" );
-
- TestHelpers.draggable.setScroll( "#main" );
- TestHelpers.draggable.testScroll( element, "absolute" );
-
- TestHelpers.draggable.restoreScroll( "#main" );
-});
-
-test( "{ helper: 'original' }, absolute, with scroll offset on grandparent", function() {
- expect( 6 );
-
- var element = $( "#draggable1" ).css({ position: "absolute", top: 0, left: 0 }).draggable({ helper: "original" });
-
- TestHelpers.draggable.setScrollable( "#main", false );
- TestHelpers.draggable.setScrollable( "#scrollParent", true );
-
- TestHelpers.draggable.setScroll( "#scrollParent" );
- TestHelpers.draggable.testScroll( element, "relative" );
-
- TestHelpers.draggable.setScroll( "#scrollParent" );
- TestHelpers.draggable.testScroll( element, "static" );
-
- TestHelpers.draggable.setScroll( "#scrollParent" );
- TestHelpers.draggable.testScroll( element, "absolute" );
-
- TestHelpers.draggable.restoreScroll( "#scrollParent" );
-});
-
-test( "{ helper: 'original' }, absolute, with scroll offset on root", function() {
- expect( 6 );
-
- var element = $( "#draggable1" ).css({ position: "absolute", top: 0, left: 0 }).draggable({ helper: "original" });
-
- TestHelpers.draggable.setScroll( document );
- TestHelpers.draggable.testScroll( element, "relative" );
-
- TestHelpers.draggable.setScroll( document );
- TestHelpers.draggable.testScroll( element, "static" );
-
- TestHelpers.draggable.setScroll( document );
- TestHelpers.draggable.testScroll( element, "absolute" );
-
- TestHelpers.draggable.restoreScroll( document );
-});
-
-test( "{ helper: 'original' }, absolute, with scroll offset on root and parent", function() {
- expect( 6 );
-
- var element = $( "#draggable1" ).css({ position: "absolute", top: 0, left: 0 }).draggable({ helper: "original" });
-
- TestHelpers.draggable.setScroll( "#main" );
- TestHelpers.draggable.setScroll( document );
- TestHelpers.draggable.testScroll( element, "relative" );
-
- TestHelpers.draggable.setScroll( "#main" );
- TestHelpers.draggable.setScroll( document );
- TestHelpers.draggable.testScroll( element, "static" );
-
- TestHelpers.draggable.setScroll( "#main" );
- TestHelpers.draggable.setScroll( document );
- TestHelpers.draggable.testScroll( element, "absolute" );
-
- TestHelpers.draggable.restoreScroll( "#main" );
- TestHelpers.draggable.restoreScroll( document );
-});
-
-test( "{ helper: 'original' }, fixed, with scroll offset on parent", function() {
- expect( 4 );
-
- var element = $( "#draggable1" ).css({ position: "fixed", top: 0, left: 0 }).draggable({ helper: "original" });
-
- TestHelpers.draggable.setScroll( "#main" );
- TestHelpers.draggable.testScroll( element, "relative" );
-
- TestHelpers.draggable.setScroll( "#main" );
- TestHelpers.draggable.testScroll( element, "static" );
-
- TestHelpers.draggable.setScroll( "#main" );
- // TODO: investigate these failure in PhantomJS
- //TestHelpers.draggable.testScroll( element, "absolute" );
-
- TestHelpers.draggable.restoreScroll( "#main" );
-});
-
-test( "{ helper: 'original' }, fixed, with scroll offset on root", function() {
- expect( 4 );
-
- var element = $( "#draggable1" ).css({ position: "fixed", top: 0, left: 0 }).draggable({ helper: "original" });
-
- TestHelpers.draggable.setScroll( document );
- TestHelpers.draggable.testScroll( element, "relative" );
-
- TestHelpers.draggable.setScroll( document );
- TestHelpers.draggable.testScroll( element, "static" );
-
- TestHelpers.draggable.setScroll( document );
- // TODO: investigate these failure in PhantomJS
- //TestHelpers.draggable.testScroll( element, "absolute" );
-
- TestHelpers.draggable.restoreScroll( document );
-});
-
-test( "{ helper: 'original' }, fixed, with scroll offset on root and parent", function() {
- expect( 4 );
-
- var element = $( "#draggable1" ).css({ position: "fixed", top: 0, left: 0 }).draggable({ helper: "original" });
-
- TestHelpers.draggable.setScroll( "#main" );
- TestHelpers.draggable.setScroll( document );
- TestHelpers.draggable.testScroll( element, "relative" );
-
- TestHelpers.draggable.setScroll( "#main" );
- TestHelpers.draggable.setScroll( document );
- TestHelpers.draggable.testScroll( element, "static" );
-
- TestHelpers.draggable.setScroll( "#main" );
- TestHelpers.draggable.setScroll( document );
- // TODO: investigate these failure in PhantomJS
- //TestHelpers.draggable.testScroll( element, "absolute" );
-
- TestHelpers.draggable.restoreScroll( "#main" );
- TestHelpers.draggable.restoreScroll( document );
-});
-
-test( "{ helper: 'clone' }, absolute", function() {
- expect( 1 );
-
- var helperOffset = null,
- origOffset = $( "#draggable1" ).offset(),
- element = $( "#draggable1" ).draggable({ helper: "clone", drag: function( event, ui) {
- helperOffset = ui.helper.offset();
- } });
-
- element.simulate( "drag", {
- dx: 1,
- dy: 1
- });
- deepEqual({ top: helperOffset.top - 1, left: helperOffset.left - 1 }, origOffset, "dragged[1, 1]" );
-});
-
-test( "{ helper: 'clone' }, absolute with scroll offset on parent", function() {
- expect( 6 );
-
- var element = $( "#draggable1" ).draggable({
- helper: "clone"
- });
-
- TestHelpers.draggable.setScroll( "#main" );
- TestHelpers.draggable.testScroll( element, "relative" );
-
- TestHelpers.draggable.setScroll( "#main" );
- TestHelpers.draggable.testScroll( element, "static" );
-
- TestHelpers.draggable.setScroll( "#main" );
- TestHelpers.draggable.testScroll( element, "absolute" );
-
- TestHelpers.draggable.restoreScroll( "#main" );
-});
-
-test( "{ helper: 'clone' }, absolute with scroll offset on root", function() {
- expect( 6 );
-
- var element = $( "#draggable1" ).draggable({
- helper: "clone"
- });
-
- TestHelpers.draggable.setScroll( document );
- TestHelpers.draggable.testScroll( element, "relative" );
-
- TestHelpers.draggable.setScroll( document );
- TestHelpers.draggable.testScroll( element, "static" );
-
- TestHelpers.draggable.setScroll( document );
- TestHelpers.draggable.testScroll( element, "absolute" );
-
- TestHelpers.draggable.restoreScroll( document );
-});
-
-test( "{ helper: 'clone' }, absolute with scroll offset on root and parent", function() {
- expect( 6 );
-
- var element = $( "#draggable1" ).draggable({
- helper: "clone"
- });
+/* jshint loopfunc: true */
+(function(){
+ var k, l, m,
+ scrollElements = {
+ "no elements": [],
+ "parent": [ "#main" ],
+ "root": [ document ],
+ "parent and root": [ "#main", document ],
+ "grandparent": [ "#scrollParent" ]
+ },
+ positions = [ "absolute", "fixed", "relative" ],
+ helpers = [ "original", "clone" ],
+ scrollPositions = [ "relative", "static", "absolute" ];
+
+ for ( m = 0 ; m < helpers.length; m++ ) {
+ for ( l = 0; l < positions.length; l++ ) {
+ for ( k in scrollElements ) {
+ (function( position, helper, scrollElements, scrollElementsTitle ){
+ test( "{ helper: '" + helper + "' }, " + position + ", with scroll offset on " + scrollElementsTitle, function() {
+ expect( 6 );
+ var i, j,
+ element = $( "#draggable1" ).css({ position: position, top: 0, left: 0 }).draggable({
+ helper: helper
+ });
+
+ if ( scrollElements.length === 1 && scrollElements[ 1 ] === "#scrollParent" ) {
+ TestHelpers.draggable.setScrollable( "#main", false );
+ TestHelpers.draggable.setScrollable( "#scrollParent", true );
+ }
- TestHelpers.draggable.setScroll( document );
- TestHelpers.draggable.setScroll( "#main" );
- TestHelpers.draggable.testScroll( element, "relative" );
+ for ( j = 0; j < scrollPositions.length; j++ ) {
+ for ( i = 0; i < scrollElements.length; i++ ) {
+ TestHelpers.draggable.setScroll( scrollElements[ i ] );
+ }
- TestHelpers.draggable.setScroll( document );
- TestHelpers.draggable.setScroll( "#main" );
- TestHelpers.draggable.testScroll( element, "static" );
+ TestHelpers.draggable.testScroll( element, scrollPositions[ j ] );
- TestHelpers.draggable.setScroll( document );
- TestHelpers.draggable.setScroll( "#main" );
- TestHelpers.draggable.testScroll( element, "absolute" );
+ for ( i = 0; i < scrollElements.length; i++ ) {
+ TestHelpers.draggable.restoreScroll( scrollElements[ i ] );
+ }
+ }
- TestHelpers.draggable.restoreScroll( document );
- TestHelpers.draggable.restoreScroll( "#main" );
-});
+ if ( scrollElements.length === 1 && scrollElements[ 1 ] === "#scrollParent" ) {
+ TestHelpers.draggable.setScrollable( "#main", true );
+ TestHelpers.draggable.setScrollable( "#scrollParent", false );
+ }
+ });
+ })( positions[ l ], helpers[ m ], scrollElements[ k ], k );
+ }
+ }
+ }
+})();
+/* jshint loopfunc: false */
test( "{ opacity: 0.5 }", function() {
expect( 1 );