11import { ComponentFixture , TestBed , fakeAsync , tick , waitForAsync , flush } from '@angular/core/testing' ;
2- import { Component , OnInit , ViewChild , DebugElement , ChangeDetectionStrategy , inject } from '@angular/core' ;
2+ import { Component , OnInit , ViewChild , DebugElement , ChangeDetectionStrategy , inject , ApplicationRef , NgZone , DOCUMENT , ChangeDetectorRef , ElementRef } from '@angular/core' ;
33import { IgxInputDirective , IgxInputState , IgxLabelDirective , IgxPrefixDirective , IgxSuffixDirective } from '../input-group/public_api' ;
44import { PickerInteractionMode } from '../date-common/types' ;
55import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
@@ -8,13 +8,13 @@ import { By } from '@angular/platform-browser';
88import { ControlsFunction } from '../test-utils/controls-functions.spec' ;
99import { UIInteractions } from '../test-utils/ui-interactions.spec' ;
1010import { HelperTestFunctions } from '../test-utils/calendar-helper-utils' ;
11- import { CancelableEventArgs } from '../core/utils' ;
11+ import { CancelableEventArgs , PlatformUtil } from '../core/utils' ;
1212import { DateRange , IgxDateRangeSeparatorDirective , IgxDateRangeStartComponent } from './date-range-picker-inputs.common' ;
1313import { IgxDateTimeEditorDirective } from '../directives/date-time-editor/public_api' ;
1414import { DateRangeType } from '../core/dates' ;
1515import { IgxDateRangePickerComponent , IgxDateRangeEndComponent } from './public_api' ;
1616import { AutoPositionStrategy , IgxOverlayService } from '../services/public_api' ;
17- import { AnimationMetadata , AnimationOptions } from '@angular/animations' ;
17+ import { AnimationBuilder , AnimationMetadata , AnimationOptions } from '@angular/animations' ;
1818import { IgxCalendarComponent , WEEKDAYS } from '../calendar/public_api' ;
1919import { Subject } from 'rxjs' ;
2020import { AsyncPipe } from '@angular/common' ;
@@ -25,6 +25,7 @@ import { IgxIconComponent } from '../icon/icon.component';
2525import { registerLocaleData } from "@angular/common" ;
2626import localeJa from "@angular/common/locales/ja" ;
2727import localeBg from "@angular/common/locales/bg" ;
28+ import { KeyboardNavigationService } from '../calendar/calendar.services' ;
2829
2930// The number of milliseconds in one day
3031const DEBOUNCE_TIME = 16 ;
@@ -48,18 +49,9 @@ const CSS_CLASS_INACTIVE_DATE = 'igx-days-view__date--inactive';
4849describe ( 'IgxDateRangePicker' , ( ) => {
4950 describe ( 'Unit tests: ' , ( ) => {
5051 let mockElement : any ;
51- let mockApplicationRef : any ;
52- let mockAnimationBuilder : any ;
53- let mockDocument : any ;
54- let mockNgZone : any ;
55- let mockPlatformUtil : any ;
56- let overlay : IgxOverlayService ;
57- let mockInjector ;
5852 let mockCalendar : IgxCalendarComponent ;
5953 let mockDaysView : any ;
60- let mockAnimationService : AnimationService ;
6154 const elementRef = { nativeElement : null } ;
62- const platform = { } as any ;
6355 const mockNgControl = jasmine . createSpyObj ( 'NgControl' ,
6456 [ 'registerOnChangeCb' ,
6557 'registerOnTouchedCb' ,
@@ -79,54 +71,21 @@ describe('IgxDateRangePicker', () => {
7971 } ;
8072 mockElement . parent = mockElement ;
8173 mockElement . parentElement = mockElement ;
82- mockApplicationRef = { attachView : ( h : any ) => { } , detachView : ( h : any ) => { } } ;
83- mockInjector = jasmine . createSpyObj ( 'Injector' , {
84- get : mockNgControl
74+
75+ TestBed . configureTestingModule ( {
76+ imports : [ NoopAnimationsModule ] ,
77+ providers : [
78+ { provide : ElementRef , useValue : elementRef } ,
79+ IgxAngularAnimationService ,
80+ IgxOverlayService ,
81+ IgxCalendarComponent ,
82+ KeyboardNavigationService ,
83+ ChangeDetectorRef ,
84+ IgxDateRangePickerComponent
85+ ]
8586 } ) ;
86- mockAnimationBuilder = {
87- build : ( a : AnimationMetadata | AnimationMetadata [ ] ) => ( {
88- create : ( e : any , opt ?: AnimationOptions ) => ( {
89- onDone : ( fn : any ) => { } ,
90- onStart : ( fn : any ) => { } ,
91- onDestroy : ( fn : any ) => { } ,
92- init : ( ) => { } ,
93- hasStarted : ( ) => true ,
94- play : ( ) => { } ,
95- pause : ( ) => { } ,
96- restart : ( ) => { } ,
97- finish : ( ) => { } ,
98- destroy : ( ) => { } ,
99- rest : ( ) => { } ,
100- setPosition : ( p : any ) => { } ,
101- getPosition : ( ) => 0 ,
102- parentPlayer : { } ,
103- totalTime : 0 ,
104- beforeDestroy : ( ) => { } ,
105- _renderer : {
106- engine : {
107- players : [
108- { }
109- ]
110- }
111- }
112- } )
113- } )
114- } ;
115- mockDocument = {
116- body : mockElement ,
117- defaultView : mockElement ,
118- documentElement : document . documentElement ,
119- createElement : ( ) => mockElement ,
120- appendChild : ( ) => { } ,
121- addEventListener : ( type : string , listener : ( this : HTMLElement , ev : MouseEvent ) => any ) => { } ,
122- removeEventListener : ( type : string , listener : ( this : HTMLElement , ev : MouseEvent ) => any ) => { }
123- } ;
124- mockNgZone = { } ;
125- mockPlatformUtil = { isIOS : false } ;
126- mockAnimationService = new IgxAngularAnimationService ( mockAnimationBuilder ) ;
127- overlay = new IgxOverlayService (
128- mockApplicationRef , mockDocument , mockNgZone , mockPlatformUtil , mockAnimationService ) ;
129- mockCalendar = new IgxCalendarComponent ( platform , 'en' ) ;
87+
88+ mockCalendar = TestBed . inject ( IgxCalendarComponent ) ;
13089
13190 mockDaysView = {
13291 focusActiveDate : jasmine . createSpy ( )
@@ -135,7 +94,7 @@ describe('IgxDateRangePicker', () => {
13594 } ) ;
13695 /* eslint-enable @typescript-eslint/no-unused-vars */
13796 it ( 'should set range dates correctly through selectRange method' , ( ) => {
138- const dateRange = new IgxDateRangePickerComponent ( elementRef , 'en-US' , platform , null , null , null , null ) ;
97+ const dateRange = TestBed . inject ( IgxDateRangePickerComponent ) ;
13998 // dateRange.calendar = calendar;
14099 let startDate = new Date ( 2020 , 3 , 7 ) ;
141100 const endDate = new Date ( 2020 , 6 , 27 ) ;
@@ -153,7 +112,7 @@ describe('IgxDateRangePicker', () => {
153112 } ) ;
154113
155114 it ( 'should emit valueChange on selection' , ( ) => {
156- const dateRange = new IgxDateRangePickerComponent ( elementRef , 'en-US' , platform , null , null , null , null ) ;
115+ const dateRange = TestBed . inject ( IgxDateRangePickerComponent ) ;
157116 // dateRange.calendar = calendar;
158117 spyOn ( dateRange . valueChange , 'emit' ) ;
159118 let startDate = new Date ( 2017 , 4 , 5 ) ;
@@ -180,7 +139,7 @@ describe('IgxDateRangePicker', () => {
180139 const rangeUpdate = { start : new Date ( 2020 , 2 , 22 ) , end : new Date ( 2020 , 2 , 25 ) } ;
181140
182141 // init
183- const dateRangePicker = new IgxDateRangePickerComponent ( null , 'en' , platform , null , null , null , null ) ;
142+ const dateRangePicker = TestBed . inject ( IgxDateRangePickerComponent ) ;
184143 dateRangePicker . registerOnChange ( mockNgControl . registerOnChangeCb ) ;
185144 dateRangePicker . registerOnTouched ( mockNgControl . registerOnTouchedCb ) ;
186145 spyOn ( dateRangePicker as any , 'handleSelection' ) . and . callThrough ( ) ;
@@ -214,7 +173,7 @@ describe('IgxDateRangePicker', () => {
214173 } ) ;
215174
216175 it ( 'should validate correctly minValue and maxValue' , ( ) => {
217- const dateRange = new IgxDateRangePickerComponent ( elementRef , 'en-US' , platform , mockInjector , null , null , null ) ;
176+ const dateRange = TestBed . inject ( IgxDateRangePickerComponent ) ;
218177 dateRange . ngOnInit ( ) ;
219178
220179 // dateRange.calendar = calendar;
@@ -239,7 +198,7 @@ describe('IgxDateRangePicker', () => {
239198 } ) ;
240199
241200 it ( 'should disable calendar dates when min and/or max values as dates are provided' , ( ) => {
242- const dateRange = new IgxDateRangePickerComponent ( elementRef , 'en-US' , platform , mockInjector , null , overlay ) ;
201+ const dateRange = TestBed . inject ( IgxDateRangePickerComponent ) ;
243202 dateRange . ngOnInit ( ) ;
244203
245204 spyOnProperty ( ( dateRange as any ) , 'calendar' ) . and . returnValue ( mockCalendar ) ;
@@ -255,7 +214,7 @@ describe('IgxDateRangePicker', () => {
255214 } ) ;
256215
257216 it ( 'should disable calendar dates when min and/or max values as strings are provided' , fakeAsync ( ( ) => {
258- const dateRange = new IgxDateRangePickerComponent ( elementRef , 'en' , platform , mockInjector , null , null , null ) ;
217+ const dateRange = TestBed . inject ( IgxDateRangePickerComponent ) ;
259218 dateRange . ngOnInit ( ) ;
260219
261220 spyOnProperty ( ( dateRange as any ) , 'calendar' ) . and . returnValue ( mockCalendar ) ;
@@ -687,7 +646,7 @@ describe('IgxDateRangePicker', () => {
687646 . withContext ( 'focus should return to the picker input' )
688647 . toBeTrue ( ) ;
689648 expect ( dateRange . isFocused ) . toBeTrue ( ) ;
690- } ) ) ;
649+ } ) ) ;
691650
692651 it ( 'should not open calendar with ALT + DOWN ARROW key if disabled is set to true' , fakeAsync ( ( ) => {
693652 fixture . componentInstance . mode = PickerInteractionMode . DropDown ;
@@ -1791,8 +1750,8 @@ export class DateRangeTwoInputsDisabledComponent extends DateRangeDisabledCompon
17911750export class DateRangeReactiveFormComponent {
17921751 private fb = inject ( UntypedFormBuilder ) ;
17931752
1794- @ViewChild ( 'range' , { read : IgxDateRangePickerComponent } ) public dateRange : IgxDateRangePickerComponent ;
1795- @ViewChild ( 'twoInputs' , { read : IgxDateRangePickerComponent } ) public dateRangeWithTwoInputs : IgxDateRangePickerComponent ;
1753+ @ViewChild ( 'range' , { read : IgxDateRangePickerComponent } ) public dateRange : IgxDateRangePickerComponent ;
1754+ @ViewChild ( 'twoInputs' , { read : IgxDateRangePickerComponent } ) public dateRangeWithTwoInputs : IgxDateRangePickerComponent ;
17961755
17971756 public form = this . fb . group ( {
17981757 range : [ '' , Validators . required ] ,
0 commit comments