@@ -328,6 +328,37 @@ describe('MatMonthView', () => {
328
328
expect ( testComponent . selected ) . toBeFalsy ( ) ;
329
329
} ) ;
330
330
331
+ it ( 'should not fire the selected change event when clicking on an already-selected ' +
332
+ 'date while selecting a single date' , ( ) => {
333
+ testComponent . selected = new Date ( 2017 , JAN , 10 ) ;
334
+ fixture . detectChanges ( ) ;
335
+
336
+ expect ( fixture . componentInstance . selectedChangeSpy ) . not . toHaveBeenCalled ( ) ;
337
+
338
+ const selectedCell =
339
+ monthViewNativeElement . querySelector ( '.mat-calendar-body-selected' ) as HTMLElement ;
340
+ selectedCell . click ( ) ;
341
+ fixture . detectChanges ( ) ;
342
+
343
+ expect ( fixture . componentInstance . selectedChangeSpy ) . not . toHaveBeenCalled ( ) ;
344
+ } ) ;
345
+
346
+ it ( 'should fire the selected change event when clicking on an already-selected ' +
347
+ 'date while selecting a range' , ( ) => {
348
+ const selectedDate = new Date ( 2017 , JAN , 10 ) ;
349
+ testComponent . selected = new DateRange ( selectedDate , null ) ;
350
+ fixture . detectChanges ( ) ;
351
+
352
+ expect ( fixture . componentInstance . selectedChangeSpy ) . not . toHaveBeenCalled ( ) ;
353
+
354
+ const selectedCell =
355
+ monthViewNativeElement . querySelector ( '.mat-calendar-body-selected' ) as HTMLElement ;
356
+ selectedCell . click ( ) ;
357
+ fixture . detectChanges ( ) ;
358
+
359
+ expect ( fixture . componentInstance . selectedChangeSpy ) . toHaveBeenCalledWith ( selectedDate ) ;
360
+ } ) ;
361
+
331
362
} ) ;
332
363
} ) ;
333
364
} ) ;
@@ -389,11 +420,16 @@ describe('MatMonthView', () => {
389
420
390
421
391
422
@Component ( {
392
- template : `<mat-month-view [(activeDate)]="date" [(selected)]="selected"></mat-month-view>` ,
423
+ template : `
424
+ <mat-month-view
425
+ [(activeDate)]="date"
426
+ [(selected)]="selected"
427
+ (selectedChange)="selectedChangeSpy($event)"></mat-month-view>` ,
393
428
} )
394
429
class StandardMonthView {
395
430
date = new Date ( 2017 , JAN , 5 ) ;
396
431
selected : Date | DateRange < Date > = new Date ( 2017 , JAN , 10 ) ;
432
+ selectedChangeSpy = jasmine . createSpy ( 'selectedChange' ) ;
397
433
}
398
434
399
435
0 commit comments