Skip to content

Commit d7b4665

Browse files
committed
tests(locale): Fix locale tests due to Angulars specifics.
1 parent 32b604f commit d7b4665

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

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

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { cloneValue, isObject, isDate, getCurrencyCode, getCurrencySymbol, getLocaleFirstDayOfWeek, formatDate, formatCurrency, formatPercent, formatNumber, getLocaleDateFormat, getLocaleDateTimeFormat } from './utils';
22
import { SampleTestData } from '../test-utils/sample-test-data.spec';
3+
import { toggleIgxAngularLocalization } from './i18n/resources';
34

45
describe('Utils', () => {
56
const complexObject = {
@@ -290,25 +291,45 @@ describe('Utils', () => {
290291
})
291292

292293
describe('date formatting', () => {
293-
it('should format string to dateTime', () => {
294+
it('should format string to dateTime using Angular', () => {
295+
// Angular expects time to be already in local time so we don't exact check timezone...
296+
expect(formatDate('2025-01-25T14:15:00', 'short', 'en-US')).toEqual('1/25/25, 2:15 PM');
297+
expect(formatDate('2025-01-25T14:15:00', 'medium', 'en-US')).toEqual('Jan 25, 2025, 2:15:00 PM');
298+
expect(formatDate('2025-01-25T14:15:00', 'long', 'en-US')).toContain('January 25, 2025 at 2:15:00 PM GMT');
299+
expect(formatDate('2025-01-25T14:15:00', 'full', 'en-US')).toContain('Saturday, January 25, 2025 at 2:15:00 PM GMT');
300+
});
301+
302+
it('should format string to dateTime using Intl', () => {
303+
toggleIgxAngularLocalization(false);
294304
expect(formatDate('2025-01-25T14:15:00', 'short', 'en-US', "Europe/Sofia")).toEqual('1/25/25, 2:15 PM');
295305
expect(formatDate('2025-01-25T14:15:00', 'medium', 'en-US', "Europe/Sofia")).toEqual('Jan 25, 2025, 2:15:00 PM');
296306
expect(formatDate('2025-01-25T14:15:00', 'long', 'en-US', "Europe/Sofia")).toEqual('January 25, 2025 at 2:15:00 PM GMT+2');
297-
expect(formatDate('2025-01-25T14:15:00', 'full', 'en-US', "Europe/Sofia")).toEqual('Saturday, January 25, 2025 at 2:15:00 PM GMT+02:00');
307+
expect(formatDate('2025-01-25T14:15:00', 'full', 'en-US', "Europe/Sofia")).toEqual('Saturday, January 25, 2025 at 2:15:00 PM Eastern European Standard Time');
308+
toggleIgxAngularLocalization(true);
298309
});
299310

300-
it('should format string to date', () => {
311+
it('should format string to date using Angular', () => {
301312
expect(formatDate('2025-01-25T14:15:00', 'shortDate', 'en-US', "Europe/Sofia")).toEqual('1/25/25');
302313
expect(formatDate('2025-01-25T14:15:00', 'mediumDate', 'en-US', "Europe/Sofia")).toEqual('Jan 25, 2025');
303314
expect(formatDate('2025-01-25T14:15:00', 'longDate', 'en-US', "Europe/Sofia")).toEqual('January 25, 2025');
304315
expect(formatDate('2025-01-25T14:15:00', 'fullDate', 'en-US', "Europe/Sofia")).toEqual('Saturday, January 25, 2025');
305316
});
306317

307-
it('should format string to time', () => {
318+
it('should format string to time using Angular', () => {
319+
// Angular expects time to be already in local time so we don't exact check timezone...
320+
expect(formatDate('2025-01-25T14:15:00', 'shortTime', 'en-US')).toEqual('2:15 PM');
321+
expect(formatDate('2025-01-25T14:15:00', 'mediumTime', 'en-US')).toEqual('2:15:00 PM');
322+
expect(formatDate('2025-01-25T14:15:00', 'longTime', 'en-US')).toContain('2:15:00 PM GMT');
323+
expect(formatDate('2025-01-25T14:15:00', 'fullTime', 'en-US')).toContain('2:15:00 PM GMT');
324+
});
325+
326+
it('should format string to time using Intl', () => {
327+
toggleIgxAngularLocalization(false);
308328
expect(formatDate('2025-01-25T14:15:00', 'shortTime', 'en-US', "Europe/Sofia")).toEqual('2:15 PM');
309329
expect(formatDate('2025-01-25T14:15:00', 'mediumTime', 'en-US', "Europe/Sofia")).toEqual('2:15:00 PM');
310330
expect(formatDate('2025-01-25T14:15:00', 'longTime', 'en-US', "Europe/Sofia")).toEqual('2:15:00 PM GMT+2');
311-
expect(formatDate('2025-01-25T14:15:00', 'fullTime', 'en-US', "Europe/Sofia")).toEqual('2:15:00 PM GMT+02:00');
331+
expect(formatDate('2025-01-25T14:15:00', 'fullTime', 'en-US', "Europe/Sofia")).toEqual('2:15:00 PM Eastern European Standard Time');
332+
toggleIgxAngularLocalization(true);
312333
});
313334

314335
it('should format string to custom format', () => {

0 commit comments

Comments
 (0)