@@ -66,35 +66,39 @@ describe('MdAutocomplete', () => {
66
66
input = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
67
67
} ) ;
68
68
69
- it ( 'should open the panel when the input is focused' , ( ) => {
69
+ it ( 'should open the panel when the input is focused' , async ( ( ) => {
70
70
expect ( fixture . componentInstance . trigger . panelOpen )
71
71
. toBe ( false , `Expected panel state to start out closed.` ) ;
72
72
73
73
dispatchFakeEvent ( input , 'focus' ) ;
74
- fixture . detectChanges ( ) ;
74
+ fixture . whenStable ( ) . then ( ( ) => {
75
+ fixture . detectChanges ( ) ;
75
76
76
- expect ( fixture . componentInstance . trigger . panelOpen )
77
- . toBe ( true , `Expected panel state to read open when input is focused.` ) ;
78
- expect ( overlayContainerElement . textContent )
79
- . toContain ( 'Alabama' , `Expected panel to display when input is focused.` ) ;
80
- expect ( overlayContainerElement . textContent )
81
- . toContain ( 'California' , `Expected panel to display when input is focused.` ) ;
82
- } ) ;
77
+ expect ( fixture . componentInstance . trigger . panelOpen )
78
+ . toBe ( true , `Expected panel state to read open when input is focused.` ) ;
79
+ expect ( overlayContainerElement . textContent )
80
+ . toContain ( 'Alabama' , `Expected panel to display when input is focused.` ) ;
81
+ expect ( overlayContainerElement . textContent )
82
+ . toContain ( 'California' , `Expected panel to display when input is focused.` ) ;
83
+ } ) ;
84
+ } ) ) ;
83
85
84
- it ( 'should open the panel programmatically' , ( ) => {
86
+ it ( 'should open the panel programmatically' , async ( ( ) => {
85
87
expect ( fixture . componentInstance . trigger . panelOpen )
86
88
. toBe ( false , `Expected panel state to start out closed.` ) ;
87
89
88
90
fixture . componentInstance . trigger . openPanel ( ) ;
89
- fixture . detectChanges ( ) ;
91
+ fixture . whenStable ( ) . then ( ( ) => {
92
+ fixture . detectChanges ( ) ;
90
93
91
- expect ( fixture . componentInstance . trigger . panelOpen )
92
- . toBe ( true , `Expected panel state to read open when opened programmatically.` ) ;
93
- expect ( overlayContainerElement . textContent )
94
- . toContain ( 'Alabama' , `Expected panel to display when opened programmatically.` ) ;
95
- expect ( overlayContainerElement . textContent )
96
- . toContain ( 'California' , `Expected panel to display when opened programmatically.` ) ;
97
- } ) ;
94
+ expect ( fixture . componentInstance . trigger . panelOpen )
95
+ . toBe ( true , `Expected panel state to read open when opened programmatically.` ) ;
96
+ expect ( overlayContainerElement . textContent )
97
+ . toContain ( 'Alabama' , `Expected panel to display when opened programmatically.` ) ;
98
+ expect ( overlayContainerElement . textContent )
99
+ . toContain ( 'California' , `Expected panel to display when opened programmatically.` ) ;
100
+ } ) ;
101
+ } ) ) ;
98
102
99
103
it ( 'should close the panel when blurred' , async ( ( ) => {
100
104
dispatchFakeEvent ( input , 'focus' ) ;
@@ -190,8 +194,6 @@ describe('MdAutocomplete', () => {
190
194
fixture . whenStable ( ) . then ( ( ) => {
191
195
fixture . detectChanges ( ) ;
192
196
193
- expect ( fixture . componentInstance . trigger . panelOpen )
194
- . toBe ( true , `Expected panel to stay open when options list is empty.` ) ;
195
197
expect ( panel . classList )
196
198
. toContain ( 'mat-autocomplete-hidden' , `Expected panel to hide itself when empty.` ) ;
197
199
} ) ;
@@ -774,20 +776,43 @@ describe('MdAutocomplete', () => {
774
776
. toBe ( 'false' , 'Expected aria-expanded to be false while panel is closed.' ) ;
775
777
776
778
fixture . componentInstance . trigger . openPanel ( ) ;
777
- fixture . detectChanges ( ) ;
779
+ fixture . whenStable ( ) . then ( ( ) => {
780
+ fixture . detectChanges ( ) ;
778
781
779
- expect ( input . getAttribute ( 'aria-expanded' ) )
780
- . toBe ( 'true' , 'Expected aria-expanded to be true while panel is open.' ) ;
782
+ expect ( input . getAttribute ( 'aria-expanded' ) )
783
+ . toBe ( 'true' , 'Expected aria-expanded to be true while panel is open.' ) ;
781
784
782
- fixture . componentInstance . trigger . closePanel ( ) ;
783
- fixture . detectChanges ( ) ;
785
+ fixture . componentInstance . trigger . closePanel ( ) ;
786
+ fixture . detectChanges ( ) ;
784
787
785
- fixture . whenStable ( ) . then ( ( ) => {
786
- expect ( input . getAttribute ( 'aria-expanded' ) )
787
- . toBe ( 'false' , 'Expected aria-expanded to be false when panel closes again.' ) ;
788
+ fixture . whenStable ( ) . then ( ( ) => {
789
+ expect ( input . getAttribute ( 'aria-expanded' ) )
790
+ . toBe ( 'false' , 'Expected aria-expanded to be false when panel closes again.' ) ;
791
+ } ) ;
788
792
} ) ;
789
793
} ) ) ;
790
794
795
+ it ( 'should set aria-expanded properly when the panel is hidden' , async ( ( ) => {
796
+ fixture . componentInstance . trigger . openPanel ( ) ;
797
+
798
+ fixture . whenStable ( ) . then ( ( ) => {
799
+ fixture . detectChanges ( ) ;
800
+ expect ( input . getAttribute ( 'aria-expanded' ) )
801
+ . toBe ( 'true' , 'Expected aria-expanded to be true while panel is open.' ) ;
802
+
803
+ typeInElement ( 'zz' , input ) ;
804
+ fixture . whenStable ( ) . then ( ( ) => {
805
+ fixture . detectChanges ( ) ;
806
+
807
+ fixture . whenStable ( ) . then ( ( ) => {
808
+ fixture . detectChanges ( ) ;
809
+ expect ( input . getAttribute ( 'aria-expanded' ) )
810
+ . toBe ( 'false' , 'Expected aria-expanded to be false when panel hides itself.' ) ;
811
+ } ) ;
812
+ } ) ;
813
+ } ) ;
814
+ } ) ) ;
815
+
791
816
it ( 'should set aria-owns based on the attached autocomplete' , ( ) => {
792
817
fixture . componentInstance . trigger . openPanel ( ) ;
793
818
fixture . detectChanges ( ) ;
@@ -901,21 +926,24 @@ describe('MdAutocomplete', () => {
901
926
} ) ;
902
927
} ) ) ;
903
928
904
- it ( 'should work when input is wrapped in ngIf' , ( ) => {
929
+ it ( 'should work when input is wrapped in ngIf' , async ( ( ) => {
905
930
const fixture = TestBed . createComponent ( NgIfAutocomplete ) ;
906
931
fixture . detectChanges ( ) ;
907
932
908
933
const input = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
909
934
dispatchFakeEvent ( input , 'focus' ) ;
910
- fixture . detectChanges ( ) ;
911
935
912
- expect ( fixture . componentInstance . trigger . panelOpen )
913
- . toBe ( true , `Expected panel state to read open when input is focused.` ) ;
914
- expect ( overlayContainerElement . textContent )
915
- . toContain ( 'One' , `Expected panel to display when input is focused.` ) ;
916
- expect ( overlayContainerElement . textContent )
917
- . toContain ( 'Two' , `Expected panel to display when input is focused.` ) ;
918
- } ) ;
936
+ fixture . whenStable ( ) . then ( ( ) => {
937
+ fixture . detectChanges ( ) ;
938
+
939
+ expect ( fixture . componentInstance . trigger . panelOpen )
940
+ . toBe ( true , `Expected panel state to read open when input is focused.` ) ;
941
+ expect ( overlayContainerElement . textContent )
942
+ . toContain ( 'One' , `Expected panel to display when input is focused.` ) ;
943
+ expect ( overlayContainerElement . textContent )
944
+ . toContain ( 'Two' , `Expected panel to display when input is focused.` ) ;
945
+ } ) ;
946
+ } ) ) ;
919
947
920
948
it ( 'should filter properly with ngIf after setting the active item' , fakeAsync ( ( ) => {
921
949
const fixture = TestBed . createComponent ( NgIfAutocomplete ) ;
0 commit comments