Skip to content

Commit

Permalink
fix: add test for when time zones are the same [LIBS-490]
Browse files Browse the repository at this point in the history
  • Loading branch information
tomzemp committed Apr 5, 2023
1 parent 06eaa5d commit 7911f8b
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions services/config/src/__tests__/useTimeZoneConversion.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,31 @@ describe('useTimeZoneConversion', () => {
expect(serverDate.getClientZonedISOString()).toBe(expectedDateString)
})

it('returns fromServerDate that assumes no time zone difference if client and server time zones are the same', () => {
const systemInfo = {
...defaultSystemInfo,
serverTimeZoneId: 'Africa/Kampala',
}
jest.spyOn(Intl, 'DateTimeFormat').mockReturnValue({
resolvedOptions: () => {
return {
timeZone: 'Africa/Kampala',
}
},
} as Intl.DateTimeFormat)
const config = { ...defaultConfig, systemInfo }
const wrapper = ({ children }: { children?: ReactNode }) => (
<ConfigProvider config={config}>{children}</ConfigProvider>
)
const { result } = renderHook(() => useTimeZoneConversion(), {
wrapper,
})

const serverDate = result.current.fromServerDate('2010-01-01')
const expectedDateString = '2010-01-01T00:00:00.000'
expect(serverDate.getClientZonedISOString()).toBe(expectedDateString)
})

it('returns fromServerDate with server date that matches passed time regardless of timezone', () => {
const systemInfo = {
...defaultSystemInfo,
Expand Down

0 comments on commit 7911f8b

Please sign in to comment.