1
+ import { IgxLabelDirective } from './../directives/label/label.directive' ;
1
2
import { Component , ViewChild , NgModule , ElementRef , EventEmitter , DebugElement } from '@angular/core' ;
2
3
import { async , TestBed , fakeAsync , tick , ComponentFixture } from '@angular/core/testing' ;
3
4
import { FormsModule , FormGroup , FormBuilder , ReactiveFormsModule , Validators } from '@angular/forms' ;
@@ -46,6 +47,32 @@ describe('IgxTimePicker', () => {
46
47
expect ( domTimePicker . id ) . toBe ( 'customTimePicker' ) ;
47
48
} ) ) ;
48
49
50
+ it ( 'Should display default and custom label' , ( ( ) => {
51
+ const fixture = TestBed . createComponent ( IgxTimePickerCustomLabelComponent ) ;
52
+ const testComponent = fixture . componentInstance ;
53
+ testComponent . mode = InteractionMode . DropDown ;
54
+ fixture . detectChanges ( ) ;
55
+
56
+ const dom = fixture . debugElement ;
57
+ let label = dom . query ( By . directive ( IgxLabelDirective ) ) . nativeElement . innerText ;
58
+ expect ( label ) . toEqual ( 'Custom label' ) ;
59
+
60
+ testComponent . customLabel = false ;
61
+ fixture . detectChanges ( ) ;
62
+ label = dom . query ( By . directive ( IgxLabelDirective ) ) . nativeElement . innerText ;
63
+ expect ( label ) . toEqual ( 'Time' ) ;
64
+
65
+ testComponent . mode = InteractionMode . Dialog ;
66
+ fixture . detectChanges ( ) ;
67
+ label = dom . query ( By . directive ( IgxLabelDirective ) ) . nativeElement . innerText ;
68
+ expect ( label ) . toEqual ( 'Time' ) ;
69
+
70
+ testComponent . customLabel = true ;
71
+ fixture . detectChanges ( ) ;
72
+ label = dom . query ( By . directive ( IgxLabelDirective ) ) . nativeElement . innerText ;
73
+ expect ( label ) . toEqual ( 'Custom label' ) ;
74
+ } ) ) ;
75
+
49
76
it ( '@Input properties' , ( ( ) => {
50
77
const fixture = TestBed . createComponent ( IgxTimePickerWithPassedTimeComponent ) ;
51
78
fixture . detectChanges ( ) ;
@@ -1640,34 +1667,34 @@ describe('IgxTimePicker', () => {
1640
1667
} ) ) ;
1641
1668
1642
1669
it ( 'When timepicker is closed via outside click, the focus should NOT remain on the input' ,
1643
- fakeAsync ( ( ) => {
1644
- fixture . detectChanges ( ) ;
1645
- input = fixture . debugElement . query ( By . directive ( IgxInputDirective ) ) . nativeElement ;
1646
- let overlayToggle = document . getElementsByClassName ( 'igx-overlay__wrapper' ) ;
1670
+ fakeAsync ( ( ) => {
1671
+ fixture . detectChanges ( ) ;
1672
+ input = fixture . debugElement . query ( By . directive ( IgxInputDirective ) ) . nativeElement ;
1673
+ let overlayToggle = document . getElementsByClassName ( 'igx-overlay__wrapper' ) ;
1647
1674
1648
- expect ( overlayToggle . length ) . toEqual ( 0 ) ;
1675
+ expect ( overlayToggle . length ) . toEqual ( 0 ) ;
1649
1676
1650
- const iconTime = dom . queryAll ( By . css ( '.igx-icon' ) ) [ 0 ] ;
1651
- UIInteractions . simulateClickAndSelectEvent ( iconTime ) ;
1652
- tick ( ) ;
1653
- fixture . detectChanges ( ) ;
1677
+ const iconTime = dom . queryAll ( By . css ( '.igx-icon' ) ) [ 0 ] ;
1678
+ UIInteractions . simulateClickAndSelectEvent ( iconTime ) ;
1679
+ tick ( ) ;
1680
+ fixture . detectChanges ( ) ;
1654
1681
1655
- overlayToggle = document . getElementsByClassName ( 'igx-overlay__wrapper' ) ;
1656
- expect ( overlayToggle [ 0 ] ) . not . toBeNull ( ) ;
1657
- expect ( overlayToggle [ 0 ] ) . not . toBeUndefined ( ) ;
1682
+ overlayToggle = document . getElementsByClassName ( 'igx-overlay__wrapper' ) ;
1683
+ expect ( overlayToggle [ 0 ] ) . not . toBeNull ( ) ;
1684
+ expect ( overlayToggle [ 0 ] ) . not . toBeUndefined ( ) ;
1658
1685
1659
- const dummyInput = fixture . componentInstance . dummyInput . nativeElement ;
1660
- dummyInput . focus ( ) ;
1661
- dummyInput . click ( ) ;
1662
- tick ( ) ;
1663
- fixture . detectChanges ( ) ;
1686
+ const dummyInput = fixture . componentInstance . dummyInput . nativeElement ;
1687
+ dummyInput . focus ( ) ;
1688
+ dummyInput . click ( ) ;
1689
+ tick ( ) ;
1690
+ fixture . detectChanges ( ) ;
1664
1691
1665
- overlayToggle = document . getElementsByClassName ( 'igx-overlay__wrapper' ) ;
1666
- input = fixture . debugElement . query ( By . directive ( IgxInputDirective ) ) . nativeElement ;
1667
- expect ( overlayToggle [ 0 ] ) . toEqual ( undefined ) ;
1668
- expect ( input ) . not . toEqual ( document . activeElement ) ;
1669
- expect ( dummyInput ) . toEqual ( document . activeElement ) ;
1670
- } ) ) ;
1692
+ overlayToggle = document . getElementsByClassName ( 'igx-overlay__wrapper' ) ;
1693
+ input = fixture . debugElement . query ( By . directive ( IgxInputDirective ) ) . nativeElement ;
1694
+ expect ( overlayToggle [ 0 ] ) . toEqual ( undefined ) ;
1695
+ expect ( input ) . not . toEqual ( document . activeElement ) ;
1696
+ expect ( dummyInput ) . toEqual ( document . activeElement ) ;
1697
+ } ) ) ;
1671
1698
1672
1699
it ( 'should apply disabled style for time outside the min and max values' , fakeAsync ( ( ) => {
1673
1700
timePicker = new IgxTimePickerComponent ( null , null ) ;
@@ -2080,7 +2107,7 @@ describe('IgxTimePicker', () => {
2080
2107
2081
2108
expect ( inputDirective . valid ) . toEqual ( IgxInputState . INITIAL ) ;
2082
2109
2083
- inputDirectiveElement . triggerEventHandler ( 'focus' , { target : { value : null } } ) ;
2110
+ inputDirectiveElement . triggerEventHandler ( 'focus' , { target : { value : null } } ) ;
2084
2111
tick ( 16 ) ;
2085
2112
fixture . detectChanges ( ) ;
2086
2113
@@ -2094,7 +2121,7 @@ describe('IgxTimePicker', () => {
2094
2121
fixture . detectChanges ( ) ;
2095
2122
expect ( inputDirective . valid ) . toEqual ( IgxInputState . INITIAL ) ;
2096
2123
2097
- inputDirectiveElement . triggerEventHandler ( 'blur' , { target : { value : null } } ) ;
2124
+ inputDirectiveElement . triggerEventHandler ( 'blur' , { target : { value : null } } ) ;
2098
2125
fixture . detectChanges ( ) ;
2099
2126
2100
2127
expect ( inputDirective . valid ) . toEqual ( IgxInputState . INVALID ) ;
@@ -2132,7 +2159,7 @@ describe('IgxTimePicker', () => {
2132
2159
nativeElement : { getBoundingClientRect : ( ) => 0 } ,
2133
2160
style : { width : null }
2134
2161
} ;
2135
- cdr = { detectChanges : ( ) => { } } ;
2162
+ cdr = { detectChanges : ( ) => { } } ;
2136
2163
toggleRef = {
2137
2164
onOpened : new EventEmitter < any > ( ) ,
2138
2165
onClosed : new EventEmitter < any > ( ) ,
@@ -2147,7 +2174,7 @@ describe('IgxTimePicker', () => {
2147
2174
const timePicker = new IgxTimePickerComponent ( injector , cdr ) ;
2148
2175
timePicker [ '_inputGroup' ] = inputGroup ;
2149
2176
timePicker [ 'toggleRef' ] = toggleRef ;
2150
- ngModel . control . validator = ( ) => ( { required : true } ) ;
2177
+ ngModel . control . validator = ( ) => ( { required : true } ) ;
2151
2178
timePicker . ngOnInit ( ) ;
2152
2179
timePicker . ngAfterViewInit ( ) ;
2153
2180
timePicker . ngAfterViewChecked ( ) ;
@@ -2167,11 +2194,11 @@ describe('IgxTimePicker', () => {
2167
2194
expect ( timePicker ) . toBeDefined ( ) ;
2168
2195
expect ( inputGroup . isRequired ) . toBeFalsy ( ) ;
2169
2196
2170
- ngModel . control . validator = ( ) => ( { required : true } ) ;
2197
+ ngModel . control . validator = ( ) => ( { required : true } ) ;
2171
2198
ngModel . statusChanges . emit ( ) ;
2172
2199
expect ( inputGroup . isRequired ) . toBeTruthy ( ) ;
2173
2200
2174
- ngModel . control . validator = ( ) => ( { required : false } ) ;
2201
+ ngModel . control . validator = ( ) => ( { required : false } ) ;
2175
2202
ngModel . statusChanges . emit ( ) ;
2176
2203
expect ( inputGroup . isRequired ) . toBeFalsy ( ) ;
2177
2204
} ) ;
@@ -2286,6 +2313,19 @@ export class IgxTimePickerWithItemsDeltaValueComponent {
2286
2313
} )
2287
2314
export class IgxTimePickerRetemplatedComponent { }
2288
2315
2316
+ @Component ( {
2317
+ template : `
2318
+ <igx-time-picker [mode]="mode">
2319
+ <label igxLabel *ngIf="customLabel">Custom label</label>
2320
+ </igx-time-picker>
2321
+ `
2322
+ } )
2323
+ export class IgxTimePickerCustomLabelComponent {
2324
+ public customLabel = true ;
2325
+ public mode = InteractionMode . DropDown ;
2326
+ }
2327
+
2328
+
2289
2329
@Component ( {
2290
2330
template : `
2291
2331
<input class="dummyInput" #dummyInput/>
@@ -2395,7 +2435,7 @@ export class IgxTimePickerReactiveFormComponent {
2395
2435
constructor ( fb : FormBuilder ) {
2396
2436
this . reactiveForm = fb . group ( {
2397
2437
timePickerOnChange : [ null , Validators . required ] ,
2398
- timePickerOnBlur : [ null , { updateOn : 'blur' , validators : Validators . required } ]
2438
+ timePickerOnBlur : [ null , { updateOn : 'blur' , validators : Validators . required } ]
2399
2439
} ) ;
2400
2440
}
2401
2441
onSubmitReactive ( ) { }
@@ -2417,7 +2457,8 @@ export class IgxTimePickerReactiveFormComponent {
2417
2457
IgxTimePickerDropDownNoValueComponent ,
2418
2458
IgxTimePickerRetemplatedDropDownComponent ,
2419
2459
IgxTimePickerWithOutletComponent ,
2420
- IgxTimePickerReactiveFormComponent
2460
+ IgxTimePickerReactiveFormComponent ,
2461
+ IgxTimePickerCustomLabelComponent
2421
2462
] ,
2422
2463
imports : [
2423
2464
IgxTimePickerModule ,
0 commit comments