Skip to content

Commit 46f607a

Browse files
committed
Draggable: Shift to use no globals
1 parent 86fd11d commit 46f607a

File tree

6 files changed

+427
-418
lines changed

6 files changed

+427
-418
lines changed

tests/unit/draggable/common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ common.testWidget( "draggable", {
3131
stack: false,
3232
zIndex: false,
3333

34-
//todo: remove the following option checks when interactions are rewritten:
34+
//Todo: remove the following option checks when interactions are rewritten:
3535
addClasses: true,
3636
delay: 0,
3737
distance: 1,

tests/unit/draggable/core.js

Lines changed: 66 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
define( [
2+
"qunit",
23
"jquery",
34
"./helper",
45
"ui/widgets/draggable",
56
"ui/widgets/droppable",
67
"ui/widgets/resizable"
7-
], function( $, testHelper ) {
8+
], function( QUnit, $, testHelper ) {
89

9-
module( "draggable: core" );
10+
QUnit.module( "draggable: core" );
1011

11-
test( "element types", function( assert ) {
12+
QUnit.test( "element types", function( assert ) {
1213
var typeNames = (
1314
"p,h1,h2,h3,h4,h5,h6,blockquote,ol,ul,dl,div,form" +
1415
",table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr" +
1516
",acronym,code,samp,kbd,var,img,hr" +
1617
",input,button,label,select,iframe"
1718
).split( "," );
1819

19-
expect( typeNames.length * 2 );
20+
assert.expect( typeNames.length * 2 );
2021

2122
$.each( typeNames, function( i ) {
2223
var offsetBefore, offsetAfter,
@@ -44,18 +45,18 @@ test( "element types", function( assert ) {
4445
} );
4546
} );
4647

47-
test( "No options, relative", function() {
48-
expect( 2 );
49-
testHelper.shouldMove( $( "#draggable1" ).draggable(), "no options, relative" );
48+
QUnit.test( "No options, relative", function( assert ) {
49+
assert.expect( 2 );
50+
testHelper.shouldMove( assert, $( "#draggable1" ).draggable(), "no options, relative" );
5051
} );
5152

52-
test( "No options, absolute", function() {
53-
expect( 2 );
54-
testHelper.shouldMove( $( "#draggable2" ).draggable(), "no options, absolute" );
53+
QUnit.test( "No options, absolute", function( assert ) {
54+
assert.expect( 2 );
55+
testHelper.shouldMove( assert, $( "#draggable2" ).draggable(), "no options, absolute" );
5556
} );
5657

57-
test( "resizable handle with complex markup (#8756 / #8757)", function() {
58-
expect( 2 );
58+
QUnit.test( "resizable handle with complex markup (#8756 / #8757)", function( assert ) {
59+
assert.expect( 2 );
5960

6061
$( "#draggable1" )
6162
.append(
@@ -69,34 +70,34 @@ test( "resizable handle with complex markup (#8756 / #8757)", function() {
6970

7071
// Todo: fix resizable so it doesn't require a mouseover
7172
handle.simulate( "mouseover" ).simulate( "drag", { dx: -50 } );
72-
equal( target.width(), 250, "compare width" );
73+
assert.equal( target.width(), 250, "compare width" );
7374

7475
// Todo: fix resizable so it doesn't require a mouseover
7576
handle.simulate( "mouseover" ).simulate( "drag", { dx: 50 } );
76-
equal( target.width(), 200, "compare width" );
77+
assert.equal( target.width(), 200, "compare width" );
7778
} );
7879

79-
test( "#8269: Removing draggable element on drop", function() {
80-
expect( 2 );
80+
QUnit.test( "#8269: Removing draggable element on drop", function( assert ) {
81+
assert.expect( 2 );
8182

8283
var element = $( "#draggable1" ).wrap( "<div id='wrapper' />" ).draggable( {
8384
stop: function() {
84-
ok( true, "stop still called despite element being removed from DOM on drop" );
85+
assert.ok( true, "stop still called despite element being removed from DOM on drop" );
8586
}
8687
} ),
8788
dropOffset = $( "#droppable" ).offset();
8889

8990
$( "#droppable" ).droppable( {
9091
drop: function() {
9192
$( "#wrapper" ).remove();
92-
ok( true, "element removed from DOM on drop" );
93+
assert.ok( true, "element removed from DOM on drop" );
9394
}
9495
} );
9596

9697
// Support: Opera 12.10, Safari 5.1, jQuery <1.8
9798
if ( testHelper.unreliableContains ) {
98-
ok( true, "Opera <12.14 and Safari <6.0 report wrong values for $.contains in jQuery < 1.8" );
99-
ok( true, "Opera <12.14 and Safari <6.0 report wrong values for $.contains in jQuery < 1.8" );
99+
assert.ok( true, "Opera <12.14 and Safari <6.0 report wrong values for $.contains in jQuery < 1.8" );
100+
assert.ok( true, "Opera <12.14 and Safari <6.0 report wrong values for $.contains in jQuery < 1.8" );
100101
} else {
101102
element.simulate( "drag", {
102103
handle: "corner",
@@ -108,8 +109,8 @@ test( "#8269: Removing draggable element on drop", function() {
108109

109110
// http://bugs.jqueryui.com/ticket/7778
110111
// drag element breaks in IE8 when its content is replaced onmousedown
111-
test( "Stray mousemove after mousedown still drags", function() {
112-
expect( 2 );
112+
QUnit.test( "Stray mousemove after mousedown still drags", function( assert ) {
113+
assert.expect( 2 );
113114

114115
var element = $( "#draggable1" ).draggable( { scroll: false } );
115116

@@ -120,16 +121,16 @@ test( "Stray mousemove after mousedown still drags", function() {
120121
$( document ).simulate( "mousemove", { button: -1 } );
121122
} );
122123

123-
testHelper.shouldMove( element, "element is draggable" );
124+
testHelper.shouldMove( assert, element, "element is draggable" );
124125
} );
125126

126-
test( "#6258: not following mouse when scrolled and using overflow-y: scroll", function() {
127-
expect( 2 );
127+
QUnit.test( "#6258: not following mouse when scrolled and using overflow-y: scroll", function( assert ) {
128+
assert.expect( 2 );
128129

129130
var element = $( "#draggable1" ).draggable( {
130131
stop: function( event, ui ) {
131-
equal( ui.position.left, 1, "left position is correct despite overflow on HTML" );
132-
equal( ui.position.top, 1, "top position is correct despite overflow on HTML" );
132+
assert.equal( ui.position.left, 1, "left position is correct despite overflow on HTML" );
133+
assert.equal( ui.position.top, 1, "top position is correct despite overflow on HTML" );
133134
$( "html" )
134135
.css( "overflow-y", oldOverflowY )
135136
.css( "overflow-x", oldOverflowX )
@@ -155,13 +156,13 @@ test( "#6258: not following mouse when scrolled and using overflow-y: scroll", f
155156
} );
156157
} );
157158

158-
test( "#9315: jumps down with offset of scrollbar", function() {
159-
expect( 2 );
159+
QUnit.test( "#9315: jumps down with offset of scrollbar", function( assert ) {
160+
assert.expect( 2 );
160161

161162
var element = $( "#draggable2" ).draggable( {
162163
stop: function( event, ui ) {
163-
equal( ui.position.left, 11, "left position is correct when position is absolute" );
164-
equal( ui.position.top, 11, "top position is correct when position is absolute" );
164+
assert.equal( ui.position.left, 11, "left position is correct when position is absolute" );
165+
assert.equal( ui.position.top, 11, "top position is correct when position is absolute" );
165166
$( "html" ).scrollTop( 0 ).scrollLeft( 0 );
166167
}
167168
} );
@@ -177,8 +178,8 @@ test( "#9315: jumps down with offset of scrollbar", function() {
177178
} );
178179
} );
179180

180-
test( "scroll offset with fixed ancestors", function() {
181-
expect( 2 );
181+
QUnit.test( "scroll offset with fixed ancestors", function( assert ) {
182+
assert.expect( 2 );
182183

183184
var startValue = 300,
184185
element = $( "#draggable1" )
@@ -196,8 +197,8 @@ test( "scroll offset with fixed ancestors", function() {
196197
$( document ).scrollTop( startValue ).scrollLeft( startValue );
197198
},
198199
stop: function( event, ui ) {
199-
equal( ui.position.left, 10, "left position is correct when parent position is fixed" );
200-
equal( ui.position.top, 10, "top position is correct when parent position is fixed" );
200+
assert.equal( ui.position.left, 10, "left position is correct when parent position is fixed" );
201+
assert.equal( ui.position.top, 10, "top position is correct when parent position is fixed" );
201202
$( document ).scrollTop( 0 ).scrollLeft( 0 );
202203
}
203204
} );
@@ -219,8 +220,8 @@ $( [ "hidden", "auto", "scroll" ] ).each( function() {
219220

220221
// Http://bugs.jqueryui.com/ticket/9379 - position bug in scrollable div
221222
// http://bugs.jqueryui.com/ticket/10147 - Wrong position in a parent with "overflow: hidden"
222-
test( "position in scrollable parent with overflow: " + overflow, function() {
223-
expect( 2 );
223+
QUnit.test( "position in scrollable parent with overflow: " + overflow, function( assert ) {
224+
assert.expect( 2 );
224225

225226
$( "#qunit-fixture" ).html( "<div id='outer'><div id='inner'></div><div id='dragged'>a</div></div>" );
226227
$( "#inner" ).css( { position: "absolute", width: "500px", height: "500px" } );
@@ -240,8 +241,8 @@ $( [ "hidden", "auto", "scroll" ] ).each( function() {
240241
$( "#outer" ).scrollTop( startValue ).scrollLeft( startValue );
241242
},
242243
stop: function( event, ui ) {
243-
equal( ui.position.left, expected, "left position is correct when grandparent is scrolled" );
244-
equal( ui.position.top, expected, "top position is correct when grandparent is scrolled" );
244+
assert.equal( ui.position.left, expected, "left position is correct when grandparent is scrolled" );
245+
assert.equal( ui.position.top, expected, "top position is correct when grandparent is scrolled" );
245246
}
246247
} );
247248

@@ -255,8 +256,8 @@ $( [ "hidden", "auto", "scroll" ] ).each( function() {
255256
} );
256257
} );
257258

258-
test( "#5727: draggable from iframe", function() {
259-
expect( 1 );
259+
QUnit.test( "#5727: draggable from iframe", function( assert ) {
260+
assert.expect( 1 );
260261

261262
var iframeBody, draggable1,
262263
iframe = $( "<iframe />" ).appendTo( "#qunit-fixture" ),
@@ -270,53 +271,55 @@ test( "#5727: draggable from iframe", function() {
270271

271272
draggable1.draggable();
272273

273-
equal( draggable1.closest( iframeBody ).length, 1 );
274+
assert.equal( draggable1.closest( iframeBody ).length, 1 );
274275

275276
// TODO: fix draggable within an IFRAME to fire events on the element properly
276277
// and these testHelper.shouldMove relies on events for testing
277-
//testHelper.shouldMove( draggable1, "draggable from an iframe" );
278+
//testHelper.shouldMove( assert, draggable1, "draggable from an iframe" );
278279
} );
279280

280-
test( "#8399: A draggable should become the active element after you are finished interacting with it, but not before.", function() {
281-
expect( 2 );
281+
QUnit.test( "#8399: A draggable should become the active element after you are finished interacting with it, but not before.", function( assert ) {
282+
assert.expect( 2 );
282283

283284
var element = $( "<a href='#'>link</a>" ).appendTo( "#qunit-fixture" ).draggable();
284285

285286
$( document ).one( "mousemove", function() {
286-
notStrictEqual( document.activeElement, element.get( 0 ), "moving a draggable anchor did not make it the active element" );
287+
assert.notStrictEqual( document.activeElement, element.get( 0 ), "moving a draggable anchor did not make it the active element" );
287288
} );
288289

289290
testHelper.move( element, 50, 50 );
290291

291-
strictEqual( document.activeElement, element.get( 0 ), "finishing moving a draggable anchor made it the active element" );
292+
assert.strictEqual( document.activeElement, element.get( 0 ), "finishing moving a draggable anchor made it the active element" );
292293
} );
293294

294-
asyncTest( "blur behavior - handle is main element", function() {
295-
expect( 3 );
295+
QUnit.test( "blur behavior - handle is main element", function( assert ) {
296+
var ready = assert.async();
297+
assert.expect( 3 );
296298

297299
var element = $( "#draggable1" ).draggable(),
298300
focusElement = $( "<div tabindex='1'></div>" ).appendTo( element );
299301

300302
testHelper.onFocus( focusElement, function() {
301-
strictEqual( document.activeElement, focusElement.get( 0 ), "test element is focused before mousing down on a draggable" );
303+
assert.strictEqual( document.activeElement, focusElement.get( 0 ), "test element is focused before mousing down on a draggable" );
302304

303305
testHelper.move( focusElement, 1, 1 );
304306

305307
// Http://bugs.jqueryui.com/ticket/10527
306308
// Draggable: Can't select option in modal dialog (IE8)
307-
strictEqual( document.activeElement, focusElement.get( 0 ), "test element is focused after mousing down on itself" );
309+
assert.strictEqual( document.activeElement, focusElement.get( 0 ), "test element is focused after mousing down on itself" );
308310

309311
testHelper.move( element, 50, 50 );
310312

311313
// Http://bugs.jqueryui.com/ticket/4261
312314
// active element should blur when mousing down on a draggable
313-
notStrictEqual( document.activeElement, focusElement.get( 0 ), "test element is no longer focused after mousing down on a draggable" );
314-
start();
315+
assert.notStrictEqual( document.activeElement, focusElement.get( 0 ), "test element is no longer focused after mousing down on a draggable" );
316+
ready();
315317
} );
316318
} );
317319

318-
asyncTest( "blur behavior - descendant of handle", function() {
319-
expect( 2 );
320+
QUnit.test( "blur behavior - descendant of handle", function( assert ) {
321+
var ready = assert.async();
322+
assert.expect( 2 );
320323

321324
var element = $( "#draggable2" ).draggable( { handle: "span" } ),
322325

@@ -325,18 +328,18 @@ asyncTest( "blur behavior - descendant of handle", function() {
325328
focusElement = $( "<div tabindex='1'></div>" ).appendTo( element );
326329

327330
testHelper.onFocus( focusElement, function() {
328-
strictEqual( document.activeElement, focusElement.get( 0 ), "test element is focused before mousing down on a draggable" );
331+
assert.strictEqual( document.activeElement, focusElement.get( 0 ), "test element is focused before mousing down on a draggable" );
329332

330333
testHelper.move( handle, 50, 50 );
331334

332335
// Elements outside of the handle should blur (#12472, #14905)
333-
notStrictEqual( document.activeElement, focusElement.get( 0 ), "test element is no longer focused after mousing down on a draggable" );
334-
start();
336+
assert.notStrictEqual( document.activeElement, focusElement.get( 0 ), "test element is no longer focused after mousing down on a draggable" );
337+
ready();
335338
} );
336339
} );
337340

338-
test( "ui-draggable-handle assigned to appropriate element", function( assert ) {
339-
expect( 5 );
341+
QUnit.test( "ui-draggable-handle assigned to appropriate element", function( assert ) {
342+
assert.expect( 5 );
340343

341344
var p = $( "<p>" ).appendTo( "#qunit-fixture" ),
342345
element = $( "<div><p></p></div>" ).appendTo( "#qunit-fixture" ).draggable();
@@ -352,8 +355,8 @@ test( "ui-draggable-handle assigned to appropriate element", function( assert )
352355
assert.lacksClasses( element.find( "p" ), "ui-draggable-handle" );
353356
} );
354357

355-
test( "ui-draggable-handle managed correctly in nested draggables", function( assert ) {
356-
expect( 4 );
358+
QUnit.test( "ui-draggable-handle managed correctly in nested draggables", function( assert ) {
359+
assert.expect( 4 );
357360
var parent = $( "<div><div></div></div>" ).draggable().appendTo( "#qunit-fixture" ),
358361
child = parent.find( "div" ).draggable();
359362

@@ -371,7 +374,7 @@ test( "ui-draggable-handle managed correctly in nested draggables", function( as
371374
QUnit[ document.documentMode === 8 ? "skip" : "test" ](
372375
"does not stop propagation to window",
373376
function( assert ) {
374-
expect( 1 );
377+
assert.expect( 1 );
375378
var element = $( "#draggable1" ).draggable();
376379

377380
var handler = function() {

0 commit comments

Comments
 (0)