11import { 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' ;
33import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
44import { FormControl , FormsModule , ReactiveFormsModule } from '@angular/forms' ;
55import { By } from '@angular/platform-browser' ;
@@ -11,7 +11,7 @@ import {MdDatepicker} from './datepicker';
1111import { MdDatepickerInput } from './datepicker-input' ;
1212import { MdInputModule } from '../input/index' ;
1313import { 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' ;
1515import { createKeyboardEvent , dispatchEvent } from '@angular/cdk/testing' ;
1616import { MdFormFieldModule } from '../form-field/index' ;
1717import { MAT_DATE_LOCALE } from '../core/datetime/date-adapter' ;
@@ -38,6 +38,7 @@ describe('MdDatepicker', () => {
3838 DatepickerWithChangeAndInputEvents ,
3939 DatepickerWithFilterAndValidation ,
4040 DatepickerWithFormControl ,
41+ DatepickerWithISOStrings ,
4142 DatepickerWithMinAndMaxValidation ,
4243 DatepickerWithNgModel ,
4344 DatepickerWithStartAt ,
@@ -856,6 +857,32 @@ describe('MdDatepicker', () => {
856857 expect ( testComponent . onDateInput ) . toHaveBeenCalled ( ) ;
857858 } ) ;
858859 } ) ;
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+ } ) ;
859886 } ) ;
860887
861888 describe ( 'with missing DateAdapter and MD_DATE_FORMATS' , ( ) => {
@@ -1170,3 +1197,18 @@ class DatepickerWithi18n {
11701197 @ViewChild ( 'd' ) datepicker : MdDatepicker < Date > ;
11711198 @ViewChild ( MdDatepickerInput ) datepickerInput : MdDatepickerInput < Date > ;
11721199}
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