test(front): fix main failing test due to timezone (#11295)
# Introduction Due to winter to summer timezone update, it shown that we have some unit tests flakiness due to both mocked and unmocked date.now invokation between app bootstrap and test bootstrap This PR does not refactor this behavior Just fix the currently failing test ## Note Removed a duplicated file
This commit is contained in:
@ -13,4 +13,4 @@ import '@testing-library/jest-dom';
|
||||
*/
|
||||
global.structuredClone = (val) => {
|
||||
return JSON.parse(JSON.stringify(val));
|
||||
};
|
||||
};
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -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<
|
||||
|
||||
@ -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;
|
||||
};
|
||||
Reference in New Issue
Block a user