1
1
import { Component , ViewChild } from '@angular/core' ;
2
- import { async , ComponentFixture , TestBed , inject } from '@angular/core/testing' ;
2
+ import { async , ComponentFixture , TestBed , inject , fakeAsync } from '@angular/core/testing' ;
3
3
import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
4
4
import { FormControl , FormsModule , ReactiveFormsModule } from '@angular/forms' ;
5
5
import { By } from '@angular/platform-browser' ;
@@ -11,7 +11,7 @@ import {MdDatepicker} from './datepicker';
11
11
import { MdDatepickerInput } from './datepicker-input' ;
12
12
import { MdInputModule } from '../input/index' ;
13
13
import { MdNativeDateModule } from '../core/datetime/index' ;
14
- import { DEC , JAN , SEP } from '../core/testing/month-constants' ;
14
+ import { DEC , JAN , JUL , JUN , SEP } from '../core/testing/month-constants' ;
15
15
import { createKeyboardEvent , dispatchEvent } from '@angular/cdk/testing' ;
16
16
import { MdFormFieldModule } from '../form-field/index' ;
17
17
import { MAT_DATE_LOCALE } from '../core/datetime/date-adapter' ;
@@ -38,6 +38,7 @@ describe('MdDatepicker', () => {
38
38
DatepickerWithChangeAndInputEvents ,
39
39
DatepickerWithFilterAndValidation ,
40
40
DatepickerWithFormControl ,
41
+ DatepickerWithISOStrings ,
41
42
DatepickerWithMinAndMaxValidation ,
42
43
DatepickerWithNgModel ,
43
44
DatepickerWithStartAt ,
@@ -856,6 +857,32 @@ describe('MdDatepicker', () => {
856
857
expect ( testComponent . onDateInput ) . toHaveBeenCalled ( ) ;
857
858
} ) ;
858
859
} ) ;
860
+
861
+ describe ( 'with ISO 8601 strings as input' , ( ) => {
862
+ let fixture : ComponentFixture < DatepickerWithISOStrings > ;
863
+ let testComponent : DatepickerWithISOStrings ;
864
+
865
+ beforeEach ( async ( ( ) => {
866
+ fixture = TestBed . createComponent ( DatepickerWithISOStrings ) ;
867
+ testComponent = fixture . componentInstance ;
868
+ } ) ) ;
869
+
870
+ afterEach ( async ( ( ) => {
871
+ testComponent . datepicker . close ( ) ;
872
+ fixture . detectChanges ( ) ;
873
+ } ) ) ;
874
+
875
+ it ( 'should coerce ISO strings' , async ( ( ) => {
876
+ expect ( ( ) => fixture . detectChanges ( ) ) . not . toThrow ( ) ;
877
+ fixture . whenStable ( ) . then ( ( ) => {
878
+ fixture . detectChanges ( ) ;
879
+ expect ( testComponent . datepicker . startAt ) . toEqual ( new Date ( 2017 , JUL , 1 ) ) ;
880
+ expect ( testComponent . datepickerInput . value ) . toEqual ( new Date ( 2017 , JUN , 1 ) ) ;
881
+ expect ( testComponent . datepickerInput . min ) . toEqual ( new Date ( 2017 , JAN , 1 ) ) ;
882
+ expect ( testComponent . datepickerInput . max ) . toEqual ( new Date ( 2017 , DEC , 31 ) ) ;
883
+ } ) ;
884
+ } ) ) ;
885
+ } ) ;
859
886
} ) ;
860
887
861
888
describe ( 'with missing DateAdapter and MD_DATE_FORMATS' , ( ) => {
@@ -1170,3 +1197,18 @@ class DatepickerWithi18n {
1170
1197
@ViewChild ( 'd' ) datepicker : MdDatepicker < Date > ;
1171
1198
@ViewChild ( MdDatepickerInput ) datepickerInput : MdDatepickerInput < Date > ;
1172
1199
}
1200
+
1201
+ @Component ( {
1202
+ template : `
1203
+ <input [mdDatepicker]="d" [(ngModel)]="value" [min]="min" [max]="max">
1204
+ <md-datepicker #d [startAt]="startAt"></md-datepicker>
1205
+ `
1206
+ } )
1207
+ class DatepickerWithISOStrings {
1208
+ value = new Date ( 2017 , JUN , 1 ) . toISOString ( ) ;
1209
+ min = new Date ( 2017 , JAN , 1 ) . toISOString ( ) ;
1210
+ max = new Date ( 2017 , DEC , 31 ) . toISOString ( ) ;
1211
+ startAt = new Date ( 2017 , JUL , 1 ) . toISOString ( ) ;
1212
+ @ViewChild ( 'd' ) datepicker : MdDatepicker < Date > ;
1213
+ @ViewChild ( MdDatepickerInput ) datepickerInput : MdDatepickerInput < Date > ;
1214
+ }
0 commit comments