1- import { IgxDateRangePickerComponent } from './date-range-picker.component' ;
21import { ComponentFixture , async , TestBed , fakeAsync , tick } from '@angular/core/testing' ;
32import { Component , OnInit , ViewChild , DebugElement } from '@angular/core' ;
43import { IgxInputGroupModule } from '../input-group/public_api' ;
@@ -13,6 +12,8 @@ import { configureTestSuite } from '../test-utils/configure-suite';
1312import { HelperTestFunctions } from '../calendar/calendar-helper-utils' ;
1413import { IgxDateTimeEditorModule } from '../directives/date-time-editor/public_api' ;
1514import { DateRangeType } from '../core/dates' ;
15+ import { IgxDateRangePickerComponent , IgxDateRangeEndComponent } from './public_api' ;
16+ import { IgxIconModule } from '../icon/public_api' ;
1617
1718// The number of milliseconds in one day
1819const ONE_DAY = 1000 * 60 * 60 * 24 ;
@@ -494,7 +495,8 @@ describe('IgxDateRangePicker', () => {
494495 DateRangeTwoInputsTestComponent ,
495496 DateRangeTwoInputsNgModelTestComponent
496497 ] ,
497- imports : [ IgxDateRangePickerModule , IgxDateTimeEditorModule , IgxInputGroupModule , FormsModule , NoopAnimationsModule ]
498+ imports : [ IgxDateRangePickerModule , IgxDateTimeEditorModule ,
499+ IgxInputGroupModule , FormsModule , NoopAnimationsModule , IgxIconModule ]
498500 } )
499501 . compileComponents ( ) ;
500502 } ) ) ;
@@ -633,6 +635,43 @@ describe('IgxDateRangePicker', () => {
633635 } ) ) ;
634636 } ) ;
635637
638+ it ( 'should focus the last focused input after the calendar closes - dropdown' , fakeAsync ( ( ) => {
639+ fixture . componentInstance . mode = InteractionMode . DropDown ;
640+ fixture . detectChanges ( ) ;
641+
642+ endInput = fixture . debugElement . queryAll ( By . css ( '.igx-input-group' ) ) [ 1 ] ;
643+ UIInteractions . simulateClickAndSelectEvent ( endInput . nativeElement ) ;
644+
645+ UIInteractions . triggerEventHandlerKeyDown ( 'ArrowDown' , endInput , true ) ;
646+ tick ( ) ;
647+ fixture . detectChanges ( ) ;
648+
649+ UIInteractions . triggerEventHandlerKeyDown ( 'Escape' , calendar ) ;
650+ fixture . detectChanges ( ) ;
651+ tick ( 100 ) ;
652+
653+ expect ( fixture . componentInstance . dateRange . projectedInputs
654+ . find ( i => i instanceof IgxDateRangeEndComponent ) . isFocused )
655+ . toBeTruthy ( ) ;
656+ } ) ) ;
657+
658+ it ( 'should focus the last focused input after the calendar closes - dialog' , fakeAsync ( ( ) => {
659+ endInput = fixture . debugElement . queryAll ( By . css ( '.igx-input-group' ) ) [ 1 ] ;
660+ UIInteractions . simulateClickAndSelectEvent ( endInput . nativeElement ) ;
661+
662+ UIInteractions . triggerEventHandlerKeyDown ( 'ArrowDown' , endInput , true ) ;
663+ tick ( ) ;
664+ fixture . detectChanges ( ) ;
665+
666+ UIInteractions . triggerEventHandlerKeyDown ( 'Escape' , calendar ) ;
667+ fixture . detectChanges ( ) ;
668+ tick ( 100 ) ;
669+
670+ expect ( fixture . componentInstance . dateRange . projectedInputs
671+ . find ( i => i instanceof IgxDateRangeEndComponent ) . isFocused )
672+ . toBeTruthy ( ) ;
673+ } ) ) ;
674+
636675 describe ( 'Data binding' , ( ) => {
637676 it ( 'should properly update component value with ngModel bound to projected inputs - #7353' , fakeAsync ( ( ) => {
638677 fixture = TestBed . createComponent ( DateRangeTwoInputsNgModelTestComponent ) ;
@@ -822,6 +861,9 @@ export class DateRangeTestComponent implements OnInit {
822861 template : `
823862 <igx-date-range-picker [mode]="mode" [(ngModel)]="range" required>
824863 <igx-date-range-start>
864+ <igx-picker-toggle igxPrefix>
865+ <igx-icon>calendar_view_day</igx-icon>
866+ </igx-picker-toggle>
825867 <input igxInput igxDateTimeEditor type="text">
826868 </igx-date-range-start>
827869 <igx-date-range-end>
0 commit comments