Skip to content

Commit 56f6f92

Browse files
committed
Selectmenu: Test cleanup
1 parent d8062dc commit 56f6f92

File tree

1 file changed

+47
-45
lines changed

1 file changed

+47
-45
lines changed
Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
(function ( $ ) {
22

33
module( "selectmenu: events", {
4-
setup: function () {
4+
setup: function() {
55
this.element = $( "#speed" );
66
}
77
});
88

9-
asyncTest( "change", function () {
10-
expect( 5 );
9+
asyncTest( "change", function() {
10+
expect( 3 );
1111

12-
var optionIndex = 1,
13-
button, menu, options;
12+
var button, menu, options,
13+
optionIndex = 1;
1414

1515
this.element.selectmenu({
1616
change: function ( event, ui ) {
17-
ok( event, "change event fired on change" );
18-
equal( event.type, "selectmenuchange", "event type set to selectmenuchange" );
1917
equal( ui.item.index, optionIndex, "ui.item.index contains correct option index" );
20-
equal( ui.item.element[ 0 ], options.eq( optionIndex )[ 0 ], "ui.item.element contains original option element" );
21-
equal( ui.item.value, options.eq( optionIndex ).text(), "ui.item.value property updated correctly" );
18+
equal( ui.item.element[ 0 ], options.eq( optionIndex )[ 0 ],
19+
"ui.item.element contains original option element" );
20+
equal( ui.item.value, options.eq( optionIndex ).text(),
21+
"ui.item.value property updated correctly" );
2222
}
2323
});
2424

2525
button = this.element.selectmenu( "widget" );
26-
menu = this.element.selectmenu( "menuWidget" ).parent();
26+
menu = this.element.selectmenu( "menuWidget" );
2727
options = this.element.find( "option" );
2828

2929
button.simulate( "focus" );
@@ -32,49 +32,53 @@ asyncTest( "change", function () {
3232
button.trigger( "click" );
3333
menu.find( "li" ).eq( optionIndex ).simulate( "mouseover" ).trigger( "click" );
3434
start();
35-
}, 1 );
35+
});
3636
});
3737

3838

39-
test( "close", function () {
40-
expect( 4 );
39+
test( "close", function() {
40+
expect( 2 );
41+
42+
var shouldFire;
4143

4244
this.element.selectmenu({
43-
close: function ( event ) {
44-
ok( event, "close event fired on close" );
45-
equal( event.type, "selectmenuclose", "event type set to selectmenuclose" );
45+
close: function() {
46+
ok( shouldFire, "close event fired on close" );
4647
}
4748
});
4849

49-
this.element.selectmenu( "open" ).selectmenu( "close" );
50-
50+
shouldFire = false;
51+
this.element.selectmenu( "open" )
52+
shouldFire = true;
53+
this.element.selectmenu( "close" );
54+
shouldFire = false;
5155
this.element.selectmenu( "open" );
56+
shouldFire = true;
5257
$( "body" ).trigger( "mousedown" );
5358
});
5459

5560

56-
asyncTest( "focus", function () {
57-
expect( 12 );
61+
asyncTest( "focus", function() {
62+
expect( 9 );
5863

59-
var that = this,
64+
var button, menu, links,
65+
that = this,
6066
optionIndex = this.element[ 0 ].selectedIndex + 1,
61-
options = this.element.find( "option" ),
62-
button, menu, links;
67+
options = this.element.find( "option" );
6368

6469
this.element.selectmenu({
65-
focus: function ( event, ui ) {
66-
ok( event, "focus event fired on element #" + optionIndex + " mouseover" );
67-
equal( event.type, "selectmenufocus", "event type set to selectmenufocus" );
70+
focus: function( event, ui ) {
71+
ok( true, "focus event fired on element #" + optionIndex + " mouseover" );
6872
equal( ui.item.index, optionIndex, "ui.item.index contains correct option index" );
69-
equal( ui.item.element[ 0 ], options.eq( optionIndex )[ 0 ], "ui.item.element contains original option element" );
73+
equal( ui.item.element[ 0 ], options.eq( optionIndex )[ 0 ],
74+
"ui.item.element contains original option element" );
7075
}
7176
});
7277

7378
button = this.element.selectmenu( "widget" );
7479
menu = this.element.selectmenu( "menuWidget" );
7580

7681
button.simulate( "focus" );
77-
7882
setTimeout(function() {
7983
button.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
8084

@@ -85,51 +89,49 @@ asyncTest( "focus", function () {
8589
optionIndex += 1;
8690
links.eq( optionIndex ).simulate( "mouseover" );
8791

88-
// this tests for unwanted, additional focus event on close
92+
// This tests for unwanted, additional focus event on close
8993
that.element.selectmenu( "close" );
9094
start();
91-
}, 1 );
95+
});
9296
});
9397

9498

95-
test( "open", function () {
96-
expect( 2 );
99+
test( "open", function() {
100+
expect( 1 );
97101

98102
this.element.selectmenu({
99-
open: function ( event ) {
100-
ok( event, "open event fired on open" );
101-
equal( event.type, "selectmenuopen", "event type set to selectmenuopen" );
103+
open: function() {
104+
ok( true, "open event fired on open" );
102105
}
103106
});
104107

105108
this.element.selectmenu( "open" );
106109
});
107110

108111

109-
asyncTest( "select", function () {
110-
expect( 4 );
112+
asyncTest( "select", function() {
113+
expect( 3 );
111114

112115
this.element.selectmenu({
113-
select: function ( event, ui ) {
114-
ok( event, "select event fired on item select" );
115-
equal( event.type, "selectmenuselect", "event type set to selectmenuselect" );
116+
select: function( event, ui ) {
117+
ok( true, "select event fired on item select" );
116118
equal( ui.item.index, optionIndex, "ui.item.index contains correct option index" );
117-
equal( ui.item.element[ 0 ], options.eq( optionIndex )[ 0 ], "ui.item.element contains original option element" );
119+
equal( ui.item.element[ 0 ], options.eq( optionIndex )[ 0 ],
120+
"ui.item.element contains original option element" );
118121
}
119122
});
120123

121124
var button = this.element.selectmenu( "widget" ),
122-
menu = this.element.selectmenu( "menuWidget" ).parent(),
125+
menu = this.element.selectmenu( "menuWidget" ),
123126
options = this.element.find( "option" ),
124127
optionIndex = 1;
125128

126129
button.simulate( "focus" );
127-
128130
setTimeout(function() {
129131
button.trigger( "click" );
130132
menu.find( "li" ).eq( optionIndex ).simulate( "mouseover" ).trigger( "click" );
131133
start();
132-
}, 1 );
134+
});
133135
});
134136

135-
})(jQuery);
137+
})( jQuery );

0 commit comments

Comments
 (0)