@@ -28,7 +28,6 @@ import {MatDatepickerInput} from './datepicker-input';
28
28
import { MatDatepickerToggle } from './datepicker-toggle' ;
29
29
import { MatDatepickerIntl , MatDatepickerModule } from './index' ;
30
30
31
-
32
31
describe ( 'MatDatepicker' , ( ) => {
33
32
afterEach ( inject ( [ OverlayContainer ] , ( container : OverlayContainer ) => {
34
33
container . getContainerElement ( ) . parentNode ! . removeChild ( container . getContainerElement ( ) ) ;
@@ -104,7 +103,7 @@ describe('MatDatepicker', () => {
104
103
. not . toBeNull ( ) ;
105
104
} ) ;
106
105
107
- it ( 'should open datepicker if opened input is set to true' , async ( ( ) => {
106
+ it ( 'should open datepicker if opened input is set to true' , ( ) => {
108
107
testComponent . opened = true ;
109
108
fixture . detectChanges ( ) ;
110
109
@@ -113,10 +112,8 @@ describe('MatDatepicker', () => {
113
112
testComponent . opened = false ;
114
113
fixture . detectChanges ( ) ;
115
114
116
- fixture . whenStable ( ) . then ( ( ) => {
117
- expect ( document . querySelector ( '.mat-datepicker-content' ) ) . toBeNull ( ) ;
118
- } ) ;
119
- } ) ) ;
115
+ expect ( document . querySelector ( '.mat-datepicker-content' ) ) . toBeNull ( ) ;
116
+ } ) ;
120
117
121
118
it ( 'open in disabled mode should not open the calendar' , ( ) => {
122
119
testComponent . disabled = true ;
@@ -156,9 +153,7 @@ describe('MatDatepicker', () => {
156
153
testComponent . datepicker . close ( ) ;
157
154
fixture . detectChanges ( ) ;
158
155
159
- fixture . whenStable ( ) . then ( ( ) => {
160
- expect ( parseInt ( getComputedStyle ( popup ) . height as string ) ) . toBe ( 0 ) ;
161
- } ) ;
156
+ expect ( parseInt ( getComputedStyle ( popup ) . height as string ) ) . toBe ( 0 ) ;
162
157
} ) ;
163
158
164
159
it ( 'should close the popup when pressing ESCAPE' , ( ) => {
@@ -182,7 +177,7 @@ describe('MatDatepicker', () => {
182
177
. toBe ( true , 'Expected default ESCAPE action to be prevented.' ) ;
183
178
} ) ;
184
179
185
- it ( 'close should close dialog' , ( ) => {
180
+ it ( 'close should close dialog' , async ( ( ) => {
186
181
testComponent . touch = true ;
187
182
fixture . detectChanges ( ) ;
188
183
@@ -197,9 +192,9 @@ describe('MatDatepicker', () => {
197
192
fixture . whenStable ( ) . then ( ( ) => {
198
193
expect ( document . querySelector ( 'mat-dialog-container' ) ) . toBeNull ( ) ;
199
194
} ) ;
200
- } ) ;
195
+ } ) ) ;
201
196
202
- it ( 'setting selected should update input and close calendar' , ( ) => {
197
+ it ( 'setting selected should update input and close calendar' , async ( ( ) => {
203
198
testComponent . touch = true ;
204
199
fixture . detectChanges ( ) ;
205
200
@@ -217,12 +212,13 @@ describe('MatDatepicker', () => {
217
212
expect ( document . querySelector ( 'mat-dialog-container' ) ) . toBeNull ( ) ;
218
213
expect ( testComponent . datepickerInput . value ) . toEqual ( new Date ( 2020 , JAN , 2 ) ) ;
219
214
} ) ;
220
- } ) ;
215
+ } ) ) ;
221
216
222
217
it ( 'clicking the currently selected date should close the calendar ' +
223
218
'without firing selectedChanged' , ( ) => {
224
219
const selectedChangedSpy =
225
220
spyOn ( testComponent . datepicker . selectedChanged , 'emit' ) . and . callThrough ( ) ;
221
+
226
222
for ( let changeCount = 1 ; changeCount < 3 ; changeCount ++ ) {
227
223
const currentDay = changeCount ;
228
224
testComponent . datepicker . open ( ) ;
@@ -236,11 +232,9 @@ describe('MatDatepicker', () => {
236
232
fixture . detectChanges ( ) ;
237
233
}
238
234
239
- fixture . whenStable ( ) . then ( ( ) => {
240
- expect ( selectedChangedSpy . calls . count ( ) ) . toEqual ( 1 ) ;
241
- expect ( document . querySelector ( 'mat-dialog-container' ) ) . toBeNull ( ) ;
242
- expect ( testComponent . datepickerInput . value ) . toEqual ( new Date ( 2020 , JAN , 2 ) ) ;
243
- } ) ;
235
+ expect ( selectedChangedSpy . calls . count ( ) ) . toEqual ( 1 ) ;
236
+ expect ( document . querySelector ( 'mat-dialog-container' ) ) . toBeNull ( ) ;
237
+ expect ( testComponent . datepickerInput . value ) . toEqual ( new Date ( 2020 , JAN , 2 ) ) ;
244
238
} ) ;
245
239
246
240
it ( 'startAt should fallback to input value' , ( ) => {
@@ -488,7 +482,7 @@ describe('MatDatepicker', () => {
488
482
expect ( inputEl . classList ) . toContain ( 'ng-touched' ) ;
489
483
} ) ;
490
484
491
- it ( 'should mark input touched on calendar selection' , ( ) => {
485
+ it ( 'should mark input touched on calendar selection' , async ( ( ) => {
492
486
let inputEl = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
493
487
494
488
expect ( inputEl . classList ) . toContain ( 'ng-untouched' ) ;
@@ -501,7 +495,7 @@ describe('MatDatepicker', () => {
501
495
502
496
expect ( inputEl . classList ) . toContain ( 'ng-touched' ) ;
503
497
} ) ;
504
- } ) ;
498
+ } ) ) ;
505
499
} ) ;
506
500
507
501
describe ( 'datepicker with formControl' , ( ) => {
@@ -711,7 +705,7 @@ describe('MatDatepicker', () => {
711
705
expect ( testComponent . datepicker . _maxDate ) . toEqual ( new Date ( 2020 , JAN , 1 ) ) ;
712
706
} ) ;
713
707
714
- it ( 'should mark invalid when value is before min' , ( ) => {
708
+ it ( 'should mark invalid when value is before min' , async ( ( ) => {
715
709
testComponent . date = new Date ( 2009 , DEC , 31 ) ;
716
710
fixture . detectChanges ( ) ;
717
711
@@ -721,9 +715,9 @@ describe('MatDatepicker', () => {
721
715
expect ( fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement . classList )
722
716
. toContain ( 'ng-invalid' ) ;
723
717
} ) ;
724
- } ) ;
718
+ } ) ) ;
725
719
726
- it ( 'should mark invalid when value is after max' , ( ) => {
720
+ it ( 'should mark invalid when value is after max' , async ( ( ) => {
727
721
testComponent . date = new Date ( 2020 , JAN , 2 ) ;
728
722
fixture . detectChanges ( ) ;
729
723
@@ -733,9 +727,9 @@ describe('MatDatepicker', () => {
733
727
expect ( fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement . classList )
734
728
. toContain ( 'ng-invalid' ) ;
735
729
} ) ;
736
- } ) ;
730
+ } ) ) ;
737
731
738
- it ( 'should not mark invalid when value equals min' , ( ) => {
732
+ it ( 'should not mark invalid when value equals min' , async ( ( ) => {
739
733
testComponent . date = testComponent . datepicker . _minDate ;
740
734
fixture . detectChanges ( ) ;
741
735
@@ -745,9 +739,9 @@ describe('MatDatepicker', () => {
745
739
expect ( fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement . classList )
746
740
. not . toContain ( 'ng-invalid' ) ;
747
741
} ) ;
748
- } ) ;
742
+ } ) ) ;
749
743
750
- it ( 'should not mark invalid when value equals max' , ( ) => {
744
+ it ( 'should not mark invalid when value equals max' , async ( ( ) => {
751
745
testComponent . date = testComponent . datepicker . _maxDate ;
752
746
fixture . detectChanges ( ) ;
753
747
@@ -757,9 +751,9 @@ describe('MatDatepicker', () => {
757
751
expect ( fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement . classList )
758
752
. not . toContain ( 'ng-invalid' ) ;
759
753
} ) ;
760
- } ) ;
754
+ } ) ) ;
761
755
762
- it ( 'should not mark invalid when value is between min and max' , ( ) => {
756
+ it ( 'should not mark invalid when value is between min and max' , async ( ( ) => {
763
757
testComponent . date = new Date ( 2010 , JAN , 2 ) ;
764
758
fixture . detectChanges ( ) ;
765
759
@@ -769,7 +763,7 @@ describe('MatDatepicker', () => {
769
763
expect ( fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement . classList )
770
764
. not . toContain ( 'ng-invalid' ) ;
771
765
} ) ;
772
- } ) ;
766
+ } ) ) ;
773
767
} ) ;
774
768
775
769
describe ( 'datepicker with filter and validation' , ( ) => {
@@ -1057,17 +1051,23 @@ describe('MatDatepicker', () => {
1057
1051
input = fixture . nativeElement . querySelector ( 'input' ) as HTMLInputElement ;
1058
1052
} ) ) ;
1059
1053
1060
- it ( 'should have the correct input value even when inverted date format' , ( ) => {
1054
+ it ( 'should have the correct input value even when inverted date format' , async ( ( ) => {
1055
+ if ( typeof Intl === 'undefined' ) {
1056
+ // Skip this test if the internationalization API is not supported in the current
1057
+ // browser. Browsers like Safari 9 do not support the "Intl" API.
1058
+ return ;
1059
+ }
1060
+
1061
1061
let selected = new Date ( 2017 , SEP , 1 ) ;
1062
1062
testComponent . date = selected ;
1063
1063
fixture . detectChanges ( ) ;
1064
1064
1065
1065
fixture . whenStable ( ) . then ( ( ) => {
1066
1066
fixture . detectChanges ( ) ;
1067
- expect ( input . value ) . toBe ( '01.09 .2017' ) ;
1067
+ expect ( input . value ) . toBe ( '1.9 .2017' ) ;
1068
1068
expect ( testComponent . datepickerInput . value ) . toBe ( selected ) ;
1069
1069
} ) ;
1070
- } ) ;
1070
+ } ) ) ;
1071
1071
} ) ;
1072
1072
} ) ;
1073
1073
0 commit comments