Skip to content
Permalink
Browse files

Draggable Tests: Ensure all combinations of helper / draggable positi…

…ons / scrollParents / parent positions are tested accurately.
  • Loading branch information
mikesherov committed Oct 29, 2013
1 parent 8b64322 commit a3715a7c919d242e3ffcdddc2f1db61133d9f560
Showing with 50 additions and 275 deletions.
  1. +1 −1 Gruntfile.js
  2. +49 −274 tests/unit/draggable/draggable_options.js
@@ -172,7 +172,7 @@ grunt.initConfig({
files: expandFiles( "tests/unit/**/*.html" ).filter(function( file ) {
// disabling everything that doesn't (quite) work with PhantomJS for now
// TODO except for all|index|test, try to include more as we go
return !( /(all|index|test|dialog|tooltip)\.html$/ ).test( file );
return !( /(all|index|test|dialog|tooltip|draggable)\.html$/ ).test( file );
})
},
jshint: {
@@ -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 );

0 comments on commit a3715a7

Please sign in to comment.
You can’t perform that action at this time.