11define ( [
2+ "qunit" ,
23 "jquery" ,
34 "ui/widgets/selectmenu"
4- ] , function ( $ ) {
5+ ] , function ( QUnit , $ ) {
56
6- module ( "selectmenu: core" ) ;
7+ QUnit . module ( "selectmenu: core" ) ;
78
8- test ( "markup structure" , function ( assert ) {
9- expect ( 7 ) ;
9+ QUnit . test ( "markup structure" , function ( assert ) {
10+ assert . expect ( 7 ) ;
1011
1112 var element = $ ( "#files" ) . selectmenu ( ) ,
1213 button = element . selectmenu ( "widget" ) ,
@@ -24,7 +25,8 @@ test( "markup structure", function( assert ) {
2425 assert . strictEqual ( icon [ 0 ] , button . children ( ) [ 0 ] , "Icon is first child of button" ) ;
2526} ) ;
2627
27- asyncTest ( "accessibility" , function ( ) {
28+ QUnit . test ( "accessibility" , function ( assert ) {
29+ var ready = assert . async ( ) ;
2830 var wrappers , button , menu ,
2931 element = $ ( "#speed" ) . attr ( "title" , "A demo title" ) ;
3032
@@ -39,43 +41,43 @@ asyncTest( "accessibility", function() {
3941 button . simulate ( "focus" ) ;
4042 wrappers = menu . find ( "li.ui-menu-item .ui-menu-item-wrapper" ) ;
4143
42- expect ( 13 + wrappers . length * 3 ) ;
44+ assert . expect ( 13 + wrappers . length * 3 ) ;
4345
4446 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 (
5153 button . attr ( "aria-labelledby" ) ,
5254 wrappers . eq ( element [ 0 ] . selectedIndex ) . attr ( "id" ) ,
5355 "button link aria-labelledby"
5456 ) ;
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 (
6365 menu . attr ( "aria-activedescendant" ) ,
6466 wrappers . eq ( element [ 0 ] . selectedIndex ) . attr ( "id" ) ,
6567 "menu aria-activedescendant"
6668 ) ;
6769 $ . each ( wrappers , function ( index ) {
6870 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" ) ;
7274 } ) ;
73- start ( ) ;
75+ ready ( ) ;
7476 } ) ;
7577} ) ;
7678
77- test ( "_renderButtonItem()" , function ( ) {
78- expect ( 2 ) ;
79+ QUnit . test ( "_renderButtonItem()" , function ( assert ) {
80+ assert . expect ( 2 ) ;
7981
8082 var option ,
8183 element = $ ( "#speed" ) . selectmenu ( ) ,
@@ -92,7 +94,7 @@ test( "_renderButtonItem()", function() {
9294
9395 element . selectmenu ( "refresh" ) ;
9496 option = element . find ( "option:selected" ) ;
95- equal (
97+ assert . equal (
9698 $ . trim ( button . text ( ) ) ,
9799 option . text ( ) + element [ 0 ] . selectedIndex ,
98100 "refresh: button item text"
@@ -101,7 +103,7 @@ test( "_renderButtonItem()", function() {
101103 button . trigger ( "click" ) ;
102104 menu . find ( "li" ) . last ( ) . simulate ( "mouseover" ) . trigger ( "click" ) ;
103105 option = element . find ( "option" ) . last ( ) ;
104- equal (
106+ assert . equal (
105107 $ . trim ( button . text ( ) ) ,
106108 option . text ( ) + element [ 0 ] . selectedIndex ,
107109 "click: button item text"
@@ -118,8 +120,9 @@ $.each( [
118120 selector : "#files"
119121 }
120122] , 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 ) ;
123126
124127 var wrappers ,
125128 element = $ ( settings . selector ) . selectmenu ( ) ,
@@ -135,28 +138,29 @@ $.each( [
135138 wrappers = menu . find ( "li.ui-menu-item .ui-menu-item-wrapper" ) ;
136139
137140 button . simulate ( "keydown" , { keyCode : $ . ui . keyCode . DOWN } ) ;
138- equal (
141+ assert . equal (
139142 menu . attr ( "aria-activedescendant" ) ,
140143 wrappers . eq ( element [ 0 ] . selectedIndex ) . attr ( "id" ) ,
141144 "menu aria-activedescendant"
142145 ) ;
143- equal (
146+ assert . equal (
144147 button . attr ( "aria-activedescendant" ) ,
145148 wrappers . eq ( element [ 0 ] . selectedIndex ) . attr ( "id" ) ,
146149 "button aria-activedescendant"
147150 ) ;
148- equal (
151+ assert . equal (
149152 element . find ( "option:selected" ) . val ( ) ,
150153 selected . val ( ) ,
151154 "original select state"
152155 ) ;
153- equal ( $ . trim ( button . text ( ) ) , selected . text ( ) , "button text" ) ;
154- start ( ) ;
156+ assert . equal ( $ . trim ( button . text ( ) ) , selected . text ( ) , "button text" ) ;
157+ ready ( ) ;
155158 } ) ;
156159 } ) ;
157160
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 ) ;
160164
161165 var wrappers ,
162166 element = $ ( settings . selector ) . selectmenu ( ) ,
@@ -170,29 +174,30 @@ $.each( [
170174
171175 button . trigger ( "click" ) ;
172176 menu . find ( "li" ) . last ( ) . simulate ( "mouseover" ) . trigger ( "click" ) ;
173- equal (
177+ assert . equal (
174178 menu . attr ( "aria-activedescendant" ) ,
175179 wrappers . eq ( element [ 0 ] . selectedIndex ) . attr ( "id" ) ,
176180 "menu aria-activedescendant"
177181 ) ;
178- equal (
182+ assert . equal (
179183 button . attr ( "aria-activedescendant" ) ,
180184 wrappers . eq ( element [ 0 ] . selectedIndex ) . attr ( "id" ) ,
181185 "button aria-activedescendant"
182186 ) ;
183- equal (
187+ assert . equal (
184188 element . find ( "option:selected" ) . val ( ) ,
185189 selected . val ( ) ,
186190 "original select state"
187191 ) ;
188- equal ( $ . trim ( button . text ( ) ) , selected . text ( ) , "button text" ) ;
189- start ( ) ;
192+ assert . equal ( $ . trim ( button . text ( ) ) , selected . text ( ) , "button text" ) ;
193+ ready ( ) ;
190194 } , 1 ) ;
191195 } ) ;
192196
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 ) ;
196201
197202 var wrappers ,
198203 element = $ ( settings . selector ) . selectmenu ( ) ,
@@ -220,20 +225,21 @@ $.each( [
220225 setTimeout ( function ( ) {
221226 button . simulate ( "keydown" , { keyCode : $ . ui . keyCode . DOWN } ) ;
222227
223- equal ( menu . attr ( "aria-activedescendant" ) , wrappers . eq ( 1 ) . attr ( "id" ) ,
228+ assert . equal ( menu . attr ( "aria-activedescendant" ) , wrappers . eq ( 1 ) . attr ( "id" ) ,
224229 "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" ) ,
226231 "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 ( ) ,
228233 "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 ( ) ;
231236 } ) ;
232237 } ) ;
233238 } ) ;
234239
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 ) ;
237243
238244 var wrappers ,
239245 element = $ ( settings . selector ) . selectmenu ( ) ,
@@ -246,21 +252,22 @@ $.each( [
246252
247253 button . trigger ( "click" ) ;
248254 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" ) ;
250256 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" ) ;
252258
253259 button . trigger ( "click" ) ;
254260 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" ) ;
256262 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 ( ) ;
259265 } ) ;
260266 } ) ;
261267
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 ) ;
264271
265272 var wrappers , focusedItem ,
266273 element = $ ( settings . selector ) . selectmenu ( ) ,
@@ -288,21 +295,22 @@ $.each( [
288295 button . trigger ( "click" ) ;
289296 setTimeout ( function ( ) {
290297 checkItemClasses ( ) ;
291- start ( ) ;
298+ ready ( ) ;
292299 } ) ;
293300 } ) ;
294301 } ) ;
295302
296303 function checkItemClasses ( ) {
297304 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" ) ,
300307 "selected item has ui-state-focus class" ) ;
301308 }
302309 } ) ;
303310
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 ) ;
306314
307315 var button , menu , wrappers , wrapper ,
308316 element = $ ( settings . selector ) ;
@@ -319,22 +327,23 @@ $.each( [
319327
320328 button . trigger ( "click" ) ;
321329
322- equal ( wrappers . length , element . find ( "option" ) . length ,
330+ assert . equal ( wrappers . length , element . find ( "option" ) . length ,
323331 "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" ) ;
326334 assert . hasClasses ( wrapper . parent ( ) , "ui-menu-item" ) ;
327335 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" ) ;
330338
331- start ( ) ;
339+ ready ( ) ;
332340 } ) ;
333341 } ) ;
334342} ) ;
335343
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 ) ;
338347
339348 var element = $ ( "#speed" ) . selectmenu ( ) ,
340349 widget = element . selectmenu ( "widget" ) ,
@@ -343,11 +352,11 @@ $.each( [
343352
344353 element . val ( "Slower" ) ;
345354 element . selectmenu ( "refresh" ) ;
346- equal ( $ . trim ( widget . text ( ) ) , "Slower" ) ;
355+ assert . equal ( $ . trim ( widget . text ( ) ) , "Slower" ) ;
347356 form [ 0 ] . reset ( ) ;
348357 setTimeout ( function ( ) {
349- equal ( $ . trim ( widget . text ( ) ) , initialValue ) ;
350- start ( ) ;
358+ assert . equal ( $ . trim ( widget . text ( ) ) , initialValue ) ;
359+ ready ( ) ;
351360 } ) ;
352361 } ) ;
353362
0 commit comments