@@ -61,35 +61,39 @@ describe('MdAutocomplete', () => {
61
61
input = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
62
62
} ) ;
63
63
64
- it ( 'should open the panel when the input is focused' , ( ) => {
64
+ it ( 'should open the panel when the input is focused' , async ( ( ) => {
65
65
expect ( fixture . componentInstance . trigger . panelOpen )
66
66
. toBe ( false , `Expected panel state to start out closed.` ) ;
67
67
68
68
dispatchFakeEvent ( input , 'focus' ) ;
69
- fixture . detectChanges ( ) ;
69
+ fixture . whenStable ( ) . then ( ( ) => {
70
+ fixture . detectChanges ( ) ;
70
71
71
- expect ( fixture . componentInstance . trigger . panelOpen )
72
- . toBe ( true , `Expected panel state to read open when input is focused.` ) ;
73
- expect ( overlayContainerElement . textContent )
74
- . toContain ( 'Alabama' , `Expected panel to display when input is focused.` ) ;
75
- expect ( overlayContainerElement . textContent )
76
- . toContain ( 'California' , `Expected panel to display when input is focused.` ) ;
77
- } ) ;
72
+ expect ( fixture . componentInstance . trigger . panelOpen )
73
+ . toBe ( true , `Expected panel state to read open when input is focused.` ) ;
74
+ expect ( overlayContainerElement . textContent )
75
+ . toContain ( 'Alabama' , `Expected panel to display when input is focused.` ) ;
76
+ expect ( overlayContainerElement . textContent )
77
+ . toContain ( 'California' , `Expected panel to display when input is focused.` ) ;
78
+ } ) ;
79
+ } ) ) ;
78
80
79
- it ( 'should open the panel programmatically' , ( ) => {
81
+ it ( 'should open the panel programmatically' , async ( ( ) => {
80
82
expect ( fixture . componentInstance . trigger . panelOpen )
81
83
. toBe ( false , `Expected panel state to start out closed.` ) ;
82
84
83
85
fixture . componentInstance . trigger . openPanel ( ) ;
84
- fixture . detectChanges ( ) ;
86
+ fixture . whenStable ( ) . then ( ( ) => {
87
+ fixture . detectChanges ( ) ;
85
88
86
- expect ( fixture . componentInstance . trigger . panelOpen )
87
- . toBe ( true , `Expected panel state to read open when opened programmatically.` ) ;
88
- expect ( overlayContainerElement . textContent )
89
- . toContain ( 'Alabama' , `Expected panel to display when opened programmatically.` ) ;
90
- expect ( overlayContainerElement . textContent )
91
- . toContain ( 'California' , `Expected panel to display when opened programmatically.` ) ;
92
- } ) ;
89
+ expect ( fixture . componentInstance . trigger . panelOpen )
90
+ . toBe ( true , `Expected panel state to read open when opened programmatically.` ) ;
91
+ expect ( overlayContainerElement . textContent )
92
+ . toContain ( 'Alabama' , `Expected panel to display when opened programmatically.` ) ;
93
+ expect ( overlayContainerElement . textContent )
94
+ . toContain ( 'California' , `Expected panel to display when opened programmatically.` ) ;
95
+ } ) ;
96
+ } ) ) ;
93
97
94
98
it ( 'should close the panel when blurred' , async ( ( ) => {
95
99
dispatchFakeEvent ( input , 'focus' ) ;
@@ -185,8 +189,6 @@ describe('MdAutocomplete', () => {
185
189
fixture . whenStable ( ) . then ( ( ) => {
186
190
fixture . detectChanges ( ) ;
187
191
188
- expect ( fixture . componentInstance . trigger . panelOpen )
189
- . toBe ( true , `Expected panel to stay open when options list is empty.` ) ;
190
192
expect ( panel . classList )
191
193
. toContain ( 'mat-autocomplete-hidden' , `Expected panel to hide itself when empty.` ) ;
192
194
} ) ;
@@ -748,20 +750,43 @@ describe('MdAutocomplete', () => {
748
750
. toBe ( 'false' , 'Expected aria-expanded to be false while panel is closed.' ) ;
749
751
750
752
fixture . componentInstance . trigger . openPanel ( ) ;
751
- fixture . detectChanges ( ) ;
753
+ fixture . whenStable ( ) . then ( ( ) => {
754
+ fixture . detectChanges ( ) ;
752
755
753
- expect ( input . getAttribute ( 'aria-expanded' ) )
754
- . toBe ( 'true' , 'Expected aria-expanded to be true while panel is open.' ) ;
756
+ expect ( input . getAttribute ( 'aria-expanded' ) )
757
+ . toBe ( 'true' , 'Expected aria-expanded to be true while panel is open.' ) ;
755
758
756
- fixture . componentInstance . trigger . closePanel ( ) ;
757
- fixture . detectChanges ( ) ;
759
+ fixture . componentInstance . trigger . closePanel ( ) ;
760
+ fixture . detectChanges ( ) ;
758
761
759
- fixture . whenStable ( ) . then ( ( ) => {
760
- expect ( input . getAttribute ( 'aria-expanded' ) )
761
- . toBe ( 'false' , 'Expected aria-expanded to be false when panel closes again.' ) ;
762
+ fixture . whenStable ( ) . then ( ( ) => {
763
+ expect ( input . getAttribute ( 'aria-expanded' ) )
764
+ . toBe ( 'false' , 'Expected aria-expanded to be false when panel closes again.' ) ;
765
+ } ) ;
762
766
} ) ;
763
767
} ) ) ;
764
768
769
+ it ( 'should set aria-expanded properly when the panel is hidden' , async ( ( ) => {
770
+ fixture . componentInstance . trigger . openPanel ( ) ;
771
+
772
+ fixture . whenStable ( ) . then ( ( ) => {
773
+ fixture . detectChanges ( ) ;
774
+ expect ( input . getAttribute ( 'aria-expanded' ) )
775
+ . toBe ( 'true' , 'Expected aria-expanded to be true while panel is open.' ) ;
776
+
777
+ typeInElement ( 'zz' , input ) ;
778
+ fixture . whenStable ( ) . then ( ( ) => {
779
+ fixture . detectChanges ( ) ;
780
+
781
+ fixture . whenStable ( ) . then ( ( ) => {
782
+ fixture . detectChanges ( ) ;
783
+ expect ( input . getAttribute ( 'aria-expanded' ) )
784
+ . toBe ( 'false' , 'Expected aria-expanded to be false when panel hides itself.' ) ;
785
+ } ) ;
786
+ } ) ;
787
+ } ) ;
788
+ } ) ) ;
789
+
765
790
it ( 'should set aria-owns based on the attached autocomplete' , ( ) => {
766
791
fixture . componentInstance . trigger . openPanel ( ) ;
767
792
fixture . detectChanges ( ) ;
@@ -863,21 +888,24 @@ describe('MdAutocomplete', () => {
863
888
} ) . not . toThrowError ( ) ;
864
889
} ) ;
865
890
866
- it ( 'should work when input is wrapped in ngIf' , ( ) => {
891
+ it ( 'should work when input is wrapped in ngIf' , async ( ( ) => {
867
892
const fixture = TestBed . createComponent ( NgIfAutocomplete ) ;
868
893
fixture . detectChanges ( ) ;
869
894
870
895
const input = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
871
896
dispatchFakeEvent ( input , 'focus' ) ;
872
- fixture . detectChanges ( ) ;
873
897
874
- expect ( fixture . componentInstance . trigger . panelOpen )
875
- . toBe ( true , `Expected panel state to read open when input is focused.` ) ;
876
- expect ( overlayContainerElement . textContent )
877
- . toContain ( 'One' , `Expected panel to display when input is focused.` ) ;
878
- expect ( overlayContainerElement . textContent )
879
- . toContain ( 'Two' , `Expected panel to display when input is focused.` ) ;
880
- } ) ;
898
+ fixture . whenStable ( ) . then ( ( ) => {
899
+ fixture . detectChanges ( ) ;
900
+
901
+ expect ( fixture . componentInstance . trigger . panelOpen )
902
+ . toBe ( true , `Expected panel state to read open when input is focused.` ) ;
903
+ expect ( overlayContainerElement . textContent )
904
+ . toContain ( 'One' , `Expected panel to display when input is focused.` ) ;
905
+ expect ( overlayContainerElement . textContent )
906
+ . toContain ( 'Two' , `Expected panel to display when input is focused.` ) ;
907
+ } ) ;
908
+ } ) ) ;
881
909
882
910
} ) ;
883
911
} ) ;
0 commit comments