@@ -98,40 +98,19 @@ describe('MatDatepicker', () => {
98
98
. not . toBeNull ( ) ;
99
99
} ) ;
100
100
101
- it ( 'should pass the datepicker theme color to the overlay' , fakeAsync ( ( ) => {
102
- testComponent . datepicker . color = 'primary' ;
103
- testComponent . datepicker . open ( ) ;
104
- fixture . detectChanges ( ) ;
105
-
106
- let contentEl = document . querySelector ( '.mat-datepicker-content' ) ! ;
107
-
108
- expect ( contentEl . classList ) . toContain ( 'mat-primary' ) ;
109
-
110
- testComponent . datepicker . close ( ) ;
111
- fixture . detectChanges ( ) ;
112
- flush ( ) ;
113
-
114
- testComponent . datepicker . color = 'warn' ;
115
- testComponent . datepicker . open ( ) ;
116
-
117
- contentEl = document . querySelector ( '.mat-datepicker-content' ) ! ;
118
- fixture . detectChanges ( ) ;
119
-
120
- expect ( contentEl . classList ) . toContain ( 'mat-warn' ) ;
121
- expect ( contentEl . classList ) . not . toContain ( 'mat-primary' ) ;
122
- } ) ) ;
123
-
124
- it ( 'should open datepicker if opened input is set to true' , ( ) => {
101
+ it ( 'should open datepicker if opened input is set to true' , fakeAsync ( ( ) => {
125
102
testComponent . opened = true ;
126
103
fixture . detectChanges ( ) ;
104
+ flush ( ) ;
127
105
128
106
expect ( document . querySelector ( '.mat-datepicker-content' ) ) . not . toBeNull ( ) ;
129
107
130
108
testComponent . opened = false ;
131
109
fixture . detectChanges ( ) ;
110
+ flush ( ) ;
132
111
133
112
expect ( document . querySelector ( '.mat-datepicker-content' ) ) . toBeNull ( ) ;
134
- } ) ;
113
+ } ) ) ;
135
114
136
115
it ( 'open in disabled mode should not open the calendar' , ( ) => {
137
116
testComponent . disabled = true ;
@@ -165,7 +144,7 @@ describe('MatDatepicker', () => {
165
144
fixture . detectChanges ( ) ;
166
145
flush ( ) ;
167
146
168
- let popup = document . querySelector ( '.cdk-overlay-pane' ) ! ;
147
+ const popup = document . querySelector ( '.cdk-overlay-pane' ) ! ;
169
148
expect ( popup ) . not . toBeNull ( ) ;
170
149
expect ( parseInt ( getComputedStyle ( popup ) . height as string ) ) . not . toBe ( 0 ) ;
171
150
@@ -211,6 +190,7 @@ describe('MatDatepicker', () => {
211
190
212
191
testComponent . datepicker . open ( ) ;
213
192
fixture . detectChanges ( ) ;
193
+ flush ( ) ;
214
194
215
195
expect ( document . querySelector ( 'mat-dialog-container' ) ) . not . toBeNull ( ) ;
216
196
expect ( testComponent . datepickerInput . value ) . toEqual ( new Date ( 2020 , JAN , 1 ) ) ;
@@ -224,28 +204,30 @@ describe('MatDatepicker', () => {
224
204
expect ( testComponent . datepickerInput . value ) . toEqual ( new Date ( 2020 , JAN , 2 ) ) ;
225
205
} ) ) ;
226
206
227
- it ( 'setting selected via enter press should update input and close calendar' , ( ) => {
228
- testComponent . touch = true ;
229
- fixture . detectChanges ( ) ;
207
+ it ( 'setting selected via enter press should update input and close calendar' ,
208
+ fakeAsync ( ( ) => {
209
+ testComponent . touch = true ;
210
+ fixture . detectChanges ( ) ;
230
211
231
- testComponent . datepicker . open ( ) ;
232
- fixture . detectChanges ( ) ;
212
+ testComponent . datepicker . open ( ) ;
213
+ fixture . detectChanges ( ) ;
214
+ flush ( ) ;
233
215
234
- expect ( document . querySelector ( 'mat-dialog-container' ) ) . not . toBeNull ( ) ;
235
- expect ( testComponent . datepickerInput . value ) . toEqual ( new Date ( 2020 , JAN , 1 ) ) ;
216
+ expect ( document . querySelector ( 'mat-dialog-container' ) ) . not . toBeNull ( ) ;
217
+ expect ( testComponent . datepickerInput . value ) . toEqual ( new Date ( 2020 , JAN , 1 ) ) ;
236
218
237
- let calendarBodyEl = document . querySelector ( '.mat-calendar-body' ) as HTMLElement ;
219
+ let calendarBodyEl = document . querySelector ( '.mat-calendar-body' ) as HTMLElement ;
238
220
239
- dispatchKeyboardEvent ( calendarBodyEl , 'keydown' , RIGHT_ARROW ) ;
240
- fixture . detectChanges ( ) ;
241
- dispatchKeyboardEvent ( calendarBodyEl , 'keydown' , ENTER ) ;
242
- fixture . detectChanges ( ) ;
221
+ dispatchKeyboardEvent ( calendarBodyEl , 'keydown' , RIGHT_ARROW ) ;
222
+ fixture . detectChanges ( ) ;
223
+ flush ( ) ;
224
+ dispatchKeyboardEvent ( calendarBodyEl , 'keydown' , ENTER ) ;
225
+ fixture . detectChanges ( ) ;
226
+ flush ( ) ;
243
227
244
- fixture . whenStable ( ) . then ( ( ) => {
245
228
expect ( document . querySelector ( 'mat-dialog-container' ) ) . toBeNull ( ) ;
246
229
expect ( testComponent . datepickerInput . value ) . toEqual ( new Date ( 2020 , JAN , 2 ) ) ;
247
- } ) ;
248
- } ) ;
230
+ } ) ) ;
249
231
250
232
it ( 'clicking the currently selected date should close the calendar ' +
251
233
'without firing selectedChanged' , fakeAsync ( ( ) => {
@@ -1342,6 +1324,52 @@ describe('MatDatepicker', () => {
1342
1324
expect ( testComponent . datepickerInput . value ) . toBe ( selected ) ;
1343
1325
} ) ) ;
1344
1326
} ) ;
1327
+
1328
+ describe ( 'popup animations' , ( ) => {
1329
+ let fixture : ComponentFixture < StandardDatepicker > ;
1330
+
1331
+ beforeEach ( fakeAsync ( ( ) => {
1332
+ TestBed . configureTestingModule ( {
1333
+ imports : [ MatDatepickerModule , MatNativeDateModule , NoopAnimationsModule ] ,
1334
+ declarations : [ StandardDatepicker ] ,
1335
+ } ) . compileComponents ( ) ;
1336
+
1337
+ fixture = TestBed . createComponent ( StandardDatepicker ) ;
1338
+ fixture . detectChanges ( ) ;
1339
+ } ) ) ;
1340
+
1341
+ it ( 'should not set the `mat-datepicker-content-above` class when opening downwards' ,
1342
+ fakeAsync ( ( ) => {
1343
+ fixture . componentInstance . datepicker . open ( ) ;
1344
+ fixture . detectChanges ( ) ;
1345
+ flush ( ) ;
1346
+ fixture . detectChanges ( ) ;
1347
+
1348
+ const content =
1349
+ document . querySelector ( '.cdk-overlay-pane mat-datepicker-content' ) ! as HTMLElement ;
1350
+
1351
+ expect ( content . classList ) . not . toContain ( 'mat-datepicker-content-above' ) ;
1352
+ } ) ) ;
1353
+
1354
+ it ( 'should set the `mat-datepicker-content-above` class when opening upwards' , fakeAsync ( ( ) => {
1355
+ const input = fixture . debugElement . nativeElement . querySelector ( 'input' ) ;
1356
+
1357
+ // Push the input to the bottom of the page to force the calendar to open upwards
1358
+ input . style . position = 'fixed' ;
1359
+ input . style . bottom = '0' ;
1360
+
1361
+ fixture . componentInstance . datepicker . open ( ) ;
1362
+ fixture . detectChanges ( ) ;
1363
+ flush ( ) ;
1364
+ fixture . detectChanges ( ) ;
1365
+
1366
+ const content =
1367
+ document . querySelector ( '.cdk-overlay-pane mat-datepicker-content' ) ! as HTMLElement ;
1368
+
1369
+ expect ( content . classList ) . toContain ( 'mat-datepicker-content-above' ) ;
1370
+ } ) ) ;
1371
+
1372
+ } ) ;
1345
1373
} ) ;
1346
1374
1347
1375
0 commit comments