From 24ffeeed35c877b569444d5b680d60f4c1aefeeb Mon Sep 17 00:00:00 2001 From: lwih Date: Thu, 14 Nov 2024 14:38:52 +0100 Subject: [PATCH] fix(test): fix tx date test --- .../elements/dates/date-picker.test.tsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/frontend/src/features/common/components/elements/dates/date-picker.test.tsx b/frontend/src/features/common/components/elements/dates/date-picker.test.tsx index 785ab28c..09d74cb3 100644 --- a/frontend/src/features/common/components/elements/dates/date-picker.test.tsx +++ b/frontend/src/features/common/components/elements/dates/date-picker.test.tsx @@ -1,5 +1,4 @@ import DatePicker from '@common/components/elements/dates/date-picker.tsx' -import { addMinutes } from 'date-fns' import { render, screen } from '../../../../../test-utils.tsx' import { postprocessDateFromPicker, preprocessDateForPicker } from '@common/components/elements/dates/utils.ts' @@ -15,19 +14,34 @@ describe.skip('DatePicker tests ', () => { }) describe('postprocessDateFromPicker', () => { + const originalGetTimezoneOffset = Date.prototype.getTimezoneOffset + + afterEach(() => { + // Restore original implementation after each test + Date.prototype.getTimezoneOffset = originalGetTimezoneOffset + }) + it('should correct the date received from picker by adding local timezone offset (summer time)', () => { + // Mock timezone offset for UTC+2 (summer time in France) + Date.prototype.getTimezoneOffset = vi.fn(() => -120) + const dateFromPicker = new Date('2023-09-01T10:15:30Z') const processedDate = postprocessDateFromPicker(dateFromPicker) expect(processedDate?.toISOString()).toEqual('2023-09-01T08:15:30.000Z') }) + it('should correct the date received from picker by adding local timezone offset (winter time)', () => { + // Mock timezone offset for UTC+1 (winter time in France) + Date.prototype.getTimezoneOffset = vi.fn(() => -60) + const dateFromPicker = new Date('2023-12-01T10:15:30Z') const processedDate = postprocessDateFromPicker(dateFromPicker) expect(processedDate?.toISOString()).toEqual('2023-12-01T09:15:30.000Z') }) }) + describe('DatePicker', () => { const onChangeMock = vi.fn()