@@ -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
} ) ;
@@ -753,20 +755,43 @@ describe('MdAutocomplete', () => {
753
755
. toBe ( 'false' , 'Expected aria-expanded to be false while panel is closed.' ) ;
754
756
755
757
fixture . componentInstance . trigger . openPanel ( ) ;
756
- fixture . detectChanges ( ) ;
758
+ fixture . whenStable ( ) . then ( ( ) => {
759
+ fixture . detectChanges ( ) ;
757
760
758
- expect ( input . getAttribute ( 'aria-expanded' ) )
759
- . toBe ( 'true' , 'Expected aria-expanded to be true while panel is open.' ) ;
761
+ expect ( input . getAttribute ( 'aria-expanded' ) )
762
+ . toBe ( 'true' , 'Expected aria-expanded to be true while panel is open.' ) ;
760
763
761
- fixture . componentInstance . trigger . closePanel ( ) ;
762
- fixture . detectChanges ( ) ;
764
+ fixture . componentInstance . trigger . closePanel ( ) ;
765
+ fixture . detectChanges ( ) ;
763
766
764
- fixture . whenStable ( ) . then ( ( ) => {
765
- expect ( input . getAttribute ( 'aria-expanded' ) )
766
- . toBe ( 'false' , 'Expected aria-expanded to be false when panel closes again.' ) ;
767
+ fixture . whenStable ( ) . then ( ( ) => {
768
+ expect ( input . getAttribute ( 'aria-expanded' ) )
769
+ . toBe ( 'false' , 'Expected aria-expanded to be false when panel closes again.' ) ;
770
+ } ) ;
767
771
} ) ;
768
772
} ) ) ;
769
773
774
+ it ( 'should set aria-expanded properly when the panel is hidden' , async ( ( ) => {
775
+ fixture . componentInstance . trigger . openPanel ( ) ;
776
+
777
+ fixture . whenStable ( ) . then ( ( ) => {
778
+ fixture . detectChanges ( ) ;
779
+ expect ( input . getAttribute ( 'aria-expanded' ) )
780
+ . toBe ( 'true' , 'Expected aria-expanded to be true while panel is open.' ) ;
781
+
782
+ typeInElement ( 'zz' , input ) ;
783
+ fixture . whenStable ( ) . then ( ( ) => {
784
+ fixture . detectChanges ( ) ;
785
+
786
+ fixture . whenStable ( ) . then ( ( ) => {
787
+ fixture . detectChanges ( ) ;
788
+ expect ( input . getAttribute ( 'aria-expanded' ) )
789
+ . toBe ( 'false' , 'Expected aria-expanded to be false when panel hides itself.' ) ;
790
+ } ) ;
791
+ } ) ;
792
+ } ) ;
793
+ } ) ) ;
794
+
770
795
it ( 'should set aria-owns based on the attached autocomplete' , ( ) => {
771
796
fixture . componentInstance . trigger . openPanel ( ) ;
772
797
fixture . detectChanges ( ) ;
@@ -880,21 +905,24 @@ describe('MdAutocomplete', () => {
880
905
} ) ;
881
906
} ) ) ;
882
907
883
- it ( 'should work when input is wrapped in ngIf' , ( ) => {
908
+ it ( 'should work when input is wrapped in ngIf' , async ( ( ) => {
884
909
const fixture = TestBed . createComponent ( NgIfAutocomplete ) ;
885
910
fixture . detectChanges ( ) ;
886
911
887
912
const input = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
888
913
dispatchFakeEvent ( input , 'focus' ) ;
889
- fixture . detectChanges ( ) ;
890
914
891
- expect ( fixture . componentInstance . trigger . panelOpen )
892
- . toBe ( true , `Expected panel state to read open when input is focused.` ) ;
893
- expect ( overlayContainerElement . textContent )
894
- . toContain ( 'One' , `Expected panel to display when input is focused.` ) ;
895
- expect ( overlayContainerElement . textContent )
896
- . toContain ( 'Two' , `Expected panel to display when input is focused.` ) ;
897
- } ) ;
915
+ fixture . whenStable ( ) . then ( ( ) => {
916
+ fixture . detectChanges ( ) ;
917
+
918
+ expect ( fixture . componentInstance . trigger . panelOpen )
919
+ . toBe ( true , `Expected panel state to read open when input is focused.` ) ;
920
+ expect ( overlayContainerElement . textContent )
921
+ . toContain ( 'One' , `Expected panel to display when input is focused.` ) ;
922
+ expect ( overlayContainerElement . textContent )
923
+ . toContain ( 'Two' , `Expected panel to display when input is focused.` ) ;
924
+ } ) ;
925
+ } ) ) ;
898
926
899
927
} ) ;
900
928
} ) ;
0 commit comments