1- import { ComponentFixture , async , TestBed , fakeAsync , tick } from '@angular/core/testing' ;
1+ import { ComponentFixture , TestBed , fakeAsync , tick , async } from '@angular/core/testing' ;
22import { Component , OnInit , ViewChild , DebugElement } from '@angular/core' ;
33import { IgxInputGroupModule } from '../input-group/public_api' ;
44import { InteractionMode } from '../core/enums' ;
@@ -599,7 +599,41 @@ describe('IgxDateRangePicker', () => {
599599 expect ( dateRange . onClosing . emit ) . toHaveBeenCalledTimes ( 1 ) ;
600600 expect ( dateRange . onClosed . emit ) . toHaveBeenCalledTimes ( 1 ) ;
601601 } ) ) ;
602+
603+ it ( 'should not open calendar with ALT + DOWN ARROW key if disabled is set to true' , fakeAsync ( ( ) => {
604+ fixture . componentInstance . mode = InteractionMode . DropDown ;
605+ fixture . componentInstance . disabled = true ;
606+ fixture . detectChanges ( ) ;
607+
608+ spyOn ( dateRange . onOpening , 'emit' ) . and . callThrough ( ) ;
609+ spyOn ( dateRange . onOpened , 'emit' ) . and . callThrough ( ) ;
610+
611+ UIInteractions . triggerEventHandlerKeyDown ( 'ArrowDown' , calendar , true ) ;
612+ tick ( DEBOUNCE_TIME * 2 ) ;
613+ fixture . detectChanges ( ) ;
614+ expect ( dateRange . collapsed ) . toBeTruthy ( ) ;
615+ expect ( dateRange . onOpening . emit ) . toHaveBeenCalledTimes ( 0 ) ;
616+ expect ( dateRange . onOpened . emit ) . toHaveBeenCalledTimes ( 0 ) ;
617+ } ) ) ;
602618 } ) ;
619+
620+ it ( 'should expand the calendar if the default icon is clicked' , fakeAsync ( ( ) => {
621+ const input = fixture . debugElement . query ( By . css ( 'igx-input-group' ) ) ;
622+ input . triggerEventHandler ( 'click' , UIInteractions . getMouseEvent ( 'click' ) ) ;
623+ tick ( ) ;
624+ fixture . detectChanges ( ) ;
625+ expect ( fixture . componentInstance . dateRange . collapsed ) . toBeFalsy ( ) ;
626+ } ) ) ;
627+
628+ it ( 'should not expand the calendar if the default icon is clicked when disabled is set to true' , fakeAsync ( ( ) => {
629+ fixture . componentInstance . disabled = true ;
630+ fixture . detectChanges ( ) ;
631+ const input = fixture . debugElement . query ( By . css ( 'igx-input-group' ) ) ;
632+ input . triggerEventHandler ( 'click' , UIInteractions . getMouseEvent ( 'click' ) ) ;
633+ tick ( ) ;
634+ fixture . detectChanges ( ) ;
635+ expect ( fixture . componentInstance . dateRange . collapsed ) . toBeTruthy ( ) ;
636+ } ) ) ;
603637 } ) ;
604638
605639 describe ( 'Two Inputs' , ( ) => {
@@ -876,6 +910,21 @@ describe('IgxDateRangePicker', () => {
876910 expect ( dateRange . onClosing . emit ) . toHaveBeenCalledTimes ( 1 ) ;
877911 expect ( dateRange . onClosed . emit ) . toHaveBeenCalledTimes ( 1 ) ;
878912 } ) ) ;
913+
914+ it ( 'should not open calendar with ALT + DOWN ARROW key if disabled is set to true' , fakeAsync ( ( ) => {
915+ fixture . componentInstance . disabled = true ;
916+ fixture . detectChanges ( ) ;
917+
918+ spyOn ( dateRange . onOpening , 'emit' ) . and . callThrough ( ) ;
919+ spyOn ( dateRange . onOpened , 'emit' ) . and . callThrough ( ) ;
920+
921+ UIInteractions . triggerEventHandlerKeyDown ( 'ArrowDown' , calendar , true ) ;
922+ tick ( DEBOUNCE_TIME * 2 ) ;
923+ fixture . detectChanges ( ) ;
924+ expect ( dateRange . collapsed ) . toBeTruthy ( ) ;
925+ expect ( dateRange . onOpening . emit ) . toHaveBeenCalledTimes ( 0 ) ;
926+ expect ( dateRange . onOpened . emit ) . toHaveBeenCalledTimes ( 0 ) ;
927+ } ) ) ;
879928 } ) ;
880929
881930 it ( 'should focus the last focused input after the calendar closes - dropdown' , fakeAsync ( ( ) => {
@@ -915,6 +964,24 @@ describe('IgxDateRangePicker', () => {
915964 . toBeTruthy ( ) ;
916965 } ) ) ;
917966
967+ it ( 'should expand the calendar if the default icon is clicked' , fakeAsync ( ( ) => {
968+ const icon = fixture . debugElement . query ( By . css ( 'igx-picker-toggle' ) ) ;
969+ icon . triggerEventHandler ( 'click' , UIInteractions . getMouseEvent ( 'click' ) ) ;
970+ tick ( ) ;
971+ fixture . detectChanges ( ) ;
972+ expect ( fixture . componentInstance . dateRange . collapsed ) . toBeFalsy ( ) ;
973+ } ) ) ;
974+
975+ it ( 'should not expand the calendar if the default icon is clicked when disabled is set to true' , fakeAsync ( ( ) => {
976+ fixture . componentInstance . disabled = true ;
977+ fixture . detectChanges ( ) ;
978+ const icon = fixture . debugElement . query ( By . css ( 'igx-picker-toggle' ) ) ;
979+ icon . triggerEventHandler ( 'click' , UIInteractions . getMouseEvent ( 'click' ) ) ;
980+ tick ( ) ;
981+ fixture . detectChanges ( ) ;
982+ expect ( fixture . componentInstance . dateRange . collapsed ) . toBeTruthy ( ) ;
983+ } ) ) ;
984+
918985 describe ( 'Data binding' , ( ) => {
919986 it ( 'should properly update component value with ngModel bound to projected inputs - #7353' , fakeAsync ( ( ) => {
920987 fixture = TestBed . createComponent ( DateRangeTwoInputsNgModelTestComponent ) ;
@@ -1065,6 +1132,7 @@ export class DateRangeTestComponent implements OnInit {
10651132 [ x : string ] : any ;
10661133 public doneButtonText : string ;
10671134 public mode : InteractionMode ;
1135+ public disabled = false ;
10681136 public minValue : Date | String ;
10691137 public maxValue : Date | String ;
10701138
@@ -1078,16 +1146,19 @@ export class DateRangeTestComponent implements OnInit {
10781146@Component ( {
10791147 selector : 'igx-date-range-single-input-test' ,
10801148 template : `
1081- <igx-date-range-picker [mode]="mode" [minValue]="minValue" [maxValue]="maxValue">
1149+ <igx-date-range-picker [mode]="mode" [disabled]="disabled" [ minValue]="minValue" [maxValue]="maxValue">
10821150 </igx-date-range-picker>
10831151 `
10841152} )
1085- export class DateRangeDefaultComponent extends DateRangeTestComponent { }
1153+ export class DateRangeDefaultComponent extends DateRangeTestComponent {
1154+ public disabled = false ;
1155+ }
10861156
10871157@Component ( {
10881158 selector : 'igx-date-range-two-inputs-test' ,
10891159 template : `
1090- <igx-date-range-picker [mode]="mode" [(ngModel)]="range" [inputFormat]="inputFormat" [displayFormat]="displayFormat" required>
1160+ <igx-date-range-picker [mode]="mode" [disabled]="disabled" [(ngModel)]="range"
1161+ [inputFormat]="inputFormat" [displayFormat]="displayFormat" required>
10911162 <igx-date-range-start>
10921163 <igx-picker-toggle igxPrefix>
10931164 <igx-icon>calendar_view_day</igx-icon>
@@ -1101,9 +1172,10 @@ export class DateRangeDefaultComponent extends DateRangeTestComponent { }
11011172`
11021173} )
11031174export class DateRangeTwoInputsTestComponent extends DateRangeTestComponent {
1104- range ;
1105- inputFormat : string ;
1106- displayFormat : string ;
1175+ public range ;
1176+ public inputFormat : string ;
1177+ public displayFormat : string ;
1178+ public disabled = false ;
11071179}
11081180@Component ( {
11091181 selector : 'igx-date-range-two-inputs-ng-model' ,
0 commit comments