@@ -36,7 +36,6 @@ const CSS_CLASS_SECONDSLIST = '.igx-time-picker__secondsList';
3636const CSS_CLASS_AMPMLIST = 'igx-time-picker__ampmList' ;
3737const CSS_CLASS_SELECTED_ITEM = '.igx-time-picker__item--selected' ;
3838const CSS_CLASS_HEADER_HOUR = '.igx-time-picker__header-hour' ;
39- const CSS_CLASS_OVERLAY = 'igx-overlay' ;
4039const CSS_CLASS_OVERLAY_WRAPPER = 'igx-overlay__wrapper' ;
4140const TIME_PICKER_TOGGLE_ICON = 'access_time' ;
4241const TIME_PICKER_CLEAR_ICON = 'clear' ;
@@ -937,7 +936,6 @@ describe('IgxTimePicker', () => {
937936 expect ( document . activeElement . children [ 3 ] . innerHTML . trim ( ) ) . toBe ( '10' ) ;
938937 } ) ;
939938
940-
941939 it ( 'should navigate through items with arrow keys' , ( ) => {
942940 timePicker . itemsDelta = { hours : 4 , minutes : 7 , seconds : 1 } ;
943941 fixture . detectChanges ( ) ;
@@ -1087,6 +1085,51 @@ describe('IgxTimePicker', () => {
10871085 expect ( selectedMinutes ) . toEqual ( '00' ) ;
10881086 expect ( selectedAMPM ) . toEqual ( 'AM' ) ;
10891087 } ) ;
1088+
1089+ it ( 'should not reset the time when clicking on AM/PM - GH#15158' , fakeAsync ( ( ) => {
1090+ timePicker . itemsDelta = { hours : 1 , minutes : 15 , seconds : 1 } ;
1091+ timePicker . mode = "dialog" ;
1092+
1093+ timePicker . open ( ) ;
1094+ fixture . detectChanges ( ) ;
1095+
1096+ const amElement = ampmColumn . query ( e => e . nativeElement . textContent === 'AM' ) ;
1097+ const pmElement = ampmColumn . query ( e => e . nativeElement . textContent === 'PM' ) ;
1098+
1099+ UIInteractions . simulateClickEvent ( amElement . nativeElement ) ;
1100+ fixture . detectChanges ( ) ;
1101+
1102+ let selectedItems = fixture . debugElement . queryAll ( By . css ( CSS_CLASS_SELECTED_ITEM ) ) ;
1103+ let selectedHour = selectedItems [ 0 ] . nativeElement . innerText ;
1104+ let selectedMinutes = selectedItems [ 1 ] . nativeElement . innerText ;
1105+ let selectedAMPM = selectedItems [ 2 ] . nativeElement . innerText ;
1106+
1107+ expect ( selectedHour ) . toBe ( '11' ) ;
1108+ expect ( selectedMinutes ) . toEqual ( '45' ) ;
1109+ expect ( selectedAMPM ) . toEqual ( 'AM' ) ;
1110+
1111+ UIInteractions . simulateClickEvent ( pmElement . nativeElement ) ; // move to the PM element
1112+ fixture . detectChanges ( ) ;
1113+ UIInteractions . simulateClickEvent ( pmElement . nativeElement ) ; // click again to reproduce the issue
1114+ fixture . detectChanges ( ) ;
1115+
1116+ selectedItems = fixture . debugElement . queryAll ( By . css ( CSS_CLASS_SELECTED_ITEM ) ) ;
1117+ selectedHour = selectedItems [ 0 ] . nativeElement . innerText ;
1118+ selectedMinutes = selectedItems [ 1 ] . nativeElement . innerText ;
1119+
1120+ expect ( selectedItems [ 2 ] ) . toBeDefined ( ) ; // if the minutes column has no elements, this will be undefined
1121+ selectedAMPM = selectedItems [ 2 ] . nativeElement . innerText ;
1122+ expect ( selectedHour ) . toBe ( '11' ) ;
1123+ expect ( selectedMinutes ) . toEqual ( '45' ) ;
1124+ expect ( selectedAMPM ) . toEqual ( 'PM' ) ;
1125+
1126+ // ensure there is content in each element of the spinners
1127+ // '08', '09', '10', '11', '12', '01', '02'
1128+ expect ( hourColumn . queryAll ( By . css ( 'span' ) ) . every ( e => ! ! e . nativeElement . innerText ) ) . toBeTrue ( ) ;
1129+
1130+ // '00', '15', '30', '45', '', '', '' - three empty elements to align the minutes spinner length with the hours spinner length
1131+ expect ( minutesColumn . queryAll ( By . css ( 'span' ) ) . filter ( e => ! ! e . nativeElement . innerText ) . length ) . toEqual ( 4 ) ;
1132+ } ) ) ;
10901133 } ) ;
10911134
10921135 describe ( 'Rendering tests' , ( ) => {
0 commit comments