Skip to content

Commit

Permalink
Merge pull request #433 from MTES-MCT/fix-test-dates
Browse files Browse the repository at this point in the history
fix(test): fix tx date test
  • Loading branch information
lwih authored Nov 18, 2024
2 parents 7d51fff + 24ffeee commit 3692e04
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 3692e04

Please sign in to comment.