Skip to content

Commit 4c537ec

Browse files
authored
Make tests pass in western hemisphere (#15387)
Fix tests run to be able to run in US ET timezone without errors. Make sure that all dates are in local timezone. e.g. new Date('2025-01-01') -> 2024-12-31 19:00 GMT -05:00 ❌ produces invalid results ymd('2025-01-01') -> 2025-01-01 19:00 GMT -05:00 ✔ See also Angular's explanation here [1], which is what they use for their Date pipe. [1]: https://github.com/angular/angular/blob/c2a46d2217dea77be30fcf5ba538a80a2f907f2d/packages/common/src/i18n/format_date.ts#L914C1-L924C6
1 parent cb515ea commit 4c537ec

File tree

10 files changed

+117
-106
lines changed

10 files changed

+117
-106
lines changed

.github/workflows/nodejs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ jobs:
5252
npm run test:i18n
5353
env:
5454
NODE_OPTIONS: --max_old_space_size=4096
55+
TZ: America/New_York
5556
- name: Build i18n & validate output
5657
run: |
5758
npm run build:i18n

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

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { FormsModule } from '@angular/forms';
44
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
55
import { configureTestSuite } from '../test-utils/configure-suite';
66
import { UIInteractions, wait } from '../test-utils/ui-interactions.spec';
7+
import { ymd } from '../test-utils/helper-utils.spec';
78
import { IgxCalendarComponent } from './public_api';
89
import { IgxDatePickerComponent } from '../date-picker/public_api';
910
import { DateRangeType } from '../core/dates';
@@ -72,7 +73,7 @@ describe('Multi-View Calendar - ', () => {
7273
});
7374

7475
it('should change months views when viewDate is changed', () => {
75-
const dates = [new Date('2019-06-19'), new Date('2019-07-19'), new Date('2019-08-19')];
76+
const dates = [ymd('2019-06-19'), ymd('2019-07-19'), ymd('2019-08-19')];
7677
const today = new Date(Date.now());
7778
expect(calendar.monthsViewNumber).toBe(3);
7879
HelperTestFunctions.verifyMonthsViewNumber(fixture, 3, true);
@@ -87,7 +88,7 @@ describe('Multi-View Calendar - ', () => {
8788
});
8889

8990
it('should be able to change hideOutsideDays property runtime', () => {
90-
calendar.viewDate = new Date('2019-07-19');
91+
calendar.viewDate = ymd('2019-07-19');
9192
fixture.detectChanges();
9293

9394
expect(calendar.hideOutsideDays).toBe(false);
@@ -147,7 +148,7 @@ describe('Multi-View Calendar - ', () => {
147148

148149
it('selected event should be fired when selecting a date', () => {
149150
spyOn(calendar.selected, 'emit');
150-
const viewDate = new Date('2019-09-06');
151+
const viewDate = ymd('2019-09-06');
151152
calendar.viewDate = viewDate;
152153
fixture.detectChanges();
153154

@@ -181,17 +182,17 @@ describe('Multi-View Calendar - ', () => {
181182
});
182183

183184
describe('KB Navigation test - ', () => {
184-
const aug2019 = new Date('2019-08-19');
185-
const sept2019 = new Date('2019-09-19');
186-
const oct2019 = new Date('2019-10-19');
187-
const nov2019 = new Date('2019-11-19');
188-
const dec2019 = new Date('2019-12-19');
189-
const jan2020 = new Date('2020-1-19');
190-
const feb2020 = new Date('2020-2-19');
191-
const march2020 = new Date('2020-3-19');
192-
const oct2021 = new Date('2021-10-19');
193-
const nov2021 = new Date('2021-11-19');
194-
const dec2021 = new Date('2021-12-19');
185+
const aug2019 = ymd('2019-08-19');
186+
const sept2019 = ymd('2019-09-19');
187+
const oct2019 = ymd('2019-10-19');
188+
const nov2019 = ymd('2019-11-19');
189+
const dec2019 = ymd('2019-12-19');
190+
const jan2020 = ymd('2020-01-19');
191+
const feb2020 = ymd('2020-02-19');
192+
const march2020 = ymd('2020-03-19');
193+
const oct2021 = ymd('2021-10-19');
194+
const nov2021 = ymd('2021-11-19');
195+
const dec2021 = ymd('2021-12-19');
195196

196197
const dateRangeDescriptors = [
197198
{ type: DateRangeType.Between, dateRange: [new Date(2019, 10, 15), new Date(2019, 11, 8)] },
@@ -505,14 +506,14 @@ describe('Multi-View Calendar - ', () => {
505506

506507
expect(calendar.activeDate.getDate()).toEqual(17);
507508
expect(calendar.activeDate.getFullYear()).toEqual(2018);
508-
HelperTestFunctions.verifyCalendarSubHeaders(fixture, [new Date('2018-10-19'), new Date('2018-11-19'), new Date('2018-12-19')]);
509+
HelperTestFunctions.verifyCalendarSubHeaders(fixture, [ymd('2018-10-19'), ymd('2018-11-19'), ymd('2018-12-19')]);
509510

510511
UIInteractions.triggerKeyDownEvtUponElem('PageUp', document.activeElement, true, false, true);
511512
fixture.detectChanges();
512513

513514
expect(calendar.activeDate.getDate()).toEqual(17);
514515
expect(calendar.activeDate.getFullYear()).toEqual(2017);
515-
HelperTestFunctions.verifyCalendarSubHeaders(fixture, [new Date('2017-10-19'), new Date('2017-11-19'), new Date('2017-12-19')]);
516+
HelperTestFunctions.verifyCalendarSubHeaders(fixture, [ymd('2017-10-19'), ymd('2017-11-19'), ymd('2017-12-19')]);
516517
});
517518

518519
it('Verify navigation with Shift plus pageDown', fakeAsync(() => {
@@ -526,7 +527,7 @@ describe('Multi-View Calendar - ', () => {
526527

527528
expect(calendar.activeDate.getDate()).toEqual(17);
528529
expect(calendar.activeDate.getFullYear()).toEqual(2020);
529-
HelperTestFunctions.verifyCalendarSubHeaders(fixture, [new Date('2020-10-19'), new Date('2020-11-19'), new Date('2020-12-19')]);
530+
HelperTestFunctions.verifyCalendarSubHeaders(fixture, [ymd('2020-10-19'), ymd('2020-11-19'), ymd('2020-12-19')]);
530531

531532
UIInteractions.triggerKeyDownEvtUponElem('PageDown', document.activeElement, true, false, true);
532533
fixture.detectChanges();
@@ -710,10 +711,10 @@ describe('Multi-View Calendar - ', () => {
710711
});
711712

712713
describe('Selection tests - ', () => {
713-
const septemberDate = new Date('2019-09-16');
714-
const octoberDate = new Date('2019-10-16');
715-
const novemberDate = new Date('2019-11-16');
716-
const decemberDate = new Date('2019-12-16');
714+
const septemberDate = ymd('2019-09-16');
715+
const octoberDate = ymd('2019-10-16');
716+
const novemberDate = ymd('2019-11-16');
717+
const decemberDate = ymd('2019-12-16');
717718
beforeEach(fakeAsync(() => {
718719
fixture = TestBed.createComponent(MultiViewCalendarSampleComponent);
719720
fixture.detectChanges();
@@ -763,8 +764,8 @@ describe('Multi-View Calendar - ', () => {
763764
calendar.selection = 'multi';
764765
fixture.detectChanges();
765766

766-
const octoberFourth = new Date('2019-10-4');
767-
const octoberThird = new Date('2019-10-3');
767+
const octoberFourth = ymd('2019-10-04');
768+
const octoberThird = ymd('2019-10-03');
768769
const secondMonthDates = HelperTestFunctions.getMonthViewDates(fixture, 1);
769770
UIInteractions.simulateClickAndSelectEvent(secondMonthDates[2].firstChild);
770771
fixture.detectChanges();
@@ -820,11 +821,11 @@ describe('Multi-View Calendar - ', () => {
820821
fixture.detectChanges();
821822

822823
calendar.selectDate([
823-
new Date("2019-10-29"),
824-
new Date("2019-11-2"),
825-
new Date("2019-10-31"),
826-
new Date("2019-11-1"),
827-
new Date("2019-10-30"),
824+
ymd('2019-10-29'),
825+
ymd('2019-11-02'),
826+
ymd('2019-10-31'),
827+
ymd('2019-11-01'),
828+
ymd('2019-10-30'),
828829
]);
829830
fixture.detectChanges();
830831

@@ -837,10 +838,10 @@ describe('Multi-View Calendar - ', () => {
837838
calendar.selection = 'single';
838839
fixture.detectChanges();
839840

840-
calendar.selectDate(new Date('2019-10-29'));
841+
calendar.selectDate(ymd('2019-10-29'));
841842
fixture.detectChanges();
842843

843-
calendar.selectDate(new Date('2019-10-30'));
844+
calendar.selectDate(ymd('2019-10-30'));
844845
fixture.detectChanges();
845846

846847
expect(HelperTestFunctions.getMonthViewSelectedDates(fixture, 1).length).toBe(1);
@@ -922,17 +923,17 @@ describe('Multi-View Calendar - ', () => {
922923

923924
calendar.selectDate([septemberDate]);
924925
fixture.detectChanges();
925-
calendar.selectDate([new Date('2019-09-21')]);
926+
calendar.selectDate([ymd('2019-09-21')]);
926927
fixture.detectChanges();
927928

928929
expect(HelperTestFunctions.getMonthViewSelectedDates(fixture, 0).length).toBe(2);
929930

930931

931-
calendar.deselectDate([septemberDate, new Date('2019-09-21')]);
932+
calendar.deselectDate([septemberDate, ymd('2019-09-21')]);
932933
fixture.detectChanges();
933934
expect(HelperTestFunctions.getMonthViewSelectedDates(fixture, 0).length).toBe(0);
934935

935-
calendar.selectDate([septemberDate, new Date('2019-10-24'), octoberDate, novemberDate]);
936+
calendar.selectDate([septemberDate, ymd('2019-10-24'), octoberDate, novemberDate]);
936937
fixture.detectChanges();
937938

938939
expect(HelperTestFunctions.getMonthViewSelectedDates(fixture, 1).length).toBe(2); // october
@@ -1047,7 +1048,7 @@ describe('Multi-View Calendar - ', () => {
10471048

10481049
let overlay = document.querySelector(HelperTestFunctions.OVERLAY_CSSCLASS);
10491050
HelperTestFunctions.verifyMonthsViewNumber(overlay, 3);
1050-
HelperTestFunctions.verifyCalendarSubHeaders(overlay, [new Date('2019-09-16'), new Date('2019-10-16'), new Date('2019-11-16')]);
1051+
HelperTestFunctions.verifyCalendarSubHeaders(overlay, [ymd('2019-09-16'), ymd('2019-10-16'), ymd('2019-11-16')]);
10511052

10521053
// close the datePicker
10531054
datePicker.close();
@@ -1066,7 +1067,7 @@ describe('Multi-View Calendar - ', () => {
10661067

10671068
overlay = document.querySelector(HelperTestFunctions.OVERLAY_CSSCLASS);
10681069
HelperTestFunctions.verifyMonthsViewNumber(overlay, 2);
1069-
HelperTestFunctions.verifyCalendarSubHeaders(overlay, [new Date('2019-09-16'), new Date('2019-10-16')]);
1070+
HelperTestFunctions.verifyCalendarSubHeaders(overlay, [ymd('2019-09-16'), ymd('2019-10-16')]);
10701071

10711072
// clean up test
10721073
tick(350);
@@ -1128,7 +1129,7 @@ export class MultiViewCalendarSampleComponent {
11281129
})
11291130
export class MultiViewDatePickerSampleComponent {
11301131
@ViewChild(IgxDatePickerComponent, { static: true }) public datePicker: IgxDatePickerComponent;
1131-
public date = new Date('2019-09-15');
1132+
public date = ymd('2019-09-15');
11321133
public monthViews = 3;
11331134
}
11341135

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ describe('IgxDateTimeEditor', () => {
796796
expect(inputElement.nativeElement.value).toEqual('__/__/____ 2_:__:__:___');
797797
inputElement.triggerEventHandler('blur', { target: inputElement.nativeElement });
798798
fixture.detectChanges();
799-
date = new Date(2010, 10, 10, 2, 0, 0);
799+
date = new Date(2000, 0, 1, 2, 0, 0);
800800
result = formatDate(date, 'longTime', 'en-US');
801801
expect(inputElement.nativeElement.value).toEqual(result);
802802
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,7 @@ describe('IgxGrid - Column properties #grid', () => {
12441244
firstCell.setEditMode(false);
12451245
fix.detectChanges();
12461246

1247-
expect(firstCell.nativeElement.innerText).toContain('8:37:11 AM GMT+');
1247+
expect(firstCell.nativeElement.innerText).toContain('8:37:11 AM GMT');
12481248

12491249
firstCell.setEditMode(true);
12501250
fix.detectChanges();

projects/igniteui-angular/src/lib/grids/grid/grid-summary.spec.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
SummariesGroupByComponent,
1414
SummariesGroupByTransactionsComponent
1515
} from '../../test-utils/grid-samples.spec';
16-
import { clearGridSubs, setupGridScrollDetection } from '../../test-utils/helper-utils.spec';
16+
import { clearGridSubs, setupGridScrollDetection, ymd } from '../../test-utils/helper-utils.spec';
1717
import { SampleTestData } from '../../test-utils/sample-test-data.spec';
1818
import { GridSummaryCalculationMode } from '../common/enums';
1919
import { IgxNumberFilteringOperand, IgxStringFilteringOperand } from '../../data-operations/filtering-condition';
@@ -108,7 +108,7 @@ describe('IgxGrid - Summaries #grid', () => {
108108
fixture.detectChanges();
109109

110110
grid.addRow({
111-
ProductID: 11, ProductName: 'Belgian Chocolate', InStock: true, UnitsInStock: 99000, OrderDate: new Date('2018-03-01')
111+
ProductID: 11, ProductName: 'Belgian Chocolate', InStock: true, UnitsInStock: 99000, OrderDate: ymd('2018-03-01')
112112
});
113113
await wait(30);
114114
fixture.detectChanges();
@@ -836,7 +836,7 @@ describe('IgxGrid - Summaries #grid', () => {
836836

837837
it('CRUD: should recalculate summary functions rowAdded', () => {
838838
grid.addRow({
839-
ProductID: 11, ProductName: 'Belgian Chocolate', InStock: true, UnitsInStock: 99000, OrderDate: new Date('2018-03-01')
839+
ProductID: 11, ProductName: 'Belgian Chocolate', InStock: true, UnitsInStock: 99000, OrderDate: ymd('2018-03-01')
840840
});
841841
fix.detectChanges();
842842

@@ -872,7 +872,7 @@ describe('IgxGrid - Summaries #grid', () => {
872872
expect(unitsInStockCell.value).toBe(2760);
873873

874874
grid.updateRow({
875-
ProductID: 1, ProductName: 'Spearmint', InStock: true, UnitsInStock: 510000, OrderDate: new Date('1984-03-21')
875+
ProductID: 1, ProductName: 'Spearmint', InStock: true, UnitsInStock: 510000, OrderDate: ymd('1984-03-21')
876876
}, 1);
877877
fix.detectChanges();
878878

@@ -2780,4 +2780,3 @@ export class CustomSummariesComponent {
27802780
};
27812781
public locale = 'en-US';
27822782
}
2783-

projects/igniteui-angular/src/lib/grids/grid/grid.component.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { AsyncPipe } from '@angular/common';
2727
import { IgxPaginatorComponent, IgxPaginatorContentDirective } from '../../paginator/paginator.component';
2828
import { IGridRowEventArgs, IgxColumnGroupComponent, IgxGridFooterComponent, IgxGridRow, IgxGroupByRow, IgxSummaryRow } from '../public_api';
2929
import { getComponentSize } from '../../core/utils';
30-
import { setElementSize } from '../../test-utils/helper-utils.spec';
30+
import { setElementSize, ymd } from '../../test-utils/helper-utils.spec';
3131

3232

3333
describe('IgxGrid Component Tests #grid', () => {
@@ -1717,11 +1717,11 @@ describe('IgxGrid Component Tests #grid', () => {
17171717
fixture.detectChanges();
17181718

17191719
rows = grid.rowList.toArray();
1720-
expectedValue = '21. März 2005';
1720+
expectedValue = `${ymd('2005-03-21').getUTCDate()}. März 2005`;
17211721
expect((rows[0].cells.toArray()[4] as any).element.nativeElement.textContent).toBe(expectedValue);
1722-
expectedValue = '15. Januar 2008';
1722+
expectedValue = `${ymd('2005-01-15').getUTCDate()}. Januar 2008`;
17231723
expect((rows[1].cells.toArray()[4] as any).element.nativeElement.textContent).toBe(expectedValue);
1724-
expectedValue = '20. November 2010';
1724+
expectedValue =`${ymd('2005-11-20').getUTCDate()}. November 2010`;
17251725
expect((rows[2].cells.toArray()[4] as any).element.nativeElement.textContent).toBe(expectedValue);
17261726

17271727
// verify summaries formatting
@@ -1735,7 +1735,7 @@ describe('IgxGrid Component Tests #grid', () => {
17351735
}
17361736
if (earliest) {
17371737
earliestValue = earliest.nativeElement.nextSibling.innerText;
1738-
expect(earliestValue).toBe('17. Mai 1990');
1738+
expect(earliestValue).toBe(`${ymd('1990-05-17').getUTCDate()}. Mai 1990`);
17391739
}
17401740
});
17411741
}));

projects/igniteui-angular/src/lib/grids/grid/grid.groupby.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { MultiColumnHeadersWithGroupingComponent } from '../../test-utils/grid-s
1818
import { GridSelectionFunctions, GridFunctions, GRID_SCROLL_CLASS } from '../../test-utils/grid-functions.spec';
1919
import { GridSelectionMode } from '../common/enums';
2020
import { ControlsFunction } from '../../test-utils/controls-functions.spec';
21+
import { ymd } from '../../test-utils/helper-utils.spec';
2122
import { IGroupingExpression } from '../../data-operations/grouping-expression.interface';
2223
import { IgxPaginatorComponent } from '../../paginator/paginator.component';
2324
import { IgxCheckboxComponent } from '../../checkbox/checkbox.component';
@@ -277,7 +278,7 @@ describe('IgxGrid - GroupBy #grid', () => {
277278
const groupRows = grid.groupsRowList.toArray();
278279
expect(groupRows.length).toEqual(4);
279280

280-
const targetTestVal = new Date(new Date('2003-03-17').setHours(3, 20, 0, 1));
281+
const targetTestVal = new Date(ymd('2003-03-17').setHours(3, 20, 0, 1));
281282
const index = groupRows.findIndex(gr => new Date(gr.groupRow.value).getTime() === targetTestVal.getTime());
282283
expect(groupRows[index].groupRow.records.length).toEqual(2);
283284

projects/igniteui-angular/src/lib/test-utils/calendar-helper-utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ export class HelperTestFunctions {
6464
const date = fixture.nativeElement.querySelector(HelperTestFunctions.CALENDAR_HEADER_DATE_CSSCLASS);
6565
expect(date).not.toBeNull();
6666

67-
const dateParts = selectedDate.toUTCString().split(' '); // (weekday, date month year)
68-
expect(date.children[0].innerText.trim()).toEqual(dateParts[0]);
69-
expect(date.children[1].innerText.trim()).toEqual(dateParts[2] + ' ' + Number(dateParts[1]));
67+
const [weekday, month, day] = selectedDate.toLocaleString('en-US', { weekday: 'short', month: 'short', day: 'numeric' }).split(' '); // (weekday, month day)
68+
expect(date.children[0].innerText.trim()).toEqual(weekday);
69+
expect(date.children[1].innerText.trim()).toEqual(month + ' ' + day);
7070
}
7171

7272
public static verifyNoRangeSelectionCreated(fixture, monthNumber: number) {

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ export function hasClass(element: HTMLElement, className: string, expected: bool
6363
expect(element.classList.contains(className)).toBe(expected);
6464
}
6565

66+
type YMD = `${string}-${string}-${string}`;
67+
68+
/** Convert a YMD string to local timezone date */
69+
export function ymd(str: YMD): Date {
70+
return new Date(str + 'T00:00');
71+
}
72+
73+
6674
@Injectable()
6775
export class TestNgZone extends NgZone {
6876
public override onStable: EventEmitter<any> = new EventEmitter(false);

0 commit comments

Comments
 (0)