Skip to content

Commit 8470b6a

Browse files
committed
Droppable: Shift to use no globals
1 parent 46f607a commit 8470b6a

File tree

5 files changed

+79
-74
lines changed

5 files changed

+79
-74
lines changed

tests/unit/droppable/core.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
define( [
2+
"qunit",
23
"jquery",
34
"./helper",
45
"ui/widgets/droppable"
5-
], function( $, testHelper ) {
6+
], function( QUnit, $, testHelper ) {
67

7-
module( "droppable: core" );
8+
QUnit.module( "droppable: core" );
89

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

15-
expect( typeNames.length );
16+
assert.expect( typeNames.length );
1617

1718
$.each( typeNames, function( i ) {
1819
var typeName = typeNames[ i ],
1920
el = $( document.createElement( typeName ) ).appendTo( "body" );
2021

2122
( typeName === "table" && el.append( "<tr><td>content</td></tr>" ) );
2223
el.droppable();
23-
testHelper.shouldDrop();
24+
testHelper.shouldDrop( assert );
2425
el.droppable( "destroy" );
2526
el.remove();
2627
} );

tests/unit/droppable/events.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
define( [
2+
"qunit",
23
"jquery",
34
"ui/widgets/droppable"
4-
], function( $ ) {
5+
], function( QUnit, $ ) {
56

6-
module( "droppable: events" );
7+
QUnit.module( "droppable: events" );
78

8-
test( "droppable destruction/recreation on drop event", function( assert ) {
9-
expect( 1 );
9+
QUnit.test( "droppable destruction/recreation on drop event", function( assert ) {
10+
assert.expect( 1 );
1011

1112
var config = {
1213
activeClass: "active",
@@ -38,9 +39,9 @@ test( "droppable destruction/recreation on drop event", function( assert ) {
3839
assert.lacksClasses( droppable2, "active", "subsequent droppable no longer active" );
3940
} );
4041

41-
// todo: comment the following in when ready to actually test
42+
// Todo: comment the following in when ready to actually test
4243
/*
43-
test("activate", function() {
44+
Test("activate", function() {
4445
ok(false, 'missing test - untested code is broken code');
4546
});
4647

tests/unit/droppable/helper.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
define( [
2+
"qunit",
23
"jquery",
34
"lib/helper"
4-
], function( $, helper ) {
5+
], function( QUnit, $, helper ) {
56

67
return $.extend( helper, {
7-
shouldDrop: function() {
8+
shouldDrop: function( assert ) {
89

9-
// todo: actually implement this
10-
ok( true, "missing test - untested code is broken code" );
10+
// Todo: actually implement this
11+
assert.ok( true, "missing test - untested code is broken code" );
1112
},
1213

13-
shouldNotDrop: function() {
14+
shouldNotDrop: function( assert ) {
1415

15-
// todo: actually implement this
16-
ok( true, "missing test - untested code is broken code" );
16+
// Todo: actually implement this
17+
assert.ok( true, "missing test - untested code is broken code" );
1718
}
1819
} );
1920

tests/unit/droppable/methods.js

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,93 @@
11
define( [
2+
"qunit",
23
"jquery",
34
"./helper",
45
"ui/widgets/droppable"
5-
], function( $, testHelper ) {
6+
], function( QUnit, $, testHelper ) {
67

7-
module( "droppable: methods" );
8+
QUnit.module( "droppable: methods" );
89

9-
test( "init", function() {
10-
expect( 5 );
10+
QUnit.test( "init", function( assert ) {
11+
assert.expect( 5 );
1112

1213
$( "<div></div>" ).appendTo( "body" ).droppable().remove();
13-
ok( true, ".droppable() called on element" );
14+
assert.ok( true, ".droppable() called on element" );
1415

1516
$( [] ).droppable();
16-
ok( true, ".droppable() called on empty collection" );
17+
assert.ok( true, ".droppable() called on empty collection" );
1718

1819
$( "<div></div>" ).droppable();
19-
ok( true, ".droppable() called on disconnected DOMElement" );
20+
assert.ok( true, ".droppable() called on disconnected DOMElement" );
2021

2122
$( "<div></div>" ).droppable().droppable( "option", "foo" );
22-
ok( true, "arbitrary option getter after init" );
23+
assert.ok( true, "arbitrary option getter after init" );
2324

2425
$( "<div></div>" ).droppable().droppable( "option", "foo", "bar" );
25-
ok( true, "arbitrary option setter after init" );
26+
assert.ok( true, "arbitrary option setter after init" );
2627
} );
2728

28-
test( "destroy", function() {
29-
expect( 4 );
29+
QUnit.test( "destroy", function( assert ) {
30+
assert.expect( 4 );
3031

3132
$( "<div></div>" ).appendTo( "body" ).droppable().droppable( "destroy" ).remove();
32-
ok( true, ".droppable('destroy') called on element" );
33+
assert.ok( true, ".droppable('destroy') called on element" );
3334

3435
$( [] ).droppable().droppable( "destroy" );
35-
ok( true, ".droppable('destroy') called on empty collection" );
36+
assert.ok( true, ".droppable('destroy') called on empty collection" );
3637

3738
$( "<div></div>" ).droppable().droppable( "destroy" );
38-
ok( true, ".droppable('destroy') called on disconnected DOMElement" );
39+
assert.ok( true, ".droppable('destroy') called on disconnected DOMElement" );
3940

4041
var expected = $( "<div></div>" ).droppable(),
4142
actual = expected.droppable( "destroy" );
42-
equal( actual, expected, "destroy is chainable" );
43+
assert.equal( actual, expected, "destroy is chainable" );
4344
} );
4445

45-
test( "enable", function() {
46-
expect( 7 );
46+
QUnit.test( "enable", function( assert ) {
47+
assert.expect( 7 );
4748

4849
var el, expected, actual;
4950

5051
el = $( "#droppable1" ).droppable( { disabled: true } );
51-
testHelper.shouldNotDrop();
52+
testHelper.shouldNotDrop( assert );
5253
el.droppable( "enable" );
53-
testHelper.shouldDrop();
54-
equal( el.droppable( "option", "disabled" ), false, "disabled option getter" );
54+
testHelper.shouldDrop( assert );
55+
assert.equal( el.droppable( "option", "disabled" ), false, "disabled option getter" );
5556
el.droppable( "destroy" );
5657
el.droppable( { disabled: true } );
57-
testHelper.shouldNotDrop();
58+
testHelper.shouldNotDrop( assert );
5859
el.droppable( "option", "disabled", false );
59-
equal( el.droppable( "option", "disabled" ), false, "disabled option setter" );
60-
testHelper.shouldDrop();
60+
assert.equal( el.droppable( "option", "disabled" ), false, "disabled option setter" );
61+
testHelper.shouldDrop( assert );
6162

6263
expected = $( "<div></div>" ).droppable(),
6364
actual = expected.droppable( "enable" );
64-
equal( actual, expected, "enable is chainable" );
65+
assert.equal( actual, expected, "enable is chainable" );
6566
} );
6667

67-
test( "disable", function( assert ) {
68-
expect( 10 );
68+
QUnit.test( "disable", function( assert ) {
69+
assert.expect( 10 );
6970

7071
var actual, expected,
7172
element = $( "#droppable1" ).droppable( { disabled: false } );
7273

73-
testHelper.shouldDrop();
74+
testHelper.shouldDrop( assert );
7475
element.droppable( "disable" );
75-
testHelper.shouldNotDrop();
76-
equal( element.droppable( "option", "disabled" ), true, "disabled option getter" );
76+
testHelper.shouldNotDrop( assert );
77+
assert.equal( element.droppable( "option", "disabled" ), true, "disabled option getter" );
7778
element.droppable( "destroy" );
7879
element.droppable( { disabled: false } );
79-
testHelper.shouldDrop();
80+
testHelper.shouldDrop( assert );
8081
element.droppable( "option", "disabled", true );
8182
assert.lacksClasses( element.droppable( "widget" ), "ui-state-disabled" );
82-
ok( !element.droppable( "widget" ).attr( "aria-disabled" ), "element does not get aria-disabled" );
83+
assert.ok( !element.droppable( "widget" ).attr( "aria-disabled" ), "element does not get aria-disabled" );
8384
assert.hasClasses( element.droppable( "widget" ), "ui-droppable-disabled" );
84-
equal( element.droppable( "option", "disabled" ), true, "disabled option setter" );
85-
testHelper.shouldNotDrop();
85+
assert.equal( element.droppable( "option", "disabled" ), true, "disabled option setter" );
86+
testHelper.shouldNotDrop( assert );
8687

8788
expected = $( "<div></div>" ).droppable();
8889
actual = expected.droppable( "disable" );
89-
equal( actual, expected, "disable is chainable" );
90+
assert.equal( actual, expected, "disable is chainable" );
9091
} );
9192

9293
} );

tests/unit/droppable/options.js

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
define( [
2+
"qunit",
23
"jquery",
34
"ui/widgets/droppable"
4-
], function( $ ) {
5+
], function( QUnit, $ ) {
56

6-
module( "droppable: options" );
7+
QUnit.module( "droppable: options" );
78

89
/*
9-
test( "{ accept '*' }, default ", function() {
10+
Test( "{ accept '*' }, default ", function() {
1011
ok(false, 'missing test - untested code is broken code');
1112
});
1213
@@ -22,23 +23,23 @@ test( "activeClass", function() {
2223
ok(false, 'missing test - untested code is broken code');
2324
});
2425
*/
25-
test( "{ addClasses: true }, default", function( assert ) {
26-
expect( 1 );
26+
QUnit.test( "{ addClasses: true }, default", function( assert ) {
27+
assert.expect( 1 );
2728
var el = $( "<div />" ).droppable( { addClasses: true } );
2829
assert.hasClasses( el, "ui-droppable" );
2930
el.droppable( "destroy" );
3031
} );
3132

32-
test( "{ addClasses: false }", function( assert ) {
33-
expect( 1 );
33+
QUnit.test( "{ addClasses: false }", function( assert ) {
34+
assert.expect( 1 );
3435
var el = $( "<div />" ).droppable( { addClasses: false } );
3536

3637
assert.lacksClasses( el, "ui-droppable" );
3738
el.droppable( "destroy" );
3839
} );
3940

40-
test( "scope", function() {
41-
expect( 4 );
41+
QUnit.test( "scope", function( assert ) {
42+
assert.expect( 4 );
4243
var droppableOffset, draggableOffset, oldDraggableOffset, dx, dy,
4344
draggable1 = $( "<div />" ).appendTo( "#qunit-fixture" ).draggable( { revert: "invalid" } ),
4445
draggable2 = $( "<div />" ).appendTo( "#qunit-fixture" ).droppable(),
@@ -60,8 +61,8 @@ test( "scope", function() {
6061
} );
6162

6263
draggableOffset = draggable1.offset();
63-
equal( draggableOffset.left, droppableOffset.left );
64-
equal( draggableOffset.top, droppableOffset.top );
64+
assert.equal( draggableOffset.left, droppableOffset.left );
65+
assert.equal( draggableOffset.top, droppableOffset.top );
6566

6667
// Test that droppable doesn't accept draggable with old scope.
6768
draggableOffset = draggable2.offset();
@@ -75,11 +76,11 @@ test( "scope", function() {
7576
} );
7677

7778
draggableOffset = draggable2.offset();
78-
equal( draggableOffset.left, oldDraggableOffset.left );
79-
equal( draggableOffset.top, oldDraggableOffset.top );
79+
assert.equal( draggableOffset.left, oldDraggableOffset.left );
80+
assert.equal( draggableOffset.top, oldDraggableOffset.top );
8081
} );
8182
/*
82-
test( "greedy", function() {
83+
Test( "greedy", function() {
8384
ok(false, 'missing test - untested code is broken code');
8485
});
8586
@@ -92,8 +93,8 @@ test( "tolerance, fit", function() {
9293
});
9394
*/
9495

95-
test( "tolerance, intersect", function() {
96-
expect( 2 );
96+
QUnit.test( "tolerance, intersect", function( assert ) {
97+
assert.expect( 2 );
9798

9899
var draggable, droppable,
99100
dataset = [
@@ -135,7 +136,7 @@ test( "tolerance, intersect", function() {
135136
} );
136137

137138
droppable.off( "drop" ).on( "drop", function() {
138-
equal( true, data[ 2 ], data[ 3 ] );
139+
assert.equal( true, data[ 2 ], data[ 3 ] );
139140
} );
140141

141142
$( draggable ).simulate( "drag", {
@@ -145,8 +146,8 @@ test( "tolerance, intersect", function() {
145146
} );
146147
} );
147148

148-
test( "tolerance, pointer", function() {
149-
expect( 3 );
149+
QUnit.test( "tolerance, pointer", function( assert ) {
150+
assert.expect( 3 );
150151

151152
var draggable, droppable,
152153
dataset = [
@@ -174,7 +175,7 @@ test( "tolerance, pointer", function() {
174175
var data = this;
175176

176177
droppable.off( "drop" ).on( "drop", function() {
177-
equal( true, data[ 2 ], data[ 3 ] );
178+
assert.equal( true, data[ 2 ], data[ 3 ] );
178179
} );
179180

180181
$( draggable ).simulate( "drag", {
@@ -188,7 +189,7 @@ test( "tolerance, pointer", function() {
188189
droppable.css( { top: 15, left: 15 } );
189190

190191
droppable.off( "drop" ).on( "drop", function() {
191-
ok( true, "drop fires as long as pointer is within droppable" );
192+
assert.ok( true, "drop fires as long as pointer is within droppable" );
192193
} );
193194

194195
$( draggable ).simulate( "drag", {
@@ -198,7 +199,7 @@ test( "tolerance, pointer", function() {
198199
} );
199200

200201
/*
201-
test( "tolerance, touch", function() {
202+
Test( "tolerance, touch", function() {
202203
ok(false, 'missing test - untested code is broken code');
203204
});
204205
*/

0 commit comments

Comments
 (0)