From 0144b270c8addb5553db36e236782e747015b361 Mon Sep 17 00:00:00 2001 From: Mike Sherov Date: Sun, 20 Oct 2013 08:37:34 -0400 Subject: [PATCH] Draggable Tests: clarify scroll helpers. --- tests/unit/draggable/draggable_options.js | 112 +++++++++--------- .../unit/draggable/draggable_test_helpers.js | 12 +- 2 files changed, 58 insertions(+), 66 deletions(-) diff --git a/tests/unit/draggable/draggable_options.js b/tests/unit/draggable/draggable_options.js index 27d53639f..e18080a5b 100644 --- a/tests/unit/draggable/draggable_options.js +++ b/tests/unit/draggable/draggable_options.js @@ -694,16 +694,16 @@ test( "{ helper: 'original' }, relative, with scroll offset on parent", function var element = $( "#draggable1" ).draggable({ helper: "original" }); - TestHelpers.draggable.setScroll(); + TestHelpers.draggable.setScroll( "#main" ); TestHelpers.draggable.testScroll( element, "relative" ); - TestHelpers.draggable.setScroll(); + TestHelpers.draggable.setScroll( "#main" ); TestHelpers.draggable.testScroll( element, "static" ); - TestHelpers.draggable.setScroll(); + TestHelpers.draggable.setScroll( "#main" ); TestHelpers.draggable.testScroll( element, "absolute" ); - TestHelpers.draggable.restoreScroll(); + TestHelpers.draggable.restoreScroll( "#main" ); }); test( "{ helper: 'original' }, relative, with scroll offset on root", function() { @@ -711,16 +711,16 @@ test( "{ helper: 'original' }, relative, with scroll offset on root", function() var element = $( "#draggable1" ).draggable({ helper: "original" }); - TestHelpers.draggable.setScroll( "root" ); + TestHelpers.draggable.setScroll( document ); TestHelpers.draggable.testScroll( element, "relative" ); - TestHelpers.draggable.setScroll( "root" ); + TestHelpers.draggable.setScroll( document ); TestHelpers.draggable.testScroll( element, "static" ); - TestHelpers.draggable.setScroll( "root" ); + TestHelpers.draggable.setScroll( document ); TestHelpers.draggable.testScroll( element, "absolute" ); - TestHelpers.draggable.restoreScroll( "root" ); + TestHelpers.draggable.restoreScroll( document ); }); test( "{ helper: 'original' }, relative, with scroll offset on root and parent", function() { @@ -728,20 +728,20 @@ test( "{ helper: 'original' }, relative, with scroll offset on root and parent", var element = $( "#draggable1" ).draggable({ helper: "original" }); - TestHelpers.draggable.setScroll(); - TestHelpers.draggable.setScroll( "root" ); + TestHelpers.draggable.setScroll( "#main" ); + TestHelpers.draggable.setScroll( document ); TestHelpers.draggable.testScroll( element, "relative" ); - TestHelpers.draggable.setScroll(); - TestHelpers.draggable.setScroll( "root" ); + TestHelpers.draggable.setScroll( "#main" ); + TestHelpers.draggable.setScroll( document ); TestHelpers.draggable.testScroll( element, "static" ); - TestHelpers.draggable.setScroll(); - TestHelpers.draggable.setScroll( "root" ); + TestHelpers.draggable.setScroll( "#main" ); + TestHelpers.draggable.setScroll( document ); TestHelpers.draggable.testScroll( element, "absolute" ); - TestHelpers.draggable.restoreScroll(); - TestHelpers.draggable.restoreScroll( "root" ); + TestHelpers.draggable.restoreScroll( "#main" ); + TestHelpers.draggable.restoreScroll( document ); }); test( "{ helper: 'original' }, absolute, with scroll offset on parent", function() { @@ -749,16 +749,16 @@ test( "{ helper: 'original' }, absolute, with scroll offset on parent", function var element = $( "#draggable1" ).css({ position: "absolute", top: 0, left: 0 }).draggable({ helper: "original" }); - TestHelpers.draggable.setScroll(); + TestHelpers.draggable.setScroll( "#main" ); TestHelpers.draggable.testScroll( element, "relative" ); - TestHelpers.draggable.setScroll(); + TestHelpers.draggable.setScroll( "#main" ); TestHelpers.draggable.testScroll( element, "static" ); - TestHelpers.draggable.setScroll(); + TestHelpers.draggable.setScroll( "#main" ); TestHelpers.draggable.testScroll( element, "absolute" ); - TestHelpers.draggable.restoreScroll(); + TestHelpers.draggable.restoreScroll( "#main" ); }); test( "{ helper: 'original' }, absolute, with scroll offset on root", function() { @@ -766,16 +766,16 @@ test( "{ helper: 'original' }, absolute, with scroll offset on root", function() var element = $( "#draggable1" ).css({ position: "absolute", top: 0, left: 0 }).draggable({ helper: "original" }); - TestHelpers.draggable.setScroll( "root" ); + TestHelpers.draggable.setScroll( document ); TestHelpers.draggable.testScroll( element, "relative" ); - TestHelpers.draggable.setScroll( "root" ); + TestHelpers.draggable.setScroll( document ); TestHelpers.draggable.testScroll( element, "static" ); - TestHelpers.draggable.setScroll( "root" ); + TestHelpers.draggable.setScroll( document ); TestHelpers.draggable.testScroll( element, "absolute" ); - TestHelpers.draggable.restoreScroll( "root" ); + TestHelpers.draggable.restoreScroll( document ); }); test( "{ helper: 'original' }, absolute, with scroll offset on root and parent", function() { @@ -783,20 +783,20 @@ test( "{ helper: 'original' }, absolute, with scroll offset on root and parent", var element = $( "#draggable1" ).css({ position: "absolute", top: 0, left: 0 }).draggable({ helper: "original" }); - TestHelpers.draggable.setScroll(); - TestHelpers.draggable.setScroll( "root" ); + TestHelpers.draggable.setScroll( "#main" ); + TestHelpers.draggable.setScroll( document ); TestHelpers.draggable.testScroll( element, "relative" ); - TestHelpers.draggable.setScroll(); - TestHelpers.draggable.setScroll( "root" ); + TestHelpers.draggable.setScroll( "#main" ); + TestHelpers.draggable.setScroll( document ); TestHelpers.draggable.testScroll( element, "static" ); - TestHelpers.draggable.setScroll(); - TestHelpers.draggable.setScroll( "root" ); + TestHelpers.draggable.setScroll( "#main" ); + TestHelpers.draggable.setScroll( document ); TestHelpers.draggable.testScroll( element, "absolute" ); - TestHelpers.draggable.restoreScroll(); - TestHelpers.draggable.restoreScroll( "root" ); + TestHelpers.draggable.restoreScroll( "#main" ); + TestHelpers.draggable.restoreScroll( document ); }); test( "{ helper: 'original' }, fixed, with scroll offset on parent", function() { @@ -804,16 +804,16 @@ test( "{ helper: 'original' }, fixed, with scroll offset on parent", function() var element = $( "#draggable1" ).css({ position: "fixed", top: 0, left: 0 }).draggable({ helper: "original" }); - TestHelpers.draggable.setScroll(); + TestHelpers.draggable.setScroll( "#main" ); TestHelpers.draggable.testScroll( element, "relative" ); - TestHelpers.draggable.setScroll(); + TestHelpers.draggable.setScroll( "#main" ); TestHelpers.draggable.testScroll( element, "static" ); - TestHelpers.draggable.setScroll(); + TestHelpers.draggable.setScroll( "#main" ); TestHelpers.draggable.testScroll( element, "absolute" ); - TestHelpers.draggable.restoreScroll(); + TestHelpers.draggable.restoreScroll( "#main" ); }); test( "{ helper: 'original' }, fixed, with scroll offset on root", function() { @@ -821,16 +821,16 @@ test( "{ helper: 'original' }, fixed, with scroll offset on root", function() { var element = $( "#draggable1" ).css({ position: "fixed", top: 0, left: 0 }).draggable({ helper: "original" }); - TestHelpers.draggable.setScroll( "root" ); + TestHelpers.draggable.setScroll( document ); TestHelpers.draggable.testScroll( element, "relative" ); - TestHelpers.draggable.setScroll( "root" ); + TestHelpers.draggable.setScroll( document ); TestHelpers.draggable.testScroll( element, "static" ); - TestHelpers.draggable.setScroll( "root" ); + TestHelpers.draggable.setScroll( document ); TestHelpers.draggable.testScroll( element, "absolute" ); - TestHelpers.draggable.restoreScroll( "root" ); + TestHelpers.draggable.restoreScroll( document ); }); test( "{ helper: 'original' }, fixed, with scroll offset on root and parent", function() { @@ -838,20 +838,20 @@ test( "{ helper: 'original' }, fixed, with scroll offset on root and parent", fu var element = $( "#draggable1" ).css({ position: "fixed", top: 0, left: 0 }).draggable({ helper: "original" }); - TestHelpers.draggable.setScroll(); - TestHelpers.draggable.setScroll( "root" ); + TestHelpers.draggable.setScroll( "#main" ); + TestHelpers.draggable.setScroll( document ); TestHelpers.draggable.testScroll( element, "relative" ); - TestHelpers.draggable.setScroll(); - TestHelpers.draggable.setScroll( "root" ); + TestHelpers.draggable.setScroll( "#main" ); + TestHelpers.draggable.setScroll( document ); TestHelpers.draggable.testScroll( element, "static" ); - TestHelpers.draggable.setScroll(); - TestHelpers.draggable.setScroll( "root" ); + TestHelpers.draggable.setScroll( "#main" ); + TestHelpers.draggable.setScroll( document ); TestHelpers.draggable.testScroll( element, "absolute" ); - TestHelpers.draggable.restoreScroll(); - TestHelpers.draggable.restoreScroll( "root" ); + TestHelpers.draggable.restoreScroll( "#main" ); + TestHelpers.draggable.restoreScroll( document ); }); test( "{ helper: 'clone' }, absolute", function() { @@ -873,7 +873,7 @@ test( "{ helper: 'clone' }, absolute", function() { test( "{ helper: 'clone' }, absolute with scroll offset on parent", function() { expect( 3 ); - TestHelpers.draggable.setScroll(); + TestHelpers.draggable.setScroll( "#main" ); var helperOffset = null, origOffset = null, element = $( "#draggable1" ).draggable({ @@ -907,13 +907,13 @@ test( "{ helper: 'clone' }, absolute with scroll offset on parent", function() { }); deepEqual({ top: helperOffset.top - 1, left: helperOffset.left - 1 }, origOffset, "dragged[1, 1]" ); - TestHelpers.draggable.restoreScroll(); + TestHelpers.draggable.restoreScroll( "#main" ); }); test( "{ helper: 'clone' }, absolute with scroll offset on root", function() { expect( 3 ); - TestHelpers.draggable.setScroll( "root" ); + TestHelpers.draggable.setScroll( document ); var helperOffset = null, origOffset = null, element = $( "#draggable1" ).draggable({ @@ -947,14 +947,14 @@ test( "{ helper: 'clone' }, absolute with scroll offset on root", function() { }); deepEqual({ top: helperOffset.top - 1, left: helperOffset.left - 1 }, origOffset, "dragged[1, 1]" ); - TestHelpers.draggable.restoreScroll( "root" ); + TestHelpers.draggable.restoreScroll( document ); }); test( "{ helper: 'clone' }, absolute with scroll offset on root and parent", function() { expect( 3 ); - TestHelpers.draggable.setScroll( "root" ); - TestHelpers.draggable.setScroll(); + TestHelpers.draggable.setScroll( document ); + TestHelpers.draggable.setScroll( "#main" ); var helperOffset = null, origOffset = null, @@ -989,8 +989,8 @@ test( "{ helper: 'clone' }, absolute with scroll offset on root and parent", fun }); deepEqual({ top: helperOffset.top - 1, left: helperOffset.left - 1 }, origOffset, "dragged[1, 1]" ); - TestHelpers.draggable.restoreScroll( "root" ); - TestHelpers.draggable.restoreScroll(); + TestHelpers.draggable.restoreScroll( document ); + TestHelpers.draggable.restoreScroll( "#main" ); }); test( "{ opacity: 0.5 }", function() { diff --git a/tests/unit/draggable/draggable_test_helpers.js b/tests/unit/draggable/draggable_test_helpers.js index 00ff08d3e..c17992b98 100644 --- a/tests/unit/draggable/draggable_test_helpers.js +++ b/tests/unit/draggable/draggable_test_helpers.js @@ -38,18 +38,10 @@ TestHelpers.draggable = { $( "#main" ).css( "position", oldPosition ); }, restoreScroll: function( what ) { - if( what ) { - $( document ).scrollTop( 0 ).scrollLeft( 0 ); - } else { - $( "#main" ).scrollTop( 0 ).scrollLeft( 0 ); - } + $( what ).scrollTop( 0 ).scrollLeft( 0 ); }, setScroll: function( what ) { - if( what ) { - $( document ).scrollTop( 100 ).scrollLeft( 100 ); - } else { - $( "#main" ).scrollTop( 100 ).scrollLeft( 100 ); - } + $( what ).scrollTop( 100 ).scrollLeft( 100 ); }, border: function( el, side ) { return parseInt( el.css( "border-" + side + "-width" ), 10 ) || 0; -- 2.39.5