Skip to content

Commit ec3b3e2

Browse files
test(time-picker): ensure view does not reset when clicking am/pm
1 parent 067f5d9 commit ec3b3e2

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

projects/igniteui-angular/src/lib/time-picker/time-picker.component.spec.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,6 @@ describe('IgxTimePicker', () => {
936936
expect(document.activeElement.children[3].innerHTML.trim()).toBe('10');
937937
});
938938

939-
940939
it('should navigate through items with arrow keys', () => {
941940
timePicker.itemsDelta = { hours: 4, minutes: 7, seconds: 1 };
942941
fixture.detectChanges();
@@ -1086,6 +1085,47 @@ describe('IgxTimePicker', () => {
10861085
expect(selectedMinutes).toEqual('00');
10871086
expect(selectedAMPM).toEqual('AM');
10881087
});
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 spinner
1127+
expect(minutesColumn.queryAll(By.css('span')).every(e => !!e.nativeElement.innerText));
1128+
}));
10891129
});
10901130

10911131
describe('Rendering tests', () => {

0 commit comments

Comments
 (0)