@@ -236,6 +236,93 @@ describe('MdAutocomplete', () => {
236
236
237
237
} ) ;
238
238
239
+ describe ( 'aria' , ( ) => {
240
+ let fixture : ComponentFixture < SimpleAutocomplete > ;
241
+ let input : HTMLInputElement ;
242
+
243
+ beforeEach ( ( ) => {
244
+ fixture = TestBed . createComponent ( SimpleAutocomplete ) ;
245
+ fixture . detectChanges ( ) ;
246
+
247
+ input = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
248
+ } ) ;
249
+
250
+ it ( 'should set role of input to combobox' , ( ) => {
251
+ expect ( input . getAttribute ( 'role' ) )
252
+ . toEqual ( 'combobox' , 'Expected role of input to be combobox.' ) ;
253
+ } ) ;
254
+
255
+ it ( 'should set role of autocomplete panel to listbox' , ( ) => {
256
+ const panel = fixture . debugElement . query ( By . css ( '.md-autocomplete-panel' ) ) . nativeElement ;
257
+
258
+ expect ( panel . getAttribute ( 'role' ) )
259
+ . toEqual ( 'listbox' , 'Expected role of the panel to be listbox.' ) ;
260
+ } ) ;
261
+
262
+ it ( 'should set aria-autocomplete to list' , ( ) => {
263
+ expect ( input . getAttribute ( 'aria-autocomplete' ) )
264
+ . toEqual ( 'list' , 'Expected aria-autocomplete attribute to equal list.' ) ;
265
+ } ) ;
266
+
267
+ it ( 'should set aria-multiline to false' , ( ) => {
268
+ expect ( input . getAttribute ( 'aria-multiline' ) )
269
+ . toEqual ( 'false' , 'Expected aria-multiline attribute to equal false.' ) ;
270
+ } ) ;
271
+
272
+ it ( 'should set aria-activedescendant based on the active option' , ( ) => {
273
+ fixture . componentInstance . trigger . openPanel ( ) ;
274
+ fixture . detectChanges ( ) ;
275
+
276
+ expect ( input . hasAttribute ( 'aria-activedescendant' ) )
277
+ . toBe ( false , 'Expected aria-activedescendant to be absent if no active item.' ) ;
278
+
279
+ const DOWN_ARROW_EVENT = new FakeKeyboardEvent ( DOWN_ARROW ) as KeyboardEvent ;
280
+ fixture . componentInstance . trigger . _handleKeydown ( DOWN_ARROW_EVENT ) ;
281
+ fixture . detectChanges ( ) ;
282
+
283
+ expect ( input . getAttribute ( 'aria-activedescendant' ) )
284
+ . toEqual ( fixture . componentInstance . options . first . id ,
285
+ 'Expected aria-activedescendant to match the active item after 1 down arrow.' ) ;
286
+
287
+ fixture . componentInstance . trigger . _handleKeydown ( DOWN_ARROW_EVENT ) ;
288
+ fixture . detectChanges ( ) ;
289
+
290
+ expect ( input . getAttribute ( 'aria-activedescendant' ) )
291
+ . toEqual ( fixture . componentInstance . options . toArray ( ) [ 1 ] . id ,
292
+ 'Expected aria-activedescendant to match the active item after 2 down arrows.' ) ;
293
+ } ) ;
294
+
295
+ it ( 'should set aria-expanded based on whether the panel is open' , async ( ( ) => {
296
+ expect ( input . getAttribute ( 'aria-expanded' ) )
297
+ . toBe ( 'false' , 'Expected aria-expanded to be false while panel is closed.' ) ;
298
+
299
+ fixture . componentInstance . trigger . openPanel ( ) ;
300
+ fixture . detectChanges ( ) ;
301
+
302
+ expect ( input . getAttribute ( 'aria-expanded' ) )
303
+ . toBe ( 'true' , 'Expected aria-expanded to be true while panel is open.' ) ;
304
+
305
+ fixture . componentInstance . trigger . closePanel ( ) ;
306
+ fixture . detectChanges ( ) ;
307
+
308
+ fixture . whenStable ( ) . then ( ( ) => {
309
+ expect ( input . getAttribute ( 'aria-expanded' ) )
310
+ . toBe ( 'false' , 'Expected aria-expanded to be false when panel closes again.' ) ;
311
+ } ) ;
312
+ } ) ) ;
313
+
314
+ it ( 'should set aria-owns based on the attached autocomplete' , ( ) => {
315
+ fixture . componentInstance . trigger . openPanel ( ) ;
316
+ fixture . detectChanges ( ) ;
317
+
318
+ const panel = fixture . debugElement . query ( By . css ( '.md-autocomplete-panel' ) ) . nativeElement ;
319
+
320
+ expect ( input . getAttribute ( 'aria-owns' ) )
321
+ . toEqual ( panel . getAttribute ( 'id' ) , 'Expected aria-owns to match attached autocomplete.' ) ;
322
+ } ) ;
323
+
324
+ } ) ;
325
+
239
326
} ) ;
240
327
241
328
@Component ( {
0 commit comments