@@ -11,9 +11,11 @@ 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 } from '../core/testing/month-constants' ;
14
+ import { DEC , JAN , SEP } from '../core/testing/month-constants' ;
15
15
import { createKeyboardEvent , dispatchEvent } from '@angular/cdk/testing' ;
16
16
import { MdFormFieldModule } from '../form-field/index' ;
17
+ import { MAT_DATE_LOCALE } from '../core/datetime/date-adapter' ;
18
+ import { NativeDateModule } from '../core/datetime/index' ;
17
19
18
20
describe ( 'MdDatepicker' , ( ) => {
19
21
afterEach ( inject ( [ OverlayContainer ] , ( container : OverlayContainer ) => {
@@ -943,6 +945,45 @@ describe('MdDatepicker', () => {
943
945
} ) ;
944
946
945
947
} ) ;
948
+
949
+ describe ( 'internationalization' , ( ) => {
950
+ let fixture : ComponentFixture < DatepickerWithi18n > ;
951
+ let testComponent : DatepickerWithi18n ;
952
+ let input : HTMLInputElement ;
953
+
954
+ beforeEach ( async ( ( ) => {
955
+ TestBed . configureTestingModule ( {
956
+ imports : [
957
+ MdDatepickerModule ,
958
+ MdFormFieldModule ,
959
+ MdInputModule ,
960
+ MdNativeDateModule ,
961
+ NoopAnimationsModule ,
962
+ NativeDateModule ,
963
+ FormsModule
964
+ ] ,
965
+ providers : [ { provide : MAT_DATE_LOCALE , useValue : 'de-DE' } ] ,
966
+ declarations : [ DatepickerWithi18n ] ,
967
+ } ) . compileComponents ( ) ;
968
+
969
+ fixture = TestBed . createComponent ( DatepickerWithi18n ) ;
970
+ fixture . detectChanges ( ) ;
971
+ testComponent = fixture . componentInstance ;
972
+ input = fixture . nativeElement . querySelector ( 'input' ) as HTMLInputElement ;
973
+ } ) ) ;
974
+
975
+ it ( 'should have the correct input value even when inverted date format' , ( ) => {
976
+ let selected = new Date ( 2017 , SEP , 1 ) ;
977
+ testComponent . date = selected ;
978
+ fixture . detectChanges ( ) ;
979
+
980
+ fixture . whenStable ( ) . then ( ( ) => {
981
+ fixture . detectChanges ( ) ;
982
+ expect ( input . value ) . toBe ( '01.09.2017' ) ;
983
+ expect ( testComponent . datepickerInput . value ) . toBe ( selected ) ;
984
+ } ) ;
985
+ } ) ;
986
+ } ) ;
946
987
} ) ;
947
988
948
989
@@ -1099,3 +1140,15 @@ class DatepickerWithChangeAndInputEvents {
1099
1140
1100
1141
onDateInput ( ) { }
1101
1142
}
1143
+
1144
+ @Component ( {
1145
+ template : `
1146
+ <input [mdDatepicker]="d" [(ngModel)]="date">
1147
+ <md-datepicker #d></md-datepicker>
1148
+ `
1149
+ } )
1150
+ class DatepickerWithi18n {
1151
+ date : Date | null = new Date ( 2010 , JAN , 1 ) ;
1152
+ @ViewChild ( 'd' ) datepicker : MdDatepicker < Date > ;
1153
+ @ViewChild ( MdDatepickerInput ) datepickerInput : MdDatepickerInput < Date > ;
1154
+ }
0 commit comments