@@ -189,6 +189,30 @@ describe('MdDatepicker', () => {
189189 } ) ;
190190 } ) ;
191191
192+ it ( 'clicking the currently selected date should close the calendar ' +
193+ 'without firing selectedChanged' , ( ) => {
194+ const selectedChangedSpy =
195+ spyOn ( testComponent . datepicker . selectedChanged , 'emit' ) . and . callThrough ( ) ;
196+ for ( let changeCount = 1 ; changeCount < 3 ; changeCount ++ ) {
197+ const currentDay = changeCount ;
198+ testComponent . datepicker . open ( ) ;
199+ fixture . detectChanges ( ) ;
200+
201+ expect ( document . querySelector ( 'md-datepicker-content' ) ) . not . toBeNull ( ) ;
202+ expect ( testComponent . datepickerInput . value ) . toEqual ( new Date ( 2020 , JAN , currentDay ) ) ;
203+
204+ let cells = document . querySelectorAll ( '.mat-calendar-body-cell' ) ;
205+ dispatchMouseEvent ( cells [ 1 ] , 'click' ) ;
206+ fixture . detectChanges ( ) ;
207+ }
208+
209+ fixture . whenStable ( ) . then ( ( ) => {
210+ expect ( selectedChangedSpy . calls . count ( ) ) . toEqual ( 1 ) ;
211+ expect ( document . querySelector ( 'md-dialog-container' ) ) . toBeNull ( ) ;
212+ expect ( testComponent . datepickerInput . value ) . toEqual ( new Date ( 2020 , JAN , 2 ) ) ;
213+ } ) ;
214+ } ) ;
215+
192216 it ( 'startAt should fallback to input value' , ( ) => {
193217 expect ( testComponent . datepicker . startAt ) . toEqual ( new Date ( 2020 , JAN , 1 ) ) ;
194218 } ) ;
@@ -361,7 +385,7 @@ describe('MdDatepicker', () => {
361385 expect ( testComponent . datepickerInput . value ) . toBeNull ( ) ;
362386
363387 let selected = new Date ( 2017 , JAN , 1 ) ;
364- testComponent . datepicker . _selectAndClose ( selected ) ;
388+ testComponent . datepicker . _select ( selected ) ;
365389 fixture . detectChanges ( ) ;
366390
367391 fixture . whenStable ( ) . then ( ( ) => {
@@ -388,7 +412,7 @@ describe('MdDatepicker', () => {
388412
389413 expect ( inputEl . classList ) . toContain ( 'ng-pristine' ) ;
390414
391- testComponent . datepicker . _selectAndClose ( new Date ( 2017 , JAN , 1 ) ) ;
415+ testComponent . datepicker . _select ( new Date ( 2017 , JAN , 1 ) ) ;
392416 fixture . detectChanges ( ) ;
393417
394418 fixture . whenStable ( ) . then ( ( ) => {
@@ -434,7 +458,7 @@ describe('MdDatepicker', () => {
434458
435459 expect ( inputEl . classList ) . toContain ( 'ng-untouched' ) ;
436460
437- testComponent . datepicker . _selectAndClose ( new Date ( 2017 , JAN , 1 ) ) ;
461+ testComponent . datepicker . _select ( new Date ( 2017 , JAN , 1 ) ) ;
438462 fixture . detectChanges ( ) ;
439463
440464 fixture . whenStable ( ) . then ( ( ) => {
@@ -478,7 +502,7 @@ describe('MdDatepicker', () => {
478502 expect ( testComponent . datepickerInput . value ) . toBeNull ( ) ;
479503
480504 let selected = new Date ( 2017 , JAN , 1 ) ;
481- testComponent . datepicker . _selectAndClose ( selected ) ;
505+ testComponent . datepicker . _select ( selected ) ;
482506 fixture . detectChanges ( ) ;
483507
484508 expect ( testComponent . formControl . value ) . toEqual ( selected ) ;
0 commit comments