@@ -391,6 +391,93 @@ describe('MdAutocomplete', () => {
391391
392392 } ) ;
393393
394+ describe ( 'aria' , ( ) => {
395+ let fixture : ComponentFixture < SimpleAutocomplete > ;
396+ let input : HTMLInputElement ;
397+
398+ beforeEach ( ( ) => {
399+ fixture = TestBed . createComponent ( SimpleAutocomplete ) ;
400+ fixture . detectChanges ( ) ;
401+
402+ input = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
403+ } ) ;
404+
405+ it ( 'should set role of input to combobox' , ( ) => {
406+ expect ( input . getAttribute ( 'role' ) )
407+ . toEqual ( 'combobox' , 'Expected role of input to be combobox.' ) ;
408+ } ) ;
409+
410+ it ( 'should set role of autocomplete panel to listbox' , ( ) => {
411+ const panel = fixture . debugElement . query ( By . css ( '.md-autocomplete-panel' ) ) . nativeElement ;
412+
413+ expect ( panel . getAttribute ( 'role' ) )
414+ . toEqual ( 'listbox' , 'Expected role of the panel to be listbox.' ) ;
415+ } ) ;
416+
417+ it ( 'should set aria-autocomplete to list' , ( ) => {
418+ expect ( input . getAttribute ( 'aria-autocomplete' ) )
419+ . toEqual ( 'list' , 'Expected aria-autocomplete attribute to equal list.' ) ;
420+ } ) ;
421+
422+ it ( 'should set aria-multiline to false' , ( ) => {
423+ expect ( input . getAttribute ( 'aria-multiline' ) )
424+ . toEqual ( 'false' , 'Expected aria-multiline attribute to equal false.' ) ;
425+ } ) ;
426+
427+ it ( 'should set aria-activedescendant based on the active option' , ( ) => {
428+ fixture . componentInstance . trigger . openPanel ( ) ;
429+ fixture . detectChanges ( ) ;
430+
431+ expect ( input . hasAttribute ( 'aria-activedescendant' ) )
432+ . toBe ( false , 'Expected aria-activedescendant to be absent if no active item.' ) ;
433+
434+ const DOWN_ARROW_EVENT = new FakeKeyboardEvent ( DOWN_ARROW ) as KeyboardEvent ;
435+ fixture . componentInstance . trigger . _handleKeydown ( DOWN_ARROW_EVENT ) ;
436+ fixture . detectChanges ( ) ;
437+
438+ expect ( input . getAttribute ( 'aria-activedescendant' ) )
439+ . toEqual ( fixture . componentInstance . options . first . id ,
440+ 'Expected aria-activedescendant to match the active item after 1 down arrow.' ) ;
441+
442+ fixture . componentInstance . trigger . _handleKeydown ( DOWN_ARROW_EVENT ) ;
443+ fixture . detectChanges ( ) ;
444+
445+ expect ( input . getAttribute ( 'aria-activedescendant' ) )
446+ . toEqual ( fixture . componentInstance . options . toArray ( ) [ 1 ] . id ,
447+ 'Expected aria-activedescendant to match the active item after 2 down arrows.' ) ;
448+ } ) ;
449+
450+ it ( 'should set aria-expanded based on whether the panel is open' , async ( ( ) => {
451+ expect ( input . getAttribute ( 'aria-expanded' ) )
452+ . toBe ( 'false' , 'Expected aria-expanded to be false while panel is closed.' ) ;
453+
454+ fixture . componentInstance . trigger . openPanel ( ) ;
455+ fixture . detectChanges ( ) ;
456+
457+ expect ( input . getAttribute ( 'aria-expanded' ) )
458+ . toBe ( 'true' , 'Expected aria-expanded to be true while panel is open.' ) ;
459+
460+ fixture . componentInstance . trigger . closePanel ( ) ;
461+ fixture . detectChanges ( ) ;
462+
463+ fixture . whenStable ( ) . then ( ( ) => {
464+ expect ( input . getAttribute ( 'aria-expanded' ) )
465+ . toBe ( 'false' , 'Expected aria-expanded to be false when panel closes again.' ) ;
466+ } ) ;
467+ } ) ) ;
468+
469+ it ( 'should set aria-owns based on the attached autocomplete' , ( ) => {
470+ fixture . componentInstance . trigger . openPanel ( ) ;
471+ fixture . detectChanges ( ) ;
472+
473+ const panel = fixture . debugElement . query ( By . css ( '.md-autocomplete-panel' ) ) . nativeElement ;
474+
475+ expect ( input . getAttribute ( 'aria-owns' ) )
476+ . toEqual ( panel . getAttribute ( 'id' ) , 'Expected aria-owns to match attached autocomplete.' ) ;
477+ } ) ;
478+
479+ } ) ;
480+
394481} ) ;
395482
396483@Component ( {
0 commit comments