Skip to content

Commit 01e26b0

Browse files
committed
Draggable Tests: Clarify position helper test generation
1 parent 2d03839 commit 01e26b0

File tree

1 file changed

+44
-43
lines changed

1 file changed

+44
-43
lines changed

tests/unit/draggable/draggable_options.js

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -671,10 +671,42 @@ test( "helper, default, switching after initialization", function() {
671671
TestHelpers.draggable.shouldMove( element, "helper: original" );
672672
});
673673

674-
/* jshint loopfunc: true */
674+
function testHelperPosition( scrollPositions, position, helper, scrollElements, scrollElementsTitle ) {
675+
test( "{ helper: '" + helper + "' }, " + position + ", with scroll offset on " + scrollElementsTitle, function() {
676+
expect( scrollPositions.length * 2 );
677+
678+
var i, j,
679+
element = $( "#draggable1" ).css({ position: position, top: 0, left: 0 }).draggable({
680+
helper: helper,
681+
scroll: false
682+
});
683+
684+
if ( scrollElements.length === 1 && scrollElements[ 0 ] === "#scrollParent" ) {
685+
TestHelpers.draggable.setScrollable( "#main", false );
686+
TestHelpers.draggable.setScrollable( "#scrollParent", true );
687+
}
688+
689+
for ( j = 0; j < scrollPositions.length; j++ ) {
690+
for ( i = 0; i < scrollElements.length; i++ ) {
691+
TestHelpers.draggable.setScroll( scrollElements[ i ] );
692+
}
693+
694+
TestHelpers.draggable.testScroll( element, scrollPositions[ j ] );
695+
696+
for ( i = 0; i < scrollElements.length; i++ ) {
697+
TestHelpers.draggable.restoreScroll( scrollElements[ i ] );
698+
}
699+
}
700+
701+
if ( scrollElements.length === 1 && scrollElements[ 1 ] === "#scrollParent" ) {
702+
TestHelpers.draggable.setScrollable( "#main", true );
703+
TestHelpers.draggable.setScrollable( "#scrollParent", false );
704+
}
705+
});
706+
}
707+
675708
(function() {
676-
var k, l, m,
677-
scrollElements = {
709+
var scrollElementsMap = {
678710
"no elements": [],
679711
"parent": [ "#main" ],
680712
"root": [ document ],
@@ -686,47 +718,16 @@ test( "helper, default, switching after initialization", function() {
686718
// static is not an option here since the fixture is in an absolute container
687719
scrollPositions = [ "relative", "absolute", "fixed" ];
688720

689-
for ( m = 0 ; m < helpers.length; m++ ) {
690-
for ( l = 0; l < positions.length; l++ ) {
691-
for ( k in scrollElements ) {
692-
(function( position, helper, scrollElements, scrollElementsTitle ) {
693-
test( "{ helper: '" + helper + "' }, " + position + ", with scroll offset on " + scrollElementsTitle, function() {
694-
expect( scrollPositions.length * 2 );
695-
696-
var i, j,
697-
element = $( "#draggable1" ).css({ position: position, top: 0, left: 0 }).draggable({
698-
helper: helper,
699-
scroll: false
700-
});
701-
702-
if ( scrollElements.length === 1 && scrollElements[ 0 ] === "#scrollParent" ) {
703-
TestHelpers.draggable.setScrollable( "#main", false );
704-
TestHelpers.draggable.setScrollable( "#scrollParent", true );
705-
}
706-
707-
for ( j = 0; j < scrollPositions.length; j++ ) {
708-
for ( i = 0; i < scrollElements.length; i++ ) {
709-
TestHelpers.draggable.setScroll( scrollElements[ i ] );
710-
}
711-
712-
TestHelpers.draggable.testScroll( element, scrollPositions[ j ] );
713-
714-
for ( i = 0; i < scrollElements.length; i++ ) {
715-
TestHelpers.draggable.restoreScroll( scrollElements[ i ] );
716-
}
717-
}
718-
719-
if ( scrollElements.length === 1 && scrollElements[ 1 ] === "#scrollParent" ) {
720-
TestHelpers.draggable.setScrollable( "#main", true );
721-
TestHelpers.draggable.setScrollable( "#scrollParent", false );
722-
}
723-
});
724-
})( positions[ l ], helpers[ m ], scrollElements[ k ], k );
725-
}
726-
}
727-
}
721+
$.each( helpers, function() {
722+
var helper = this;
723+
$.each( positions, function() {
724+
var position = this;
725+
$.each( scrollElementsMap, function( scrollElementsTitle, scrollElements ) {
726+
testHelperPosition( scrollPositions, position, helper, scrollElements, scrollElementsTitle );
727+
});
728+
});
729+
});
728730
})();
729-
/* jshint loopfunc: false */
730731

731732
test( "{ opacity: 0.5 }", function() {
732733
expect( 1 );

0 commit comments

Comments
 (0)