Skip to content

Commit d842573

Browse files
committed
tests(localization): Fix some unicode mismatches from Angular 21. Add clean unicode method.
1 parent e3d72fc commit d842573

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

projects/igniteui-angular/core/src/core/i18n/formatters/formatter-base.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ describe('Localization', () => {
4040
describe('date formatting', () => {
4141
it('should format string to dateTime using Angular', () => {
4242
// Angular expects time to be already in local time so we don't exact check timezone...
43-
expect(i18nFormatter.formatDate('2025-01-25T14:15:00', 'short', 'en-US')).toEqual('1/25/25, 2:15 PM');
44-
expect(i18nFormatter.formatDate('2025-01-25T14:15:00', 'medium', 'en-US')).toEqual('Jan 25, 2025, 2:15:00 PM');
45-
expect(i18nFormatter.formatDate('2025-01-25T14:15:00', 'long', 'en-US')).toContain('January 25, 2025 at 2:15:00 PM GMT');
46-
expect(i18nFormatter.formatDate('2025-01-25T14:15:00', 'full', 'en-US')).toContain('Saturday, January 25, 2025 at 2:15:00 PM GMT');
43+
expect(i18nFormatter.formatDate('2025-01-25T14:15:00', 'short', 'en-US')).toEqual('1/25/25, 2:15PM');
44+
expect(i18nFormatter.formatDate('2025-01-25T14:15:00', 'medium', 'en-US')).toEqual('Jan 25, 2025, 2:15:00PM');
45+
expect(i18nFormatter.formatDate('2025-01-25T14:15:00', 'long', 'en-US')).toContain('January 25, 2025, 2:15:00PM GMT');
46+
expect(i18nFormatter.formatDate('2025-01-25T14:15:00', 'full', 'en-US')).toContain('Saturday, January 25, 2025, 2:15:00PM GMT');
4747
});
4848

4949
it('should format string to date using Angular', () => {
@@ -55,10 +55,10 @@ describe('Localization', () => {
5555

5656
it('should format string to time using Angular', () => {
5757
// Angular expects time to be already in local time so we don't exact check timezone...
58-
expect(i18nFormatter.formatDate('2025-01-25T14:15:00', 'shortTime', 'en-US')).toEqual('2:15 PM');
59-
expect(i18nFormatter.formatDate('2025-01-25T14:15:00', 'mediumTime', 'en-US')).toEqual('2:15:00 PM');
60-
expect(i18nFormatter.formatDate('2025-01-25T14:15:00', 'longTime', 'en-US')).toContain('2:15:00 PM GMT');
61-
expect(i18nFormatter.formatDate('2025-01-25T14:15:00', 'fullTime', 'en-US')).toContain('2:15:00 PM GMT');
58+
expect(i18nFormatter.formatDate('2025-01-25T14:15:00', 'shortTime', 'en-US')).toEqual('2:15PM');
59+
expect(i18nFormatter.formatDate('2025-01-25T14:15:00', 'mediumTime', 'en-US')).toEqual('2:15:00PM');
60+
expect(i18nFormatter.formatDate('2025-01-25T14:15:00', 'longTime', 'en-US')).toContain('2:15:00PM GMT');
61+
expect(i18nFormatter.formatDate('2025-01-25T14:15:00', 'fullTime', 'en-US')).toContain('2:15:00PM GMT');
6262
});
6363

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

projects/igniteui-angular/directives/src/directives/date-time-editor/date-time-editor.directive.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { ViewEncapsulation } from '@angular/core';
1212
import localeJa from "@angular/common/locales/ja";
1313
import localeBg from "@angular/common/locales/bg";
1414
import { DatePart, BaseFormatter } from 'igniteui-angular/core';
15+
import { removeUnicodeSpaces } from 'igniteui-angular/test-utils/helper-utils.spec';
1516

1617
describe('IgxDateTimeEditor', () => {
1718
let dateTimeEditor: IgxDateTimeEditorDirective;
@@ -789,7 +790,7 @@ describe('IgxDateTimeEditor', () => {
789790
date = new Date(0, 0, 0, 1, 0, 0);
790791
const shortTimeOptions = { hour: 'numeric', minute: 'numeric', hour12: true };
791792
result = ControlsFunction.formatDate(date, shortTimeOptions);
792-
expect(inputElement.nativeElement.value).toEqual(result);
793+
expect(removeUnicodeSpaces(inputElement.nativeElement.value)).toEqual(result);
793794

794795
dateTimeEditorDirective.clear();
795796
fixture.detectChanges();
@@ -804,7 +805,7 @@ describe('IgxDateTimeEditor', () => {
804805
fixture.detectChanges();
805806
date = new Date(2000, 0, 1, 2, 0, 0);
806807
result = formatDate(date, 'longTime', 'en-US').normalize("NFKD");
807-
expect(inputElement.nativeElement.value).toEqual(result);
808+
expect(removeUnicodeSpaces(inputElement.nativeElement.value)).toContain(result);
808809
});
809810
it('should be able to apply custom display format.', fakeAsync(() => {
810811
// default format

projects/igniteui-angular/grids/grid/src/column.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ describe('IgxGrid - Column properties #grid', () => {
913913
const input = dateTimeEditor.nativeElement;
914914

915915
// input is not focused yet, so the value is as the display format sets it
916-
expect(input.value).toEqual('Oct 1, 2015, 11:37:22 AM');
916+
expect(input.value).toEqual('Oct 1, 2015, 11:37:22AM');
917917

918918
expect(dateTimeEditor.inputFormat.normalize('NFKC')).toBe('MM/dd/yyyy, hh:mm:ss tt');
919919
dateTimeEditor.onFocus();

projects/igniteui-angular/test-utils/helper-utils.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ export function ymd(str: YMD): Date {
7272
return new Date(str + 'T00:00');
7373
}
7474

75+
/**
76+
* Removes any unicode symbols for different variations in spaces.
77+
* Use when just comparing to basic string wouldn't work.
78+
*/
79+
export function removeUnicodeSpaces(value: string) {
80+
return value.replace(/[\u00A0\u1680\u180e\u2000-\u2009\u200a\u200b\u202f\u205f\u3000]/g, ' ');
81+
}
82+
7583

7684
@Injectable()
7785
export class TestNgZone extends NgZone {

0 commit comments

Comments
 (0)