@@ -211,6 +211,9 @@ describe('DlDateTimeInputDirective', () => {
211
211
} ) ;
212
212
213
213
it ( 'should remove ng-invalid when model is updated with valid date' , fakeAsync ( ( ) => {
214
+ // This is to fix #448, inputting a value that is a disallowed date (but a valid date)
215
+ // should change to ng-valid when the model is updated to an allowed date.
216
+
214
217
const allowedValue = moment ( '2019-10-29T17:00' ) . valueOf ( ) ;
215
218
spyOn ( component , 'dateTimeFilter' ) . and . callFake ( ( date : number ) => {
216
219
return date === allowedValue ;
@@ -233,6 +236,35 @@ describe('DlDateTimeInputDirective', () => {
233
236
expect ( inputElement . classList ) . toContain ( 'ng-valid' ) ;
234
237
} ) ) ;
235
238
239
+ it ( 'should add ng-invalid for non-date input and remove ng-invalid after when model is updated with valid date' , fakeAsync ( ( ) => {
240
+ // This is to fix #448, inputting a completely invalid date value (i.e not a date at all)
241
+ // should change to ng-valid when the model is updated to an allowed date.
242
+
243
+ const allowedValue = moment ( '2019-10-29T17:00' ) . valueOf ( ) ;
244
+ spyOn ( component , 'dateTimeFilter' ) . and . callFake ( ( date : number ) => {
245
+ return date === allowedValue ;
246
+ } ) ;
247
+
248
+ const inputElement = debugElement . query ( By . directive ( DlDateTimeInputDirective ) ) . nativeElement ;
249
+ inputElement . value = 'very-invalid-date' ;
250
+ inputElement . dispatchEvent ( new Event ( 'input' ) ) ;
251
+
252
+ fixture . detectChanges ( ) ;
253
+
254
+ expect ( inputElement . classList ) . toContain ( 'ng-invalid' ) ;
255
+
256
+ inputElement . dispatchEvent ( new Event ( 'blur' ) ) ;
257
+ fixture . detectChanges ( ) ;
258
+
259
+ component . dateValue = allowedValue ;
260
+
261
+ fixture . detectChanges ( ) ;
262
+ tick ( ) ;
263
+ fixture . detectChanges ( ) ;
264
+
265
+ expect ( inputElement . classList ) . toContain ( 'ng-valid' ) ;
266
+ } ) ) ;
267
+
236
268
it ( 'should disable input when setDisabled is called' , ( ) => {
237
269
const inputElement = debugElement . query ( By . directive ( DlDateTimeInputDirective ) ) . nativeElement ;
238
270
expect ( inputElement . disabled ) . toBe ( false ) ;
0 commit comments