From fda793ced255a96abcdc54a3af8d2c40a4fa6286 Mon Sep 17 00:00:00 2001 From: Lucas Bordeau Date: Tue, 29 Apr 2025 11:45:58 +0200 Subject: [PATCH] Fix formatDateString test (#11786) This PR fixes a broken test that makes the CI crash. This is due to the library `date-fns` which now doesn't use the word "about" in its relative date formatting, if we're not precisely on minus 2 months, which can change for example today the 29th of April, where the 29th of February doesn't exist. So instead of using months and falling into hard to test cases, we use days instead, which is an easy and predictable relative computation. --- .../utils/string/__tests__/formatDateString.test.ts | 10 ++-------- .../string/__tests__/formatDateTimeString.test.ts | 10 ++-------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/packages/twenty-front/src/utils/string/__tests__/formatDateString.test.ts b/packages/twenty-front/src/utils/string/__tests__/formatDateString.test.ts index a88d7f61f..8841ec97e 100644 --- a/packages/twenty-front/src/utils/string/__tests__/formatDateString.test.ts +++ b/packages/twenty-front/src/utils/string/__tests__/formatDateString.test.ts @@ -28,14 +28,8 @@ describe('formatDateString', () => { }); it('should format date as relative when displayFormat is set to RELATIVE', () => { - const mockDate = DateTime.now().minus({ months: 2 }).toISO(); - const mockRelativeDate = 'about 2 months ago'; - - jest.mock('@/localization/utils/formatDateISOStringToRelativeDate', () => ({ - formatDateISOStringToRelativeDate: jest - .fn() - .mockReturnValue(mockRelativeDate), - })); + const mockDate = DateTime.now().minus({ days: 2 }).toISO(); + const mockRelativeDate = '2 days ago'; const result = formatDateString({ ...defaultParams, diff --git a/packages/twenty-front/src/utils/string/__tests__/formatDateTimeString.test.ts b/packages/twenty-front/src/utils/string/__tests__/formatDateTimeString.test.ts index 69ba8c54c..d14fbe616 100644 --- a/packages/twenty-front/src/utils/string/__tests__/formatDateTimeString.test.ts +++ b/packages/twenty-front/src/utils/string/__tests__/formatDateTimeString.test.ts @@ -30,14 +30,8 @@ describe('formatDateTimeString', () => { }); it('should format date as relative when displayFormat is RELATIVE', () => { - const mockDate = DateTime.now().minus({ months: 2 }).toISO(); - const mockRelativeDate = 'about 2 months ago'; - - jest.mock('@/localization/utils/formatDateISOStringToRelativeDate', () => ({ - formatDateISOStringToRelativeDate: jest - .fn() - .mockReturnValue(mockRelativeDate), - })); + const mockDate = DateTime.now().minus({ days: 2 }).toISO(); + const mockRelativeDate = '2 days ago'; const result = formatDateTimeString({ ...defaultParams,