Skip to content

Commit 3fb2aa8

Browse files
committed
test(time-picker): add test for non-zero padded format
1 parent e09c7a8 commit 3fb2aa8

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,29 @@ describe('IgxTimePicker', () => {
969969
expect(selectedAMPM).toEqual(ampm);
970970
}));
971971

972+
it('should display correctly non-zero padded time format', fakeAsync(() => {
973+
fixture.componentInstance.date = new Date(2021, 24, 2, 8, 5, 5);
974+
fixture.componentInstance.timePicker.mode = PickerInteractionMode.DropDown;
975+
timePicker.inputFormat = 'h:m:s';
976+
fixture.detectChanges();
977+
978+
timePicker.open();
979+
tick();
980+
fixture.detectChanges();
981+
982+
const selectedItems = fixture.debugElement.queryAll(By.css(CSS_CLASS_SELECTED_ITEM));
983+
const selectedHour = selectedItems[0].nativeElement.innerText;
984+
const selectedMinutes = selectedItems[1].nativeElement.innerText;
985+
const selectedAMPM = selectedItems[2].nativeElement.innerText;
986+
987+
const hours = fixture.componentInstance.date.getHours();
988+
const minutes = fixture.componentInstance.date.getMinutes();
989+
const seconds = fixture.componentInstance.date.getSeconds();
990+
991+
expect(selectedHour).toEqual(hours.toString());
992+
expect(selectedMinutes).toEqual(minutes.toString());
993+
expect(selectedAMPM).toEqual(seconds.toString());
994+
}));
972995

973996
it('should display selected time in dialog header', fakeAsync(() => {
974997
fixture.componentInstance.timePicker.mode = PickerInteractionMode.Dialog;

projects/igniteui-angular/src/lib/time-picker/time-picker.directives.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -264,29 +264,18 @@ export class IgxTimeItemDirective {
264264
}
265265

266266
public get isSelectedTime(): boolean {
267-
let currentValue = this.value;
268-
const time = parseInt(currentValue, 10);
267+
const currentValue = this.value.length < 2 ? `0${this.value}` : this.value;
269268
const dateType = this.itemList.type;
270269
const inputDateParts = DateTimeUtil.parseDateTimeFormat(this.timePicker.inputFormat);
271270
switch (dateType) {
272271
case 'hourList':
273272
const hourPart = inputDateParts.find(element => element.type === 'hours');
274-
if (time < 10 && this.timePicker.inputFormat.indexOf('hh') === - 1 && this.timePicker.inputFormat.indexOf('HH') === - 1) {
275-
currentValue = `0${currentValue}`;
276-
}
277-
console.log(currentValue);
278273
return DateTimeUtil.getPartValue(this.timePicker.selectedDate, hourPart, hourPart.format.length) === currentValue;
279274
case 'minuteList':
280275
const minutePart = inputDateParts.find(element => element.type === 'minutes');
281-
if (time < 10 && this.timePicker.inputFormat.indexOf('mm') === - 1) {
282-
currentValue = `0${currentValue}`;
283-
}
284276
return DateTimeUtil.getPartValue(this.timePicker.selectedDate, minutePart, minutePart.format.length) === currentValue;
285277
case 'secondsList':
286278
const secondsPart = inputDateParts.find(element => element.type === 'seconds');
287-
if (time < 10 && this.timePicker.inputFormat.indexOf('ss') === - 1) {
288-
currentValue = `0${currentValue}`;
289-
}
290279
return DateTimeUtil.getPartValue(this.timePicker.selectedDate, secondsPart, secondsPart.format.length) === currentValue;
291280
case 'ampmList':
292281
const ampmPart = inputDateParts.find(element => element.format === 'tt');

0 commit comments

Comments
 (0)