From 46f607af976abef77bf53685d21fa836359c8438 Mon Sep 17 00:00:00 2001 From: Amanpreet Singh Date: Sun, 3 Apr 2016 21:51:57 +0530 Subject: [PATCH] Draggable: Shift to use no globals --- tests/unit/draggable/common.js | 2 +- tests/unit/draggable/core.js | 129 ++++---- tests/unit/draggable/events.js | 55 ++-- tests/unit/draggable/helper.js | 47 +-- tests/unit/draggable/methods.js | 73 ++--- tests/unit/draggable/options.js | 539 ++++++++++++++++---------------- 6 files changed, 427 insertions(+), 418 deletions(-) diff --git a/tests/unit/draggable/common.js b/tests/unit/draggable/common.js index 228bba5dc..b2a46c7a7 100644 --- a/tests/unit/draggable/common.js +++ b/tests/unit/draggable/common.js @@ -31,7 +31,7 @@ common.testWidget( "draggable", { stack: false, zIndex: false, - //todo: remove the following option checks when interactions are rewritten: + //Todo: remove the following option checks when interactions are rewritten: addClasses: true, delay: 0, distance: 1, diff --git a/tests/unit/draggable/core.js b/tests/unit/draggable/core.js index a36852ebb..2ec102598 100644 --- a/tests/unit/draggable/core.js +++ b/tests/unit/draggable/core.js @@ -1,14 +1,15 @@ define( [ + "qunit", "jquery", "./helper", "ui/widgets/draggable", "ui/widgets/droppable", "ui/widgets/resizable" -], function( $, testHelper ) { +], function( QUnit, $, testHelper ) { -module( "draggable: core" ); +QUnit.module( "draggable: core" ); -test( "element types", function( assert ) { +QUnit.test( "element types", function( assert ) { var typeNames = ( "p,h1,h2,h3,h4,h5,h6,blockquote,ol,ul,dl,div,form" + ",table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr" + @@ -16,7 +17,7 @@ test( "element types", function( assert ) { ",input,button,label,select,iframe" ).split( "," ); - expect( typeNames.length * 2 ); + assert.expect( typeNames.length * 2 ); $.each( typeNames, function( i ) { var offsetBefore, offsetAfter, @@ -44,18 +45,18 @@ test( "element types", function( assert ) { } ); } ); -test( "No options, relative", function() { - expect( 2 ); - testHelper.shouldMove( $( "#draggable1" ).draggable(), "no options, relative" ); +QUnit.test( "No options, relative", function( assert ) { + assert.expect( 2 ); + testHelper.shouldMove( assert, $( "#draggable1" ).draggable(), "no options, relative" ); } ); -test( "No options, absolute", function() { - expect( 2 ); - testHelper.shouldMove( $( "#draggable2" ).draggable(), "no options, absolute" ); +QUnit.test( "No options, absolute", function( assert ) { + assert.expect( 2 ); + testHelper.shouldMove( assert, $( "#draggable2" ).draggable(), "no options, absolute" ); } ); -test( "resizable handle with complex markup (#8756 / #8757)", function() { - expect( 2 ); +QUnit.test( "resizable handle with complex markup (#8756 / #8757)", function( assert ) { + assert.expect( 2 ); $( "#draggable1" ) .append( @@ -69,19 +70,19 @@ test( "resizable handle with complex markup (#8756 / #8757)", function() { // Todo: fix resizable so it doesn't require a mouseover handle.simulate( "mouseover" ).simulate( "drag", { dx: -50 } ); - equal( target.width(), 250, "compare width" ); + assert.equal( target.width(), 250, "compare width" ); // Todo: fix resizable so it doesn't require a mouseover handle.simulate( "mouseover" ).simulate( "drag", { dx: 50 } ); - equal( target.width(), 200, "compare width" ); + assert.equal( target.width(), 200, "compare width" ); } ); -test( "#8269: Removing draggable element on drop", function() { - expect( 2 ); +QUnit.test( "#8269: Removing draggable element on drop", function( assert ) { + assert.expect( 2 ); var element = $( "#draggable1" ).wrap( "
" ).draggable( { stop: function() { - ok( true, "stop still called despite element being removed from DOM on drop" ); + assert.ok( true, "stop still called despite element being removed from DOM on drop" ); } } ), dropOffset = $( "#droppable" ).offset(); @@ -89,14 +90,14 @@ test( "#8269: Removing draggable element on drop", function() { $( "#droppable" ).droppable( { drop: function() { $( "#wrapper" ).remove(); - ok( true, "element removed from DOM on drop" ); + assert.ok( true, "element removed from DOM on drop" ); } } ); // Support: Opera 12.10, Safari 5.1, jQuery <1.8 if ( testHelper.unreliableContains ) { - ok( true, "Opera <12.14 and Safari <6.0 report wrong values for $.contains in jQuery < 1.8" ); - ok( true, "Opera <12.14 and Safari <6.0 report wrong values for $.contains in jQuery < 1.8" ); + assert.ok( true, "Opera <12.14 and Safari <6.0 report wrong values for $.contains in jQuery < 1.8" ); + assert.ok( true, "Opera <12.14 and Safari <6.0 report wrong values for $.contains in jQuery < 1.8" ); } else { element.simulate( "drag", { handle: "corner", @@ -108,8 +109,8 @@ test( "#8269: Removing draggable element on drop", function() { // http://bugs.jqueryui.com/ticket/7778 // drag element breaks in IE8 when its content is replaced onmousedown -test( "Stray mousemove after mousedown still drags", function() { - expect( 2 ); +QUnit.test( "Stray mousemove after mousedown still drags", function( assert ) { + assert.expect( 2 ); var element = $( "#draggable1" ).draggable( { scroll: false } ); @@ -120,16 +121,16 @@ test( "Stray mousemove after mousedown still drags", function() { $( document ).simulate( "mousemove", { button: -1 } ); } ); - testHelper.shouldMove( element, "element is draggable" ); + testHelper.shouldMove( assert, element, "element is draggable" ); } ); -test( "#6258: not following mouse when scrolled and using overflow-y: scroll", function() { - expect( 2 ); +QUnit.test( "#6258: not following mouse when scrolled and using overflow-y: scroll", function( assert ) { + assert.expect( 2 ); var element = $( "#draggable1" ).draggable( { stop: function( event, ui ) { - equal( ui.position.left, 1, "left position is correct despite overflow on HTML" ); - equal( ui.position.top, 1, "top position is correct despite overflow on HTML" ); + assert.equal( ui.position.left, 1, "left position is correct despite overflow on HTML" ); + assert.equal( ui.position.top, 1, "top position is correct despite overflow on HTML" ); $( "html" ) .css( "overflow-y", oldOverflowY ) .css( "overflow-x", oldOverflowX ) @@ -155,13 +156,13 @@ test( "#6258: not following mouse when scrolled and using overflow-y: scroll", f } ); } ); -test( "#9315: jumps down with offset of scrollbar", function() { - expect( 2 ); +QUnit.test( "#9315: jumps down with offset of scrollbar", function( assert ) { + assert.expect( 2 ); var element = $( "#draggable2" ).draggable( { stop: function( event, ui ) { - equal( ui.position.left, 11, "left position is correct when position is absolute" ); - equal( ui.position.top, 11, "top position is correct when position is absolute" ); + assert.equal( ui.position.left, 11, "left position is correct when position is absolute" ); + assert.equal( ui.position.top, 11, "top position is correct when position is absolute" ); $( "html" ).scrollTop( 0 ).scrollLeft( 0 ); } } ); @@ -177,8 +178,8 @@ test( "#9315: jumps down with offset of scrollbar", function() { } ); } ); -test( "scroll offset with fixed ancestors", function() { - expect( 2 ); +QUnit.test( "scroll offset with fixed ancestors", function( assert ) { + assert.expect( 2 ); var startValue = 300, element = $( "#draggable1" ) @@ -196,8 +197,8 @@ test( "scroll offset with fixed ancestors", function() { $( document ).scrollTop( startValue ).scrollLeft( startValue ); }, stop: function( event, ui ) { - equal( ui.position.left, 10, "left position is correct when parent position is fixed" ); - equal( ui.position.top, 10, "top position is correct when parent position is fixed" ); + assert.equal( ui.position.left, 10, "left position is correct when parent position is fixed" ); + assert.equal( ui.position.top, 10, "top position is correct when parent position is fixed" ); $( document ).scrollTop( 0 ).scrollLeft( 0 ); } } ); @@ -219,8 +220,8 @@ $( [ "hidden", "auto", "scroll" ] ).each( function() { // Http://bugs.jqueryui.com/ticket/9379 - position bug in scrollable div // http://bugs.jqueryui.com/ticket/10147 - Wrong position in a parent with "overflow: hidden" - test( "position in scrollable parent with overflow: " + overflow, function() { - expect( 2 ); + QUnit.test( "position in scrollable parent with overflow: " + overflow, function( assert ) { + assert.expect( 2 ); $( "#qunit-fixture" ).html( "
a
" ); $( "#inner" ).css( { position: "absolute", width: "500px", height: "500px" } ); @@ -240,8 +241,8 @@ $( [ "hidden", "auto", "scroll" ] ).each( function() { $( "#outer" ).scrollTop( startValue ).scrollLeft( startValue ); }, stop: function( event, ui ) { - equal( ui.position.left, expected, "left position is correct when grandparent is scrolled" ); - equal( ui.position.top, expected, "top position is correct when grandparent is scrolled" ); + assert.equal( ui.position.left, expected, "left position is correct when grandparent is scrolled" ); + assert.equal( ui.position.top, expected, "top position is correct when grandparent is scrolled" ); } } ); @@ -255,8 +256,8 @@ $( [ "hidden", "auto", "scroll" ] ).each( function() { } ); } ); -test( "#5727: draggable from iframe", function() { - expect( 1 ); +QUnit.test( "#5727: draggable from iframe", function( assert ) { + assert.expect( 1 ); var iframeBody, draggable1, iframe = $( "