@@ -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,54 @@ 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
+ let testComponent : StandardDatepicker ;
1331
+
1332
+ beforeEach ( fakeAsync ( ( ) => {
1333
+ TestBed . configureTestingModule ( {
1334
+ imports : [ MatDatepickerModule , MatNativeDateModule , NoopAnimationsModule ] ,
1335
+ declarations : [ StandardDatepicker ] ,
1336
+ } ) . compileComponents ( ) ;
1337
+
1338
+ fixture = TestBed . createComponent ( StandardDatepicker ) ;
1339
+ fixture . detectChanges ( ) ;
1340
+ testComponent = fixture . componentInstance ;
1341
+ } ) ) ;
1342
+
1343
+ it ( 'should not set the `mat-datepicker-content-above` class when opening downwards' ,
1344
+ fakeAsync ( ( ) => {
1345
+ fixture . componentInstance . datepicker . open ( ) ;
1346
+ fixture . detectChanges ( ) ;
1347
+ flush ( ) ;
1348
+ fixture . detectChanges ( ) ;
1349
+
1350
+ const content =
1351
+ document . querySelector ( '.cdk-overlay-pane mat-datepicker-content' ) ! as HTMLElement ;
1352
+
1353
+ expect ( content . classList ) . not . toContain ( 'mat-datepicker-content-above' ) ;
1354
+ } ) ) ;
1355
+
1356
+ it ( 'should set the `mat-datepicker-content-above` class when opening upwards' , fakeAsync ( ( ) => {
1357
+ const input = fixture . debugElement . nativeElement . querySelector ( 'input' ) ;
1358
+
1359
+ // Push the input to the bottom of the page to force the calendar to open upwards
1360
+ input . style . position = 'fixed' ;
1361
+ input . style . bottom = '0' ;
1362
+
1363
+ fixture . componentInstance . datepicker . open ( ) ;
1364
+ fixture . detectChanges ( ) ;
1365
+ flush ( ) ;
1366
+ fixture . detectChanges ( ) ;
1367
+
1368
+ const content =
1369
+ document . querySelector ( '.cdk-overlay-pane mat-datepicker-content' ) ! as HTMLElement ;
1370
+
1371
+ expect ( content . classList ) . toContain ( 'mat-datepicker-content-above' ) ;
1372
+ } ) ) ;
1373
+
1374
+ } ) ;
1345
1375
} ) ;
1346
1376
1347
1377
0 commit comments