1
1
define ( [
2
+ "qunit" ,
2
3
"jquery" ,
3
4
"ui/widgets/selectmenu"
4
- ] , function ( $ ) {
5
+ ] , function ( QUnit , $ ) {
5
6
6
- module ( "selectmenu: core" ) ;
7
+ QUnit . module ( "selectmenu: core" ) ;
7
8
8
- test ( "markup structure" , function ( assert ) {
9
- expect ( 7 ) ;
9
+ QUnit . test ( "markup structure" , function ( assert ) {
10
+ assert . expect ( 7 ) ;
10
11
11
12
var element = $ ( "#files" ) . selectmenu ( ) ,
12
13
button = element . selectmenu ( "widget" ) ,
@@ -24,7 +25,8 @@ test( "markup structure", function( assert ) {
24
25
assert . strictEqual ( icon [ 0 ] , button . children ( ) [ 0 ] , "Icon is first child of button" ) ;
25
26
} ) ;
26
27
27
- asyncTest ( "accessibility" , function ( ) {
28
+ QUnit . test ( "accessibility" , function ( assert ) {
29
+ var ready = assert . async ( ) ;
28
30
var wrappers , button , menu ,
29
31
element = $ ( "#speed" ) . attr ( "title" , "A demo title" ) ;
30
32
@@ -39,43 +41,43 @@ asyncTest( "accessibility", function() {
39
41
button . simulate ( "focus" ) ;
40
42
wrappers = menu . find ( "li.ui-menu-item .ui-menu-item-wrapper" ) ;
41
43
42
- expect ( 13 + wrappers . length * 3 ) ;
44
+ assert . expect ( 13 + wrappers . length * 3 ) ;
43
45
44
46
setTimeout ( function ( ) {
45
- equal ( button . attr ( "role" ) , "combobox" , "button role" ) ;
46
- equal ( button . attr ( "aria-haspopup" ) , "true" , "button aria-haspopup" ) ;
47
- equal ( button . attr ( "aria-expanded" ) , "false" , "button aria-expanded" ) ;
48
- equal ( button . attr ( "aria-autocomplete" ) , "list" , "button aria-autocomplete" ) ;
49
- equal ( button . attr ( "aria-owns" ) , menu . attr ( "id" ) , "button aria-owns" ) ;
50
- equal (
47
+ assert . equal ( button . attr ( "role" ) , "combobox" , "button role" ) ;
48
+ assert . equal ( button . attr ( "aria-haspopup" ) , "true" , "button aria-haspopup" ) ;
49
+ assert . equal ( button . attr ( "aria-expanded" ) , "false" , "button aria-expanded" ) ;
50
+ assert . equal ( button . attr ( "aria-autocomplete" ) , "list" , "button aria-autocomplete" ) ;
51
+ assert . equal ( button . attr ( "aria-owns" ) , menu . attr ( "id" ) , "button aria-owns" ) ;
52
+ assert . equal (
51
53
button . attr ( "aria-labelledby" ) ,
52
54
wrappers . eq ( element [ 0 ] . selectedIndex ) . attr ( "id" ) ,
53
55
"button link aria-labelledby"
54
56
) ;
55
- equal ( button . attr ( "tabindex" ) , 0 , "button link tabindex" ) ;
56
- equal ( button . attr ( "title" ) , "A demo title" , "button title" ) ;
57
-
58
- equal ( menu . attr ( "role" ) , "listbox" , "menu role" ) ;
59
- equal ( menu . attr ( "aria-labelledby" ) , button . attr ( "id" ) , "menu aria-labelledby" ) ;
60
- equal ( menu . attr ( "aria-hidden" ) , "true" , "menu aria-hidden" ) ;
61
- equal ( menu . attr ( "tabindex" ) , 0 , "menu tabindex" ) ;
62
- equal (
57
+ assert . equal ( button . attr ( "tabindex" ) , 0 , "button link tabindex" ) ;
58
+ assert . equal ( button . attr ( "title" ) , "A demo title" , "button title" ) ;
59
+
60
+ assert . equal ( menu . attr ( "role" ) , "listbox" , "menu role" ) ;
61
+ assert . equal ( menu . attr ( "aria-labelledby" ) , button . attr ( "id" ) , "menu aria-labelledby" ) ;
62
+ assert . equal ( menu . attr ( "aria-hidden" ) , "true" , "menu aria-hidden" ) ;
63
+ assert . equal ( menu . attr ( "tabindex" ) , 0 , "menu tabindex" ) ;
64
+ assert . equal (
63
65
menu . attr ( "aria-activedescendant" ) ,
64
66
wrappers . eq ( element [ 0 ] . selectedIndex ) . attr ( "id" ) ,
65
67
"menu aria-activedescendant"
66
68
) ;
67
69
$ . each ( wrappers , function ( index ) {
68
70
var item = $ ( this ) ;
69
- equal ( item . attr ( "role" ) , "option" , "menu item #" + index + " role" ) ;
70
- equal ( item . attr ( "tabindex" ) , - 1 , "menu item #" + index + " tabindex" ) ;
71
- equal ( item . attr ( "title" ) , "A demo title #" + index , "menu item #" + index + " title" ) ;
71
+ assert . equal ( item . attr ( "role" ) , "option" , "menu item #" + index + " role" ) ;
72
+ assert . equal ( item . attr ( "tabindex" ) , - 1 , "menu item #" + index + " tabindex" ) ;
73
+ assert . equal ( item . attr ( "title" ) , "A demo title #" + index , "menu item #" + index + " title" ) ;
72
74
} ) ;
73
- start ( ) ;
75
+ ready ( ) ;
74
76
} ) ;
75
77
} ) ;
76
78
77
- test ( "_renderButtonItem()" , function ( ) {
78
- expect ( 2 ) ;
79
+ QUnit . test ( "_renderButtonItem()" , function ( assert ) {
80
+ assert . expect ( 2 ) ;
79
81
80
82
var option ,
81
83
element = $ ( "#speed" ) . selectmenu ( ) ,
@@ -92,7 +94,7 @@ test( "_renderButtonItem()", function() {
92
94
93
95
element . selectmenu ( "refresh" ) ;
94
96
option = element . find ( "option:selected" ) ;
95
- equal (
97
+ assert . equal (
96
98
$ . trim ( button . text ( ) ) ,
97
99
option . text ( ) + element [ 0 ] . selectedIndex ,
98
100
"refresh: button item text"
@@ -101,7 +103,7 @@ test( "_renderButtonItem()", function() {
101
103
button . trigger ( "click" ) ;
102
104
menu . find ( "li" ) . last ( ) . simulate ( "mouseover" ) . trigger ( "click" ) ;
103
105
option = element . find ( "option" ) . last ( ) ;
104
- equal (
106
+ assert . equal (
105
107
$ . trim ( button . text ( ) ) ,
106
108
option . text ( ) + element [ 0 ] . selectedIndex ,
107
109
"click: button item text"
@@ -118,8 +120,9 @@ $.each( [
118
120
selector : "#files"
119
121
}
120
122
] , function ( i , settings ) {
121
- asyncTest ( "state synchronization - after keydown on button - " + settings . type , function ( ) {
122
- expect ( 4 ) ;
123
+ QUnit . test ( "state synchronization - after keydown on button - " + settings . type , function ( assert ) {
124
+ var ready = assert . async ( ) ;
125
+ assert . expect ( 4 ) ;
123
126
124
127
var wrappers ,
125
128
element = $ ( settings . selector ) . selectmenu ( ) ,
@@ -135,28 +138,29 @@ $.each( [
135
138
wrappers = menu . find ( "li.ui-menu-item .ui-menu-item-wrapper" ) ;
136
139
137
140
button . simulate ( "keydown" , { keyCode : $ . ui . keyCode . DOWN } ) ;
138
- equal (
141
+ assert . equal (
139
142
menu . attr ( "aria-activedescendant" ) ,
140
143
wrappers . eq ( element [ 0 ] . selectedIndex ) . attr ( "id" ) ,
141
144
"menu aria-activedescendant"
142
145
) ;
143
- equal (
146
+ assert . equal (
144
147
button . attr ( "aria-activedescendant" ) ,
145
148
wrappers . eq ( element [ 0 ] . selectedIndex ) . attr ( "id" ) ,
146
149
"button aria-activedescendant"
147
150
) ;
148
- equal (
151
+ assert . equal (
149
152
element . find ( "option:selected" ) . val ( ) ,
150
153
selected . val ( ) ,
151
154
"original select state"
152
155
) ;
153
- equal ( $ . trim ( button . text ( ) ) , selected . text ( ) , "button text" ) ;
154
- start ( ) ;
156
+ assert . equal ( $ . trim ( button . text ( ) ) , selected . text ( ) , "button text" ) ;
157
+ ready ( ) ;
155
158
} ) ;
156
159
} ) ;
157
160
158
- asyncTest ( "state synchronization - after click on item - " + settings . type , function ( ) {
159
- expect ( 4 ) ;
161
+ QUnit . test ( "state synchronization - after click on item - " + settings . type , function ( assert ) {
162
+ var ready = assert . async ( ) ;
163
+ assert . expect ( 4 ) ;
160
164
161
165
var wrappers ,
162
166
element = $ ( settings . selector ) . selectmenu ( ) ,
@@ -170,29 +174,30 @@ $.each( [
170
174
171
175
button . trigger ( "click" ) ;
172
176
menu . find ( "li" ) . last ( ) . simulate ( "mouseover" ) . trigger ( "click" ) ;
173
- equal (
177
+ assert . equal (
174
178
menu . attr ( "aria-activedescendant" ) ,
175
179
wrappers . eq ( element [ 0 ] . selectedIndex ) . attr ( "id" ) ,
176
180
"menu aria-activedescendant"
177
181
) ;
178
- equal (
182
+ assert . equal (
179
183
button . attr ( "aria-activedescendant" ) ,
180
184
wrappers . eq ( element [ 0 ] . selectedIndex ) . attr ( "id" ) ,
181
185
"button aria-activedescendant"
182
186
) ;
183
- equal (
187
+ assert . equal (
184
188
element . find ( "option:selected" ) . val ( ) ,
185
189
selected . val ( ) ,
186
190
"original select state"
187
191
) ;
188
- equal ( $ . trim ( button . text ( ) ) , selected . text ( ) , "button text" ) ;
189
- start ( ) ;
192
+ assert . equal ( $ . trim ( button . text ( ) ) , selected . text ( ) , "button text" ) ;
193
+ ready ( ) ;
190
194
} , 1 ) ;
191
195
} ) ;
192
196
193
- asyncTest ( "state synchronization - " +
194
- "after focus item and keydown on button - " + settings . type , function ( ) {
195
- expect ( 4 ) ;
197
+ QUnit . test ( "state synchronization - " +
198
+ "after focus item and keydown on button - " + settings . type , function ( assert ) {
199
+ var ready = assert . async ( ) ;
200
+ assert . expect ( 4 ) ;
196
201
197
202
var wrappers ,
198
203
element = $ ( settings . selector ) . selectmenu ( ) ,
@@ -220,20 +225,21 @@ $.each( [
220
225
setTimeout ( function ( ) {
221
226
button . simulate ( "keydown" , { keyCode : $ . ui . keyCode . DOWN } ) ;
222
227
223
- equal ( menu . attr ( "aria-activedescendant" ) , wrappers . eq ( 1 ) . attr ( "id" ) ,
228
+ assert . equal ( menu . attr ( "aria-activedescendant" ) , wrappers . eq ( 1 ) . attr ( "id" ) ,
224
229
"menu aria-activedescendant" ) ;
225
- equal ( button . attr ( "aria-activedescendant" ) , wrappers . eq ( 1 ) . attr ( "id" ) ,
230
+ assert . equal ( button . attr ( "aria-activedescendant" ) , wrappers . eq ( 1 ) . attr ( "id" ) ,
226
231
"button aria-activedescendant" ) ;
227
- equal ( element . find ( "option:selected" ) . val ( ) , options . eq ( 1 ) . val ( ) ,
232
+ assert . equal ( element . find ( "option:selected" ) . val ( ) , options . eq ( 1 ) . val ( ) ,
228
233
"original select state" ) ;
229
- equal ( $ . trim ( button . text ( ) ) , options . eq ( 1 ) . text ( ) , "button text" ) ;
230
- start ( ) ;
234
+ assert . equal ( $ . trim ( button . text ( ) ) , options . eq ( 1 ) . text ( ) , "button text" ) ;
235
+ ready ( ) ;
231
236
} ) ;
232
237
} ) ;
233
238
} ) ;
234
239
235
- asyncTest ( "item looping - " + settings . type , function ( ) {
236
- expect ( 4 ) ;
240
+ QUnit . test ( "item looping - " + settings . type , function ( assert ) {
241
+ var ready = assert . async ( ) ;
242
+ assert . expect ( 4 ) ;
237
243
238
244
var wrappers ,
239
245
element = $ ( settings . selector ) . selectmenu ( ) ,
@@ -246,21 +252,22 @@ $.each( [
246
252
247
253
button . trigger ( "click" ) ;
248
254
wrappers . first ( ) . simulate ( "mouseover" ) . trigger ( "click" ) ;
249
- equal ( element [ 0 ] . selectedIndex , 0 , "First item is selected" ) ;
255
+ assert . equal ( element [ 0 ] . selectedIndex , 0 , "First item is selected" ) ;
250
256
button . simulate ( "keydown" , { keyCode : $ . ui . keyCode . UP } ) ;
251
- equal ( element [ 0 ] . selectedIndex , 0 , "No looping beyond first item" ) ;
257
+ assert . equal ( element [ 0 ] . selectedIndex , 0 , "No looping beyond first item" ) ;
252
258
253
259
button . trigger ( "click" ) ;
254
260
wrappers . last ( ) . simulate ( "mouseover" ) . trigger ( "click" ) ;
255
- equal ( element [ 0 ] . selectedIndex , wrappers . length - 1 , "Last item is selected" ) ;
261
+ assert . equal ( element [ 0 ] . selectedIndex , wrappers . length - 1 , "Last item is selected" ) ;
256
262
button . simulate ( "keydown" , { keyCode : $ . ui . keyCode . DOWN } ) ;
257
- equal ( element [ 0 ] . selectedIndex , wrappers . length - 1 , "No looping behind last item" ) ;
258
- start ( ) ;
263
+ assert . equal ( element [ 0 ] . selectedIndex , wrappers . length - 1 , "No looping behind last item" ) ;
264
+ ready ( ) ;
259
265
} ) ;
260
266
} ) ;
261
267
262
- asyncTest ( "item focus and active state - " + settings . type , function ( ) {
263
- expect ( 4 ) ;
268
+ QUnit . test ( "item focus and active state - " + settings . type , function ( assert ) {
269
+ var ready = assert . async ( ) ;
270
+ assert . expect ( 4 ) ;
264
271
265
272
var wrappers , focusedItem ,
266
273
element = $ ( settings . selector ) . selectmenu ( ) ,
@@ -288,21 +295,22 @@ $.each( [
288
295
button . trigger ( "click" ) ;
289
296
setTimeout ( function ( ) {
290
297
checkItemClasses ( ) ;
291
- start ( ) ;
298
+ ready ( ) ;
292
299
} ) ;
293
300
} ) ;
294
301
} ) ;
295
302
296
303
function checkItemClasses ( ) {
297
304
focusedItem = menu . find ( ".ui-menu-item-wrapper.ui-state-active" ) ;
298
- equal ( focusedItem . length , 1 , "only one item has ui-state-focus class" ) ;
299
- equal ( focusedItem . attr ( "id" ) , wrappers . eq ( element [ 0 ] . selectedIndex ) . attr ( "id" ) ,
305
+ assert . equal ( focusedItem . length , 1 , "only one item has ui-state-focus class" ) ;
306
+ assert . equal ( focusedItem . attr ( "id" ) , wrappers . eq ( element [ 0 ] . selectedIndex ) . attr ( "id" ) ,
300
307
"selected item has ui-state-focus class" ) ;
301
308
}
302
309
} ) ;
303
310
304
- asyncTest ( "empty option - " + settings . type , function ( assert ) {
305
- expect ( 7 ) ;
311
+ QUnit . test ( "empty option - " + settings . type , function ( assert ) {
312
+ var ready = assert . async ( ) ;
313
+ assert . expect ( 7 ) ;
306
314
307
315
var button , menu , wrappers , wrapper ,
308
316
element = $ ( settings . selector ) ;
@@ -319,22 +327,23 @@ $.each( [
319
327
320
328
button . trigger ( "click" ) ;
321
329
322
- equal ( wrappers . length , element . find ( "option" ) . length ,
330
+ assert . equal ( wrappers . length , element . find ( "option" ) . length ,
323
331
"correct amount of list elements" ) ;
324
- ok ( wrapper . outerHeight ( ) > 10 , "empty item seems to have reasonable height" ) ;
325
- ok ( wrapper . attr ( "id" ) , "empty item has id attribute" ) ;
332
+ assert . ok ( wrapper . outerHeight ( ) > 10 , "empty item seems to have reasonable height" ) ;
333
+ assert . ok ( wrapper . attr ( "id" ) , "empty item has id attribute" ) ;
326
334
assert . hasClasses ( wrapper . parent ( ) , "ui-menu-item" ) ;
327
335
assert . lacksClasses ( wrapper , "ui-menu-divider" ) ;
328
- equal ( wrapper . attr ( "tabindex" ) , - 1 , "empty item has tabindex" ) ;
329
- equal ( wrapper . attr ( "role" ) , "option" , "empty item has role option" ) ;
336
+ assert . equal ( wrapper . attr ( "tabindex" ) , - 1 , "empty item has tabindex" ) ;
337
+ assert . equal ( wrapper . attr ( "role" ) , "option" , "empty item has role option" ) ;
330
338
331
- start ( ) ;
339
+ ready ( ) ;
332
340
} ) ;
333
341
} ) ;
334
342
} ) ;
335
343
336
- asyncTest ( "Selectmenu should reset when its parent form resets" , function ( ) {
337
- expect ( 2 ) ;
344
+ QUnit . test ( "Selectmenu should reset when its parent form resets" , function ( assert ) {
345
+ var ready = assert . async ( ) ;
346
+ assert . expect ( 2 ) ;
338
347
339
348
var element = $ ( "#speed" ) . selectmenu ( ) ,
340
349
widget = element . selectmenu ( "widget" ) ,
@@ -343,11 +352,11 @@ $.each( [
343
352
344
353
element . val ( "Slower" ) ;
345
354
element . selectmenu ( "refresh" ) ;
346
- equal ( $ . trim ( widget . text ( ) ) , "Slower" ) ;
355
+ assert . equal ( $ . trim ( widget . text ( ) ) , "Slower" ) ;
347
356
form [ 0 ] . reset ( ) ;
348
357
setTimeout ( function ( ) {
349
- equal ( $ . trim ( widget . text ( ) ) , initialValue ) ;
350
- start ( ) ;
358
+ assert . equal ( $ . trim ( widget . text ( ) ) , initialValue ) ;
359
+ ready ( ) ;
351
360
} ) ;
352
361
} ) ;
353
362
0 commit comments