@@ -860,15 +860,59 @@ describe('IgxTimePicker', () => {
860
860
tick ( ) ;
861
861
} ) ) ;
862
862
863
- it ( 'TimePicker with retemplated input group (icon removed)' , ( async ( ) => {
863
+ it ( 'TimePicker with retemplated input group (icon removed)' , fakeAsync ( ( ) => {
864
864
const fixture = TestBed . createComponent ( IgxTimePickerRetemplatedComponent ) ;
865
- wait ( ) ;
865
+ tick ( ) ;
866
866
fixture . detectChanges ( ) ;
867
867
868
868
const dom = fixture . debugElement ;
869
869
expect ( dom . query ( By . css ( '.igx-input-group' ) ) ) . not . toBeNull ( ) ;
870
870
expect ( dom . query ( By . css ( '.igx-icon' ) ) ) . toBeNull ( ) ;
871
871
} ) ) ;
872
+
873
+ // https://github.com/IgniteUI/igniteui-angular/issues/2470
874
+ it ( 'TimePicker always use date from value' , fakeAsync ( ( ) => {
875
+ const fixture = TestBed . createComponent ( IgxTimePickerWithPassedTimeComponent ) ;
876
+ tick ( ) ;
877
+ fixture . detectChanges ( ) ;
878
+ const dom = fixture . debugElement ;
879
+
880
+ const initialValue = ( fixture . componentInstance . timePicker . value ) ;
881
+ const initialDate = getDateStringFromDateObject ( initialValue ) ;
882
+ const initialTime = initialValue . getHours ( ) + ':' + initialValue . getMinutes ( ) ;
883
+
884
+ const timePickerTarget = dom . query ( By . directive ( IgxInputDirective ) ) ;
885
+ UIInteractions . clickElement ( timePickerTarget ) ;
886
+ tick ( 100 ) ;
887
+ fixture . detectChanges ( ) ;
888
+
889
+ const hourColumn = dom . query ( By . css ( '.igx-time-picker__hourList' ) ) ;
890
+ const selectHour = hourColumn . children [ 5 ] ;
891
+
892
+ const minutesColumn = dom . query ( By . css ( '.igx-time-picker__minuteList' ) ) ;
893
+ const selectMinutes = minutesColumn . children [ 2 ] ;
894
+
895
+ UIInteractions . clickElement ( selectHour ) ;
896
+ fixture . detectChanges ( ) ;
897
+ tick ( 100 ) ;
898
+ UIInteractions . clickElement ( selectMinutes ) ;
899
+ fixture . detectChanges ( ) ;
900
+ tick ( 100 ) ;
901
+
902
+ const OkButton = dom . queryAll ( By . css ( '.igx-button--flat' ) ) [ 1 ] ;
903
+ UIInteractions . clickElement ( OkButton ) ;
904
+ fixture . detectChanges ( ) ;
905
+ tick ( 100 ) ;
906
+
907
+ const changedValue = ( fixture . componentInstance . timePicker . value ) ;
908
+ const changedDate = getDateStringFromDateObject ( changedValue ) ;
909
+ const changedTime = changedValue . getHours ( ) + ':' + changedValue . getMinutes ( ) ;
910
+
911
+ expect ( initialDate ) . toEqual ( changedDate ) ;
912
+ expect ( initialTime ) . not . toEqual ( changedTime ) ;
913
+ expect ( changedTime ) . toEqual ( '5:23' ) ;
914
+
915
+ } ) ) ;
872
916
} ) ;
873
917
874
918
@Component ( {
@@ -986,3 +1030,11 @@ function findByInnerText(collection, searchText) {
986
1030
}
987
1031
}
988
1032
}
1033
+
1034
+ function getDateStringFromDateObject ( date : Date ) : string {
1035
+ const month = date . getMonth ( ) + 1 ;
1036
+ const day = date . getDate ( ) ;
1037
+ const year = date . getFullYear ( ) ;
1038
+
1039
+ return year + '/' + month + '/' + day ;
1040
+ }
0 commit comments