Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(test): fix tx date test #433

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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('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
Loading