1
- import { Platform } from '@angular/cdk/platform' ;
2
1
import { LOCALE_ID } from '@angular/core' ;
3
2
import { waitForAsync , inject , TestBed } from '@angular/core/testing' ;
4
3
import { DEC , FEB , JAN , MAR } from '../../testing' ;
5
4
import { DateAdapter , MAT_DATE_LOCALE , NativeDateAdapter , NativeDateModule } from './index' ;
6
5
7
- const SUPPORTS_INTL = typeof Intl != 'undefined' ;
8
-
9
6
10
7
describe ( 'NativeDateAdapter' , ( ) => {
11
- let platform : Platform ;
12
8
let adapter : NativeDateAdapter ;
13
9
let assertValidDate : ( d : Date | null , valid : boolean ) => void ;
14
10
@@ -18,10 +14,8 @@ describe('NativeDateAdapter', () => {
18
14
} ) . compileComponents ( ) ;
19
15
} ) ) ;
20
16
21
- beforeEach ( inject ( [ DateAdapter , Platform ] ,
22
- ( dateAdapter : NativeDateAdapter , _platform : Platform ) => {
17
+ beforeEach ( inject ( [ DateAdapter ] , ( dateAdapter : NativeDateAdapter ) => {
23
18
adapter = dateAdapter ;
24
- platform = _platform ;
25
19
26
20
assertValidDate = ( d : Date | null , valid : boolean ) => {
27
21
expect ( adapter . isDateInstance ( d ) ) . not
@@ -62,30 +56,16 @@ describe('NativeDateAdapter', () => {
62
56
} ) ;
63
57
64
58
it ( 'should get narrow month names' , ( ) => {
65
- // Edge & IE use same value for short and narrow.
66
- if ( platform . EDGE || platform . TRIDENT ) {
67
- expect ( adapter . getMonthNames ( 'narrow' ) ) . toEqual ( [
68
- 'Jan' , 'Feb' , 'Mar' , 'Apr' , 'May' , 'Jun' , 'Jul' , 'Aug' , 'Sep' , 'Oct' , 'Nov' , 'Dec'
69
- ] ) ;
70
- } else {
71
- expect ( adapter . getMonthNames ( 'narrow' ) ) . toEqual ( [
72
- 'J' , 'F' , 'M' , 'A' , 'M' , 'J' , 'J' , 'A' , 'S' , 'O' , 'N' , 'D'
73
- ] ) ;
74
- }
59
+ expect ( adapter . getMonthNames ( 'narrow' ) ) . toEqual ( [
60
+ 'J' , 'F' , 'M' , 'A' , 'M' , 'J' , 'J' , 'A' , 'S' , 'O' , 'N' , 'D'
61
+ ] ) ;
75
62
} ) ;
76
63
77
64
it ( 'should get month names in a different locale' , ( ) => {
78
65
adapter . setLocale ( 'ja-JP' ) ;
79
- if ( SUPPORTS_INTL ) {
80
- expect ( adapter . getMonthNames ( 'long' ) ) . toEqual ( [
81
- '1月' , '2月' , '3月' , '4月' , '5月' , '6月' , '7月' , '8月' , '9月' , '10月' , '11月' , '12月'
82
- ] ) ;
83
- } else {
84
- expect ( adapter . getMonthNames ( 'long' ) ) . toEqual ( [
85
- 'January' , 'February' , 'March' , 'April' , 'May' , 'June' , 'July' , 'August' , 'September' ,
86
- 'October' , 'November' , 'December'
87
- ] ) ;
88
- }
66
+ expect ( adapter . getMonthNames ( 'long' ) ) . toEqual ( [
67
+ '1月' , '2月' , '3月' , '4月' , '5月' , '6月' , '7月' , '8月' , '9月' , '10月' , '11月' , '12月'
68
+ ] ) ;
89
69
} ) ;
90
70
91
71
it ( 'should get date names' , ( ) => {
@@ -97,18 +77,11 @@ describe('NativeDateAdapter', () => {
97
77
98
78
it ( 'should get date names in a different locale' , ( ) => {
99
79
adapter . setLocale ( 'ja-JP' ) ;
100
- if ( SUPPORTS_INTL ) {
101
- expect ( adapter . getDateNames ( ) ) . toEqual ( [
102
- '1日' , '2日' , '3日' , '4日' , '5日' , '6日' , '7日' , '8日' , '9日' , '10日' , '11日' , '12日' ,
103
- '13日' , '14日' , '15日' , '16日' , '17日' , '18日' , '19日' , '20日' , '21日' , '22日' , '23日' , '24日' ,
104
- '25日' , '26日' , '27日' , '28日' , '29日' , '30日' , '31日'
105
- ] ) ;
106
- } else {
107
- expect ( adapter . getDateNames ( ) ) . toEqual ( [
108
- '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , '10' , '11' , '12' , '13' , '14' , '15' , '16' , '17' ,
109
- '18' , '19' , '20' , '21' , '22' , '23' , '24' , '25' , '26' , '27' , '28' , '29' , '30' , '31'
110
- ] ) ;
111
- }
80
+ expect ( adapter . getDateNames ( ) ) . toEqual ( [
81
+ '1日' , '2日' , '3日' , '4日' , '5日' , '6日' , '7日' , '8日' , '9日' , '10日' , '11日' , '12日' ,
82
+ '13日' , '14日' , '15日' , '16日' , '17日' , '18日' , '19日' , '20日' , '21日' , '22日' , '23日' , '24日' ,
83
+ '25日' , '26日' , '27日' , '28日' , '29日' , '30日' , '31日'
84
+ ] ) ;
112
85
} ) ;
113
86
114
87
it ( 'should get long day of week names' , ( ) => {
@@ -124,29 +97,16 @@ describe('NativeDateAdapter', () => {
124
97
} ) ;
125
98
126
99
it ( 'should get narrow day of week names' , ( ) => {
127
- // Edge & IE use two-letter narrow days.
128
- if ( platform . EDGE || platform . TRIDENT ) {
129
- expect ( adapter . getDayOfWeekNames ( 'narrow' ) ) . toEqual ( [
130
- 'Su' , 'Mo' , 'Tu' , 'We' , 'Th' , 'Fr' , 'Sa'
131
- ] ) ;
132
- } else {
133
- expect ( adapter . getDayOfWeekNames ( 'narrow' ) ) . toEqual ( [
134
- 'S' , 'M' , 'T' , 'W' , 'T' , 'F' , 'S'
135
- ] ) ;
136
- }
100
+ expect ( adapter . getDayOfWeekNames ( 'narrow' ) ) . toEqual ( [
101
+ 'S' , 'M' , 'T' , 'W' , 'T' , 'F' , 'S'
102
+ ] ) ;
137
103
} ) ;
138
104
139
105
it ( 'should get day of week names in a different locale' , ( ) => {
140
106
adapter . setLocale ( 'ja-JP' ) ;
141
- if ( SUPPORTS_INTL ) {
142
- expect ( adapter . getDayOfWeekNames ( 'long' ) ) . toEqual ( [
143
- '日曜日' , '月曜日' , '火曜日' , '水曜日' , '木曜日' , '金曜日' , '土曜日'
144
- ] ) ;
145
- } else {
146
- expect ( adapter . getDayOfWeekNames ( 'long' ) ) . toEqual ( [
147
- 'Sunday' , 'Monday' , 'Tuesday' , 'Wednesday' , 'Thursday' , 'Friday' , 'Saturday'
148
- ] ) ;
149
- }
107
+ expect ( adapter . getDayOfWeekNames ( 'long' ) ) . toEqual ( [
108
+ '日曜日' , '月曜日' , '火曜日' , '水曜日' , '木曜日' , '金曜日' , '土曜日'
109
+ ] ) ;
150
110
} ) ;
151
111
152
112
it ( 'should get year name' , ( ) => {
@@ -165,11 +125,7 @@ describe('NativeDateAdapter', () => {
165
125
166
126
it ( 'should get year name in a different locale' , ( ) => {
167
127
adapter . setLocale ( 'ja-JP' ) ;
168
- if ( SUPPORTS_INTL ) {
169
- expect ( adapter . getYearName ( new Date ( 2017 , JAN , 1 ) ) ) . toBe ( '2017年' ) ;
170
- } else {
171
- expect ( adapter . getYearName ( new Date ( 2017 , JAN , 1 ) ) ) . toBe ( '2017' ) ;
172
- }
128
+ expect ( adapter . getYearName ( new Date ( 2017 , JAN , 1 ) ) ) . toBe ( '2017年' ) ;
173
129
} ) ;
174
130
175
131
it ( 'should get first day of week' , ( ) => {
@@ -203,15 +159,9 @@ describe('NativeDateAdapter', () => {
203
159
return adapter . format ( adapter . createDate ( year , JAN , 1 ) , { } ) ;
204
160
} ;
205
161
206
- if ( SUPPORTS_INTL ) {
207
- expect ( createAndFormat ( 50 ) ) . toBe ( '1/1/50' ) ;
208
- expect ( createAndFormat ( 99 ) ) . toBe ( '1/1/99' ) ;
209
- expect ( createAndFormat ( 100 ) ) . toBe ( '1/1/100' ) ;
210
- } else {
211
- expect ( createAndFormat ( 50 ) ) . toBe ( 'Sat Jan 01 0050' ) ;
212
- expect ( createAndFormat ( 99 ) ) . toBe ( 'Thu Jan 01 0099' ) ;
213
- expect ( createAndFormat ( 100 ) ) . toBe ( 'Fri Jan 01 0100' ) ;
214
- }
162
+ expect ( createAndFormat ( 50 ) ) . toBe ( '1/1/50' ) ;
163
+ expect ( createAndFormat ( 99 ) ) . toBe ( '1/1/99' ) ;
164
+ expect ( createAndFormat ( 100 ) ) . toBe ( '1/1/100' ) ;
215
165
} ) ;
216
166
217
167
it ( "should get today's date" , ( ) => {
@@ -244,41 +194,20 @@ describe('NativeDateAdapter', () => {
244
194
} ) ;
245
195
246
196
it ( 'should format' , ( ) => {
247
- if ( SUPPORTS_INTL ) {
248
- expect ( adapter . format ( new Date ( 2017 , JAN , 1 ) , { } ) ) . toEqual ( '1/1/2017' ) ;
249
- } else {
250
- expect ( adapter . format ( new Date ( 2017 , JAN , 1 ) , { } ) ) . toEqual ( 'Sun Jan 01 2017' ) ;
251
- }
197
+ expect ( adapter . format ( new Date ( 2017 , JAN , 1 ) , { } ) ) . toEqual ( '1/1/2017' ) ;
252
198
} ) ;
253
199
254
200
it ( 'should format with custom format' , ( ) => {
255
- if ( SUPPORTS_INTL ) {
256
- expect ( adapter . format ( new Date ( 2017 , JAN , 1 ) , {
257
- year : 'numeric' ,
258
- month : 'long' ,
259
- day : 'numeric'
260
- } ) ) . toEqual ( 'January 1, 2017' ) ;
261
- } else {
262
- expect ( adapter . format ( new Date ( 2017 , JAN , 1 ) , {
263
- year : 'numeric' ,
264
- month : 'long' ,
265
- day : 'numeric'
266
- } ) ) . toEqual ( 'Sun Jan 01 2017' ) ;
267
- }
201
+ expect ( adapter . format ( new Date ( 2017 , JAN , 1 ) , {
202
+ year : 'numeric' ,
203
+ month : 'long' ,
204
+ day : 'numeric'
205
+ } ) ) . toEqual ( 'January 1, 2017' ) ;
268
206
} ) ;
269
207
270
208
it ( 'should format with a different locale' , ( ) => {
271
209
adapter . setLocale ( 'ja-JP' ) ;
272
- if ( SUPPORTS_INTL ) {
273
- // Edge & IE use a different format in Japanese.
274
- if ( platform . EDGE || platform . TRIDENT ) {
275
- expect ( adapter . format ( new Date ( 2017 , JAN , 1 ) , { } ) ) . toEqual ( '2017年1月1日' ) ;
276
- } else {
277
- expect ( adapter . format ( new Date ( 2017 , JAN , 1 ) , { } ) ) . toEqual ( '2017/1/1' ) ;
278
- }
279
- } else {
280
- expect ( adapter . format ( new Date ( 2017 , JAN , 1 ) , { } ) ) . toEqual ( 'Sun Jan 01 2017' ) ;
281
- }
210
+ expect ( adapter . format ( new Date ( 2017 , JAN , 1 ) , { } ) ) . toEqual ( '2017/1/1' ) ;
282
211
} ) ;
283
212
284
213
it ( 'should throw when attempting to format invalid date' , ( ) => {
@@ -352,11 +281,7 @@ describe('NativeDateAdapter', () => {
352
281
} ) ;
353
282
354
283
it ( 'should use UTC for formatting by default' , ( ) => {
355
- if ( SUPPORTS_INTL ) {
356
- expect ( adapter . format ( new Date ( 1800 , 7 , 14 ) , { day : 'numeric' } ) ) . toBe ( '14' ) ;
357
- } else {
358
- expect ( adapter . format ( new Date ( 1800 , 7 , 14 ) , { day : 'numeric' } ) ) . toBe ( 'Thu Aug 14 1800' ) ;
359
- }
284
+ expect ( adapter . format ( new Date ( 1800 , 7 , 14 ) , { day : 'numeric' } ) ) . toBe ( '14' ) ;
360
285
} ) ;
361
286
362
287
it ( 'should count today as a valid date instance' , ( ) => {
@@ -432,10 +357,7 @@ describe('NativeDateAdapter with MAT_DATE_LOCALE override', () => {
432
357
} ) ) ;
433
358
434
359
it ( 'should take the default locale id from the MAT_DATE_LOCALE injection token' , ( ) => {
435
- const expectedValue = SUPPORTS_INTL ?
436
- [ 'søndag' , 'mandag' , 'tirsdag' , 'onsdag' , 'torsdag' , 'fredag' , 'lørdag' ] :
437
- [ 'Sunday' , 'Monday' , 'Tuesday' , 'Wednesday' , 'Thursday' , 'Friday' , 'Saturday' ] ;
438
-
360
+ const expectedValue = [ 'søndag' , 'mandag' , 'tirsdag' , 'onsdag' , 'torsdag' , 'fredag' , 'lørdag' ] ;
439
361
expect ( adapter . getDayOfWeekNames ( 'long' ) ) . toEqual ( expectedValue ) ;
440
362
} ) ;
441
363
@@ -456,10 +378,7 @@ describe('NativeDateAdapter with LOCALE_ID override', () => {
456
378
} ) ) ;
457
379
458
380
it ( 'should cascade locale id from the LOCALE_ID injection token to MAT_DATE_LOCALE' , ( ) => {
459
- const expectedValue = SUPPORTS_INTL ?
460
- [ 'søndag' , 'mandag' , 'tirsdag' , 'onsdag' , 'torsdag' , 'fredag' , 'lørdag' ] :
461
- [ 'Sunday' , 'Monday' , 'Tuesday' , 'Wednesday' , 'Thursday' , 'Friday' , 'Saturday' ] ;
462
-
381
+ const expectedValue = [ 'søndag' , 'mandag' , 'tirsdag' , 'onsdag' , 'torsdag' , 'fredag' , 'lørdag' ] ;
463
382
expect ( adapter . getDayOfWeekNames ( 'long' ) ) . toEqual ( expectedValue ) ;
464
383
} ) ;
465
384
} ) ;
0 commit comments