1
1
import { ComponentFixture , TestBed , fakeAsync , tick , waitForAsync , flush } from '@angular/core/testing' ;
2
- import { Component , OnInit , ViewChild , DebugElement } from '@angular/core' ;
2
+ import { Component , OnInit , ViewChild , DebugElement , ChangeDetectionStrategy } from '@angular/core' ;
3
3
import { IgxInputGroupModule } from '../input-group/public_api' ;
4
4
import { PickerInteractionMode } from '../date-common/types' ;
5
5
import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
@@ -21,6 +21,8 @@ import { AnimationMetadata, AnimationOptions } from '@angular/animations';
21
21
import { IgxPickersCommonModule } from '../date-common/public_api' ;
22
22
import { IgxCalendarContainerComponent , IgxCalendarContainerModule } from '../date-common/calendar-container/calendar-container.component' ;
23
23
import { IgxCalendarComponent } from '../calendar/public_api' ;
24
+ import { Subject } from 'rxjs' ;
25
+ import { CommonModule } from '@angular/common' ;
24
26
25
27
// The number of milliseconds in one day
26
28
const ONE_DAY = 1000 * 60 * 60 * 24 ;
@@ -224,7 +226,7 @@ describe('IgxDateRangePicker', () => {
224
226
} ) ;
225
227
226
228
it ( 'should validate correctly minValue and maxValue' , ( ) => {
227
- const dateRange = new IgxDateRangePickerComponent ( elementRef , null , platform , mockInjector , null , null ) ;
229
+ const dateRange = new IgxDateRangePickerComponent ( elementRef , null , platform , mockInjector , null , null , null ) ;
228
230
dateRange . ngOnInit ( ) ;
229
231
230
232
// dateRange.calendar = calendar;
@@ -249,7 +251,7 @@ describe('IgxDateRangePicker', () => {
249
251
} ) ;
250
252
251
253
it ( 'should disable calendar dates when min and/or max values as dates are provided' , ( ) => {
252
- const dateRange = new IgxDateRangePickerComponent ( elementRef , 'en-US' , platform , mockInjector , ngModuleRef , overlay ) ;
254
+ const dateRange = new IgxDateRangePickerComponent ( elementRef , 'en-US' , platform , mockInjector , ngModuleRef , null , overlay ) ;
253
255
dateRange . ngOnInit ( ) ;
254
256
255
257
spyOnProperty ( ( dateRange as any ) , 'calendar' ) . and . returnValue ( mockCalendar ) ;
@@ -275,7 +277,7 @@ describe('IgxDateRangePicker', () => {
275
277
} ) ;
276
278
277
279
it ( 'should disable calendar dates when min and/or max values as strings are provided' , fakeAsync ( ( ) => {
278
- const dateRange = new IgxDateRangePickerComponent ( elementRef , null , platform , mockInjector , null , null ) ;
280
+ const dateRange = new IgxDateRangePickerComponent ( elementRef , null , platform , mockInjector , null , null , null ) ;
279
281
dateRange . ngOnInit ( ) ;
280
282
281
283
spyOnProperty ( ( dateRange as any ) , 'calendar' ) . and . returnValue ( mockCalendar ) ;
@@ -332,17 +334,19 @@ describe('IgxDateRangePicker', () => {
332
334
TestBed . configureTestingModule ( {
333
335
declarations : [
334
336
DateRangeTestComponent ,
335
- DateRangeDefaultComponent
337
+ DateRangeDefaultComponent ,
338
+ DateRangeDisabledComponent
336
339
] ,
337
340
imports : [
341
+ CommonModule ,
338
342
IgxDateRangePickerModule ,
339
343
IgxDateTimeEditorModule ,
340
344
IgxInputGroupModule ,
341
345
IgxIconModule ,
342
346
FormsModule ,
343
347
NoopAnimationsModule ,
344
348
IgxPickersCommonModule ,
345
- IgxCalendarContainerModule ,
349
+ IgxCalendarContainerModule
346
350
]
347
351
} )
348
352
. compileComponents ( ) ;
@@ -732,6 +736,28 @@ describe('IgxDateRangePicker', () => {
732
736
fixture . detectChanges ( ) ;
733
737
expect ( fixture . componentInstance . dateRange . collapsed ) . toBeTruthy ( ) ;
734
738
} ) ) ;
739
+
740
+ it ( 'should properly set/update disabled when ChangeDetectionStrategy.OnPush is used' , fakeAsync ( ( ) => {
741
+ const testFixture = TestBed
742
+ . createComponent ( DateRangeDisabledComponent ) as ComponentFixture < DateRangeDisabledComponent > ;
743
+ testFixture . detectChanges ( ) ;
744
+ dateRange = testFixture . componentInstance . dateRange ;
745
+ const disabled$ = testFixture . componentInstance . disabled$ ;
746
+
747
+ disabled$ . next ( true ) ;
748
+ testFixture . detectChanges ( ) ;
749
+ expect ( dateRange . inputDirective . disabled ) . toBeTrue ( ) ;
750
+
751
+ disabled$ . next ( false ) ;
752
+ testFixture . detectChanges ( ) ;
753
+ expect ( dateRange . inputDirective . disabled ) . toBeFalse ( ) ;
754
+
755
+ disabled$ . next ( true ) ;
756
+ testFixture . detectChanges ( ) ;
757
+ expect ( dateRange . inputDirective . disabled ) . toBeTrue ( ) ;
758
+
759
+ disabled$ . complete ( ) ;
760
+ } ) ) ;
735
761
} ) ;
736
762
737
763
describe ( 'Two Inputs' , ( ) => {
@@ -743,9 +769,12 @@ describe('IgxDateRangePicker', () => {
743
769
declarations : [
744
770
DateRangeTestComponent ,
745
771
DateRangeTwoInputsTestComponent ,
746
- DateRangeTwoInputsNgModelTestComponent
772
+ DateRangeTwoInputsNgModelTestComponent ,
773
+ DateRangeDisabledComponent ,
774
+ DateRangeTwoInputsDisabledComponent
747
775
] ,
748
776
imports : [
777
+ CommonModule ,
749
778
IgxDateRangePickerModule ,
750
779
IgxDateTimeEditorModule ,
751
780
IgxPickersCommonModule ,
@@ -1116,6 +1145,31 @@ describe('IgxDateRangePicker', () => {
1116
1145
expect ( fixture . componentInstance . dateRange . collapsed ) . toBeTruthy ( ) ;
1117
1146
} ) ) ;
1118
1147
1148
+ it ( 'should properly set/update disabled when ChangeDetectionStrategy.OnPush is used' , fakeAsync ( ( ) => {
1149
+ const testFixture = TestBed
1150
+ . createComponent ( DateRangeTwoInputsDisabledComponent ) as ComponentFixture < DateRangeTwoInputsDisabledComponent > ;
1151
+ testFixture . detectChanges ( ) ;
1152
+ dateRange = testFixture . componentInstance . dateRange ;
1153
+ const disabled$ = testFixture . componentInstance . disabled$ ;
1154
+
1155
+ disabled$ . next ( true ) ;
1156
+ testFixture . detectChanges ( ) ;
1157
+ expect ( dateRange . projectedInputs . first . inputDirective . disabled ) . toBeTrue ( ) ;
1158
+ expect ( dateRange . projectedInputs . last . inputDirective . disabled ) . toBeTrue ( ) ;
1159
+
1160
+ disabled$ . next ( false ) ;
1161
+ testFixture . detectChanges ( ) ;
1162
+ expect ( dateRange . projectedInputs . first . inputDirective . disabled ) . toBeFalse ( ) ;
1163
+ expect ( dateRange . projectedInputs . last . disabled ) . toBeFalse ( ) ;
1164
+
1165
+ disabled$ . next ( true ) ;
1166
+ testFixture . detectChanges ( ) ;
1167
+ expect ( dateRange . projectedInputs . first . inputDirective . disabled ) . toBeTrue ( ) ;
1168
+ expect ( dateRange . projectedInputs . last . inputDirective . disabled ) . toBeTrue ( ) ;
1169
+
1170
+ disabled$ . complete ( ) ;
1171
+ } ) ) ;
1172
+
1119
1173
describe ( 'Data binding' , ( ) => {
1120
1174
it ( 'should properly update component value with ngModel bound to projected inputs - #7353' , fakeAsync ( ( ) => {
1121
1175
fixture = TestBed . createComponent ( DateRangeTwoInputsNgModelTestComponent ) ;
@@ -1417,3 +1471,30 @@ export class DateRangeCustomComponent extends DateRangeTestComponent {
1417
1471
export class DateRangeTemplatesComponent extends DateRangeTestComponent {
1418
1472
public range ;
1419
1473
}
1474
+
1475
+ @Component ( {
1476
+ template : `<igx-date-range-picker [disabled]="(disabled$ | async) === true"></igx-date-range-picker>` ,
1477
+ changeDetection : ChangeDetectionStrategy . OnPush
1478
+ } )
1479
+ export class DateRangeDisabledComponent extends DateRangeTestComponent {
1480
+ public disabled$ = new Subject < boolean > ( ) ;
1481
+
1482
+ constructor ( ) {
1483
+ super ( ) ;
1484
+ this . disabled$ . subscribe ( { next : ( v ) => v } ) ;
1485
+ }
1486
+ }
1487
+
1488
+ @Component ( {
1489
+ template : `
1490
+ <igx-date-range-picker [disabled]="(disabled$ | async) === true">
1491
+ <igx-date-range-start>
1492
+ <input igxInput igxDateTimeEditor>
1493
+ </igx-date-range-start>
1494
+ <igx-date-range-end>
1495
+ <input igxInput igxDateTimeEditor>
1496
+ </igx-date-range-end>
1497
+ </igx-date-range-picker>` ,
1498
+ changeDetection : ChangeDetectionStrategy . OnPush
1499
+ } )
1500
+ export class DateRangeTwoInputsDisabledComponent extends DateRangeDisabledComponent { }
0 commit comments