@@ -20,6 +20,7 @@ import {BACKSPACE} from '@angular/cdk/keycodes';
2020import { MatDateRangeInput } from './date-range-input' ;
2121import { MatDateRangePicker } from './date-range-picker' ;
2222import { MatStartDate , MatEndDate } from './date-range-input-parts' ;
23+ import { Subscription } from 'rxjs' ;
2324
2425describe ( 'MatDateRangeInput' , ( ) => {
2526 function createComponent < T > (
@@ -317,6 +318,57 @@ describe('MatDateRangeInput', () => {
317318 expect ( end . errors ?. matDatepickerFilter ) . toBeTruthy ( ) ;
318319 } ) ;
319320
321+ it ( 'should should revalidate when a new date filter function is assigned' , ( ) => {
322+ const fixture = createComponent ( StandardRangePicker ) ;
323+ fixture . detectChanges ( ) ;
324+ const { start, end} = fixture . componentInstance . range . controls ;
325+ const date = new Date ( 2020 , 2 , 2 ) ;
326+ start . setValue ( date ) ;
327+ end . setValue ( date ) ;
328+ fixture . detectChanges ( ) ;
329+
330+ const spy = jasmine . createSpy ( 'change spy' ) ;
331+ const subscription = new Subscription ( ) ;
332+ subscription . add ( start . valueChanges . subscribe ( spy ) ) ;
333+ subscription . add ( end . valueChanges . subscribe ( spy ) ) ;
334+
335+ fixture . componentInstance . dateFilter = ( ) => false ;
336+ fixture . detectChanges ( ) ;
337+ expect ( spy ) . toHaveBeenCalledTimes ( 2 ) ;
338+
339+ fixture . componentInstance . dateFilter = ( ) => true ;
340+ fixture . detectChanges ( ) ;
341+ expect ( spy ) . toHaveBeenCalledTimes ( 4 ) ;
342+
343+ subscription . unsubscribe ( ) ;
344+ } ) ;
345+
346+ it ( 'should not dispatch the change event if a new filter function with the same result ' +
347+ 'is assigned' , ( ) => {
348+ const fixture = createComponent ( StandardRangePicker ) ;
349+ fixture . detectChanges ( ) ;
350+ const { start, end} = fixture . componentInstance . range . controls ;
351+ const date = new Date ( 2020 , 2 , 2 ) ;
352+ start . setValue ( date ) ;
353+ end . setValue ( date ) ;
354+ fixture . detectChanges ( ) ;
355+
356+ const spy = jasmine . createSpy ( 'change spy' ) ;
357+ const subscription = new Subscription ( ) ;
358+ subscription . add ( start . valueChanges . subscribe ( spy ) ) ;
359+ subscription . add ( end . valueChanges . subscribe ( spy ) ) ;
360+
361+ fixture . componentInstance . dateFilter = ( ) => false ;
362+ fixture . detectChanges ( ) ;
363+ expect ( spy ) . toHaveBeenCalledTimes ( 2 ) ;
364+
365+ fixture . componentInstance . dateFilter = ( ) => false ;
366+ fixture . detectChanges ( ) ;
367+ expect ( spy ) . toHaveBeenCalledTimes ( 2 ) ;
368+
369+ subscription . unsubscribe ( ) ;
370+ } ) ;
371+
320372 it ( 'should throw if there is no start input' , ( ) => {
321373 expect ( ( ) => {
322374 const fixture = createComponent ( RangePickerNoStart ) ;
0 commit comments