Skip to content

Commit 8b392a3

Browse files
committed
fix(calendar): Fixes related to date and calendar init in test.
1 parent cda8d3f commit 8b392a3

File tree

3 files changed

+25
-19
lines changed

3 files changed

+25
-19
lines changed

projects/igniteui-angular/src/lib/calendar/calendar.component.spec.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2930,7 +2930,7 @@ describe("IgxCalendar - ", () => {
29302930
it("Should prioritize weekStart property over locale.", fakeAsync(() => {
29312931
calendar.locale = "en";
29322932
fixture.detectChanges();
2933-
expect(calendar.weekStart).toEqual(1);
2933+
expect(calendar.weekStart).toEqual(0);
29342934

29352935
calendar.weekStart = WEEKDAYS.FRIDAY;
29362936
expect(calendar.weekStart).toEqual(5);
@@ -2942,14 +2942,16 @@ describe("IgxCalendar - ", () => {
29422942
flush();
29432943
}));
29442944

2945-
it("Should respect passing invalid value for locale, then setting weekStart.", fakeAsync(() => {
2946-
calendar.locale = "frrr";
2947-
calendar.weekStart = WEEKDAYS.FRIDAY;
2948-
fixture.detectChanges();
2949-
2950-
expect(calendar.locale).toEqual("fr");
2951-
expect(calendar.weekStart).toEqual(WEEKDAYS.FRIDAY);
2945+
it("Should throw error when setting incorrect locale", fakeAsync(() => {
2946+
let errorThrown;
2947+
try {
2948+
calendar.locale = "frrr";
2949+
fixture.detectChanges();
2950+
} catch(err) {
2951+
errorThrown = err;
2952+
}
29522953

2954+
expect(errorThrown).not.toBeUndefined();
29532955
flush();
29542956
}));
29552957

projects/igniteui-angular/src/lib/core/utils.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
isPlatformBrowser,
77
FormatWidth
88
} from '@angular/common';
9-
import { DestroyRef, Inject, Injectable, InjectionToken, PLATFORM_ID, inject } from '@angular/core';
9+
import { DestroyRef, Inject, Injectable, InjectionToken, PLATFORM_ID, inject, ɵR3Injector as R3Injector } from '@angular/core';
1010
import { mergeWith } from 'lodash-es';
1111
import { NEVER, Observable, Subject } from 'rxjs';
1212
import { setImmediate } from './setImmediate';
@@ -596,9 +596,10 @@ export function onResourceChangeHandle(destroyObj: Subject<any> | DestroyRef, ca
596596
const removeHandler = () => {
597597
getI18nManager().removeEventListener("onResourceChange", onResourceChangeHandler);
598598
}
599-
if (destroyObj instanceof DestroyRef) {
599+
if (destroyObj instanceof DestroyRef || destroyObj instanceof R3Injector) {
600+
// R3Injector is for tests only
600601
destroyObj.onDestroy(() => removeHandler());
601-
} else {
602+
} else if (destroyObj) {
602603
destroyObj.subscribe({
603604
complete: () => removeHandler()
604605
});
@@ -666,11 +667,11 @@ export function formatDate(value: Date | string | number | null | undefined, for
666667
if (format === 'short' || format === 'medium' || format === 'long' || format === 'full') {
667668
dateStyle = format;
668669
timeStyle = format;
669-
} else if (format.includes('Date')) {
670+
} else if (format?.includes('Date')) {
670671
dateStyle = format.replace('Date', '');
671-
} else if (format.includes('Time')) {
672+
} else if (format?.includes('Time')) {
672673
timeStyle = format.replace('Time', '');
673-
} else {
674+
} else if (format) {
674675
return getI18nManager().formatDateCustomFormat(value, locale, format, timezone);
675676
}
676677
const options: Intl.DateTimeFormatOptions = {
@@ -681,18 +682,18 @@ export function formatDate(value: Date | string | number | null | undefined, for
681682
return getI18nManager().formatDateTime(value, locale, options);
682683
}
683684

684-
function parseDigitsInfo(value: string) {
685+
function parseDigitsInfo(value?: string) {
685686
let minIntegerDigits = undefined, minFractionDigits = undefined, maxFractionDigits = undefined;
686687
if (value) {
687688
const parts = value.split("-");
688689
const innerParts = parts[0].split(".");
689-
if (innerParts[0] !== "1") {
690+
if (innerParts.length > 0) {
690691
minIntegerDigits = parseInt(innerParts[0]);
691692
}
692-
if (innerParts.length == 2 && innerParts[1] !== "0") {
693+
if (innerParts.length == 2) {
693694
minFractionDigits = parseInt(innerParts[1]);
694695
}
695-
if (parts.length == 2 && parts[1] !== "3") {
696+
if (parts.length == 2) {
696697
maxFractionDigits = parseInt(parts[1]);
697698
}
698699
}
@@ -758,6 +759,7 @@ export function getCurrencySymbol(currencyCode: string, locale?: string, curren
758759

759760
export function getLocaleFirstDayOfWeek(locale?: string) {
760761
try {
762+
// Angular returns 0 for Sunday...
761763
return ngGetLocaleFirstDayOfWeek(locale);
762764
} catch {}
763765
return getI18nManager().getFirstDayOfWeek(locale);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ describe('IgxDateRangePicker', () => {
127127
mockAnimationService = new IgxAngularAnimationService(mockAnimationBuilder);
128128
overlay = new IgxOverlayService(
129129
mockApplicationRef, mockDocument, mockNgZone, mockPlatformUtil, mockAnimationService);
130-
mockCalendar = new IgxCalendarComponent(platform, 'en');
130+
mockCalendar = TestBed.runInInjectionContext(() => {
131+
return new IgxCalendarComponent(platform, 'en');
132+
});
131133

132134
mockDaysView = {
133135
focusActiveDate: jasmine.createSpy()

0 commit comments

Comments
 (0)