@@ -14,11 +14,11 @@ asyncTest( "accessibility", function() {
14
14
expect ( 12 + links . length * 2 ) ;
15
15
16
16
setTimeout ( function ( ) {
17
- equal ( button . attr ( "role" ) , "combobox" , "button link role" ) ;
18
- equal ( button . attr ( "aria-haspopup" ) , "true" , "button link aria-haspopup" ) ;
19
- equal ( button . attr ( "aria-expanded" ) , "false" , "button link aria-expanded" ) ;
20
- equal ( button . attr ( "aria-autocomplete" ) , "list" , "button link aria-autocomplete" ) ;
21
- equal ( button . attr ( "aria-owns" ) , menu . attr ( "id" ) , "button link aria-owns" ) ;
17
+ equal ( button . attr ( "role" ) , "combobox" , "button role" ) ;
18
+ equal ( button . attr ( "aria-haspopup" ) , "true" , "button aria-haspopup" ) ;
19
+ equal ( button . attr ( "aria-expanded" ) , "false" , "button aria-expanded" ) ;
20
+ equal ( button . attr ( "aria-autocomplete" ) , "list" , "button aria-autocomplete" ) ;
21
+ equal ( button . attr ( "aria-owns" ) , menu . attr ( "id" ) , "button aria-owns" ) ;
22
22
equal (
23
23
button . attr ( "aria-labelledby" ) ,
24
24
links . eq ( element [ 0 ] . selectedIndex ) . attr ( "id" ) ,
@@ -35,9 +35,10 @@ asyncTest( "accessibility", function() {
35
35
links . eq ( element [ 0 ] . selectedIndex ) . attr ( "id" ) ,
36
36
"menu aria-activedescendant"
37
37
) ;
38
- $ . each ( links , function ( index ) {
39
- equal ( $ ( this ) . attr ( "role" ) , "option" , "menu link #" + index + " role" ) ;
40
- equal ( $ ( this ) . attr ( "tabindex" ) , - 1 , "menu link #" + index + " tabindex" ) ;
38
+ $ . each ( links , function ( index ) {
39
+ var link = $ ( this ) ;
40
+ equal ( link . attr ( "role" ) , "option" , "menu link #" + index + " role" ) ;
41
+ equal ( link . attr ( "tabindex" ) , - 1 , "menu link #" + index + " tabindex" ) ;
41
42
} ) ;
42
43
start ( ) ;
43
44
} ) ;
@@ -54,18 +55,21 @@ $.each([
54
55
selector : "#files"
55
56
}
56
57
] , function ( i , settings ) {
57
- asyncTest ( "state synchronization - after keydown on button - " + settings . type , function ( ) {
58
+ asyncTest ( "state synchronization - after keydown on button - " + settings . type , function ( ) {
58
59
expect ( 4 ) ;
59
60
60
61
var links ,
61
62
element = $ ( settings . selector ) . selectmenu ( ) ,
62
63
button = element . selectmenu ( "widget" ) ,
63
64
menu = element . selectmenu ( "menuWidget" ) ,
64
- selected = element . find ( "option:selected" ) ;
65
+
66
+ // Get the option after the currently selected option because
67
+ // we simulate pressing DOWN.
68
+ selected = element . find ( "option:selected" ) . next ( ) ;
65
69
66
70
button . simulate ( "focus" ) ;
67
71
setTimeout ( function ( ) {
68
- links = menu . find ( "li.ui-menu-item" ) ;
72
+ links = menu . find ( "li.ui-menu-item" ) ;
69
73
70
74
button . simulate ( "keydown" , { keyCode : $ . ui . keyCode . DOWN } ) ;
71
75
equal (
@@ -80,25 +84,26 @@ $.each([
80
84
) ;
81
85
equal (
82
86
element . find ( "option:selected" ) . val ( ) ,
83
- selected . next ( "option" ) . val ( ) ,
87
+ selected . val ( ) ,
84
88
"original select state"
85
89
) ;
86
- equal ( button . text ( ) , selected . next ( "option" ) . text ( ) , "button text" ) ;
90
+ equal ( button . text ( ) , selected . text ( ) , "button text" ) ;
87
91
start ( ) ;
88
- } , 1 ) ;
92
+ } ) ;
89
93
} ) ;
90
94
91
- asyncTest ( "state synchronization - after click on item - " + settings . type , function ( ) {
95
+ asyncTest ( "state synchronization - after click on item - " + settings . type , function ( ) {
92
96
expect ( 4 ) ;
93
97
94
98
var links ,
95
99
element = $ ( settings . selector ) . selectmenu ( ) ,
96
100
button = element . selectmenu ( "widget" ) ,
97
- menu = element . selectmenu ( "menuWidget" ) ;
101
+ menu = element . selectmenu ( "menuWidget" ) ,
102
+ selected = element . find ( "option" ) . last ( ) ;
98
103
99
104
button . simulate ( "focus" ) ;
100
105
setTimeout ( function ( ) {
101
- links = menu . find ( "li.ui-menu-item" ) ;
106
+ links = menu . find ( "li.ui-menu-item" ) ;
102
107
103
108
button . trigger ( "click" ) ;
104
109
menu . find ( "li" ) . last ( ) . simulate ( "mouseover" ) . trigger ( "click" ) ;
@@ -114,15 +119,16 @@ $.each([
114
119
) ;
115
120
equal (
116
121
element . find ( "option:selected" ) . val ( ) ,
117
- element . find ( "option" ) . last ( ) . val ( ) ,
122
+ selected . val ( ) ,
118
123
"original select state"
119
124
) ;
120
- equal ( button . text ( ) , element . find ( "option" ) . last ( ) . text ( ) , "button text" ) ;
125
+ equal ( button . text ( ) , selected . text ( ) , "button text" ) ;
121
126
start ( ) ;
122
127
} , 1 ) ;
123
128
} ) ;
124
129
125
- asyncTest ( "state synchronization - after focus item and keydown on button - " + settings . type , function ( ) {
130
+ asyncTest ( "state synchronization - " +
131
+ "after focus item and keydown on button - " + settings . type , function ( ) {
126
132
expect ( 4 ) ;
127
133
128
134
var links ,
@@ -131,70 +137,74 @@ $.each([
131
137
menu = element . selectmenu ( "menuWidget" ) ,
132
138
options = element . find ( "option" ) ;
133
139
134
- // init menu
140
+ // Init menu
135
141
button . simulate ( "focus" ) ;
136
142
137
143
setTimeout ( function ( ) {
138
144
links = menu . find ( "li.ui-menu-item" ) ;
139
- // open menu and click first item
145
+
146
+ // Open menu and click first item
140
147
button . trigger ( "click" ) ;
141
148
links . first ( ) . simulate ( "mouseover" ) . trigger ( "click" ) ;
142
- // open menu again and hover item
149
+
150
+ // Open menu again and hover item
143
151
button . trigger ( "click" ) ;
144
152
links . eq ( 3 ) . simulate ( "mouseover" ) ;
145
- // close and use keyboard control on button
153
+
154
+ // Close and use keyboard control on button
146
155
button . simulate ( "keydown" , { keyCode : $ . ui . keyCode . ESCAPE } ) ;
147
156
button . simulate ( "focus" ) ;
148
157
setTimeout ( function ( ) {
149
158
button . simulate ( "keydown" , { keyCode : $ . ui . keyCode . DOWN } ) ;
150
159
151
- equal ( menu . attr ( "aria-activedescendant" ) , links . eq ( 1 ) . attr ( "id" ) , "menu aria-activedescendant" ) ;
152
- equal ( button . attr ( "aria-activedescendant" ) , links . eq ( 1 ) . attr ( "id" ) , "button aria-activedescendant" ) ;
153
- equal ( element . find ( "option:selected" ) . val ( ) , options . eq ( 1 ) . val ( ) , "original select state" ) ;
160
+ equal ( menu . attr ( "aria-activedescendant" ) , links . eq ( 1 ) . attr ( "id" ) ,
161
+ "menu aria-activedescendant" ) ;
162
+ equal ( button . attr ( "aria-activedescendant" ) , links . eq ( 1 ) . attr ( "id" ) ,
163
+ "button aria-activedescendant" ) ;
164
+ equal ( element . find ( "option:selected" ) . val ( ) , options . eq ( 1 ) . val ( ) ,
165
+ "original select state" ) ;
154
166
equal ( button . text ( ) , options . eq ( 1 ) . text ( ) , "button text" ) ;
155
167
start ( ) ;
156
- } , 1 ) ;
157
- } , 1 ) ;
168
+ } ) ;
169
+ } ) ;
158
170
} ) ;
159
171
160
- asyncTest ( "item looping - " + settings . type , function ( ) {
161
- expect ( 2 ) ;
172
+ asyncTest ( "item looping - " + settings . type , function ( ) {
173
+ expect ( 4 ) ;
162
174
163
175
var links ,
164
176
element = $ ( settings . selector ) . selectmenu ( ) ,
165
177
button = element . selectmenu ( "widget" ) ,
166
178
menu = element . selectmenu ( "menuWidget" ) ;
167
179
168
- // init menu
169
180
button . simulate ( "focus" ) ;
170
-
171
181
setTimeout ( function ( ) {
172
182
links = menu . find ( "li.ui-menu-item" ) ;
173
183
174
184
button . trigger ( "click" ) ;
175
185
links . first ( ) . simulate ( "mouseover" ) . trigger ( "click" ) ;
186
+ equal ( element [ 0 ] . selectedIndex , 0 , "First item is selected" ) ;
176
187
button . simulate ( "keydown" , { keyCode : $ . ui . keyCode . UP } ) ;
177
188
equal ( element [ 0 ] . selectedIndex , 0 , "No looping beyond first item" ) ;
178
189
179
190
button . trigger ( "click" ) ;
180
191
links . last ( ) . simulate ( "mouseover" ) . trigger ( "click" ) ;
192
+ equal ( element [ 0 ] . selectedIndex , links . length - 1 , "Last item is selected" ) ;
181
193
button . simulate ( "keydown" , { keyCode : $ . ui . keyCode . DOWN } ) ;
182
- equal ( element [ 0 ] . selectedIndex + 1 , links . length , "No looping behind last item" ) ;
194
+ equal ( element [ 0 ] . selectedIndex , links . length - 1 , "No looping behind last item" ) ;
183
195
start ( ) ;
184
- } , 1 ) ;
196
+ } ) ;
185
197
} ) ;
186
198
187
- asyncTest ( "item focus and active state - " + settings . type , function ( ) {
199
+ asyncTest ( "item focus and active state - " + settings . type , function ( ) {
188
200
expect ( 4 ) ;
189
201
190
202
var items , focusedItem ,
191
203
element = $ ( settings . selector ) . selectmenu ( ) ,
192
204
button = element . selectmenu ( "widget" ) ,
193
205
menu = element . selectmenu ( "menuWidget" ) ;
194
206
195
- // Initialize menu
196
207
button . simulate ( "focus" ) ;
197
-
198
208
setTimeout ( function ( ) {
199
209
items = menu . find ( "li.ui-menu-item" ) ;
200
210
@@ -216,47 +226,48 @@ $.each([
216
226
setTimeout ( function ( ) {
217
227
checkItemClasses ( ) ;
218
228
start ( ) ;
219
- } , 350 ) ;
220
- } , 350 ) ;
221
- } , 1 ) ;
229
+ } ) ;
230
+ } ) ;
231
+ } ) ;
222
232
223
233
function checkItemClasses ( ) {
224
234
focusedItem = menu . find ( "li.ui-state-focus" ) ;
225
235
equal ( focusedItem . length , 1 , "only one item has ui-state-focus class" ) ;
226
- equal ( focusedItem . attr ( "id" ) , items . eq ( element [ 0 ] . selectedIndex ) . attr ( "id" ) , "selected item has ui-state-focus class" ) ;
236
+ equal ( focusedItem . attr ( "id" ) , items . eq ( element [ 0 ] . selectedIndex ) . attr ( "id" ) ,
237
+ "selected item has ui-state-focus class" ) ;
227
238
}
228
239
} ) ;
229
240
230
- asyncTest ( "empty option - " + settings . type , function ( ) {
241
+ asyncTest ( "empty option - " + settings . type , function ( ) {
231
242
expect ( 7 ) ;
232
243
233
- var element = $ ( settings . selector ) ,
234
- button , menu , links , link ;
244
+ var button , menu , links , link ,
245
+ element = $ ( settings . selector ) ;
235
246
236
247
element . find ( "option" ) . first ( ) . text ( "" ) ;
237
248
element . selectmenu ( ) ;
238
249
button = element . selectmenu ( "widget" ) ;
239
250
menu = element . selectmenu ( "menuWidget" ) ;
240
251
241
- // init menu
242
252
button . simulate ( "focus" ) ;
243
-
244
253
setTimeout ( function ( ) {
245
254
links = menu . find ( "li:not(.ui-selectmenu-optgroup)" ) ;
246
255
link = links . first ( ) ;
247
256
248
257
button . trigger ( "click" ) ;
249
258
250
- equal ( links . length , element . find ( "option" ) . length , "correct amount of list elements" ) ;
259
+ equal ( links . length , element . find ( "option" ) . length ,
260
+ "correct amount of list elements" ) ;
251
261
ok ( link . outerHeight ( ) > 10 , "empty item seems to have reasonable height" ) ;
252
262
ok ( link . attr ( "id" ) , "empty item has id attribute" ) ;
253
263
ok ( link . hasClass ( "ui-menu-item" ) , "empty item has ui-menu-item class" ) ;
254
- ok ( ! link . hasClass ( "ui-menu-divider" ) , "empty item has not ui-menu-divider class" ) ;
264
+ ok ( ! link . hasClass ( "ui-menu-divider" ) ,
265
+ "empty item does not have ui-menu-divider class" ) ;
255
266
equal ( link . attr ( "tabindex" ) , - 1 , "empty item has tabindex" ) ;
256
267
equal ( link . attr ( "role" ) , "option" , "empty item has role option" ) ;
257
268
258
269
start ( ) ;
259
- } , 1 ) ;
270
+ } ) ;
260
271
} ) ;
261
272
} ) ;
262
273
0 commit comments