Skip to content

Commit

Permalink
fix(test): fix tx date test
Browse files Browse the repository at this point in the history
  • Loading branch information
lwih committed Nov 14, 2024
1 parent 7d51fff commit 24ffeee
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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

Check warning on line 21 in frontend/src/features/common/components/elements/dates/date-picker.test.tsx

View workflow job for this annotation

GitHub Actions / build-and-test-frontend

Date prototype is read only, properties should not be added
})

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)

Check warning on line 26 in frontend/src/features/common/components/elements/dates/date-picker.test.tsx

View workflow job for this annotation

GitHub Actions / build-and-test-frontend

Date prototype is read only, properties should not be added

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)

Check warning on line 36 in frontend/src/features/common/components/elements/dates/date-picker.test.tsx

View workflow job for this annotation

GitHub Actions / build-and-test-frontend

Date prototype is read only, properties should not be added

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()

Expand Down

0 comments on commit 24ffeee

Please sign in to comment.