The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
test(front): fix main failing test due to timezone (#11295)
Paul Rastoin3c9bf2294fce
diff --git a/packages/twenty-front/setupTests.ts b/packages/twenty-front/setupTests.tsindex e5aa41c46c9..d995aadc1eb 100644--- a/packages/twenty-front/setupTests.ts+++ b/packages/twenty-front/setupTests.ts@@ -13,4 +13,4 @@ import '@testing-library/jest-dom';*/global.structuredClone = (val) => {return JSON.parse(JSON.stringify(val));-};+};\ No newline at end of filediff --git a/packages/twenty-front/src/modules/localization/utils/__tests__/findAvailableTimeZoneOption.test.ts b/packages/twenty-front/src/modules/localization/utils/__tests__/findAvailableTimeZoneOption.test.tsindex 05e670b592c..b1058e7ad66 100644--- a/packages/twenty-front/src/modules/localization/utils/__tests__/findAvailableTimeZoneOption.test.ts+++ b/packages/twenty-front/src/modules/localization/utils/__tests__/findAvailableTimeZoneOption.test.ts@@ -1,11 +1,12 @@import { findAvailableTimeZoneOption } from '@/localization/utils/findAvailableTimeZoneOption';-jest.useFakeTimers().setSystemTime(new Date('2024-01-01T00:00:00.000Z'));+// TODO: This test is flaky, datetime retrieve in its scope, if mocked will be different than the one computed to build AVAILABLE_TIME_ZONE_OPTIONS_BY_LABEL+// We should refactor our tests to start from a controlled mocked date directly within `setupTests.ts`describe('findAvailableTimeZoneOption', () => {it('should find the matching available IANA time zone select option from a given IANA time zone', () => {const ianaTimeZone = 'Europe/Paris';const value = 'Europe/Paris';- const label = '(GMT+01:00) Central European Standard Time - Paris';+ const label = '(GMT+02:00) Central European Summer Time - Paris';const option = findAvailableTimeZoneOption(ianaTimeZone);diff --git a/packages/twenty-front/src/modules/settings/accounts/constants/AvailableTimezoneOptionsByLabel.ts b/packages/twenty-front/src/modules/settings/accounts/constants/AvailableTimezoneOptionsByLabel.tsindex 6e8ea2b3a02..eba6bb35259 100644--- a/packages/twenty-front/src/modules/settings/accounts/constants/AvailableTimezoneOptionsByLabel.ts+++ b/packages/twenty-front/src/modules/settings/accounts/constants/AvailableTimezoneOptionsByLabel.ts@@ -1,7 +1,7 @@/* eslint-disable @typescript-eslint/naming-convention *//* eslint-disable @nx/workspace-max-consts-per-file */import { IANA_TIME_ZONES } from '@/localization/constants/IanaTimeZones';-import { formatTimeZoneLabel } from '@/settings/accounts/utils/formatTimeZoneLabel';+import { formatTimeZoneLabel } from '@/localization/utils/formatTimeZoneLabel';import { SelectOption } from 'twenty-ui';export const AVAILABLE_TIME_ZONE_OPTIONS_BY_LABEL = IANA_TIME_ZONES.reduce<diff --git a/packages/twenty-front/src/modules/settings/accounts/utils/formatTimeZoneLabel.ts b/packages/twenty-front/src/modules/settings/accounts/utils/formatTimeZoneLabel.tsdeleted file mode 100644index e5f1ac97e0c..00000000000--- a/packages/twenty-front/src/modules/settings/accounts/utils/formatTimeZoneLabel.ts+++ /dev/null@@ -1,29 +0,0 @@-import defaultLocale from 'date-fns/locale/en-US';-import { formatInTimeZone } from 'date-fns-tz';--/**- * Formats a IANA time zone to a select option label.- * @param ianaTimeZone IANA time zone- * @returns Formatted label- * @example 'Europe/Paris' => '(GMT+01:00) Central European Time - Paris'- */-export const formatTimeZoneLabel = (ianaTimeZone: string) => {- const timeZoneWithGmtOffset = formatInTimeZone(- Date.now(),- ianaTimeZone,- `(OOOO) zzzz`,- { locale: defaultLocale },- );- const ianaTimeZoneParts = ianaTimeZone.split('/');- const location =- ianaTimeZoneParts.length > 1- ? ianaTimeZoneParts.slice(-1)[0].replaceAll('_', ' ')- : undefined;-- const timeZoneLabel =- !location || timeZoneWithGmtOffset.includes(location)- ? timeZoneWithGmtOffset- : [timeZoneWithGmtOffset, location].join(' - ');-- return timeZoneLabel;-};