统一前端时间按酒店时区显示
This commit is contained in:
45
client/src/tests/reservationFormat.spec.ts
Normal file
45
client/src/tests/reservationFormat.spec.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { afterEach, describe, expect, it } from 'vitest'
|
||||
|
||||
import {
|
||||
setReservationTimeZoneProvider,
|
||||
} from '@/config/reservationConfig'
|
||||
import {
|
||||
formatReservationDateRange,
|
||||
formatReservationDateTime,
|
||||
} from '@/utils/reservationFormat'
|
||||
|
||||
describe('reservationFormat', () => {
|
||||
afterEach(() => {
|
||||
setReservationTimeZoneProvider(null)
|
||||
})
|
||||
|
||||
it('formats UTC API timestamps in the default hotel time zone', () => {
|
||||
expect(formatReservationDateTime('2026-07-09T05:56:56Z')).toBe('2026-07-09 12:56:56')
|
||||
})
|
||||
|
||||
it('formats timestamps in the selected hotel time zone', () => {
|
||||
setReservationTimeZoneProvider(() => 'Asia/Tokyo')
|
||||
|
||||
expect(formatReservationDateTime('2026-07-09T05:56:56Z')).toBe('2026-07-09 14:56:56')
|
||||
})
|
||||
|
||||
it('honors offsets from source timestamps before converting to hotel time', () => {
|
||||
expect(formatReservationDateTime('2026-07-08T09:18:00+08:00')).toBe('2026-07-08 08:18:00')
|
||||
})
|
||||
|
||||
it('falls back to the default hotel time zone when the selected hotel timezone is invalid', () => {
|
||||
setReservationTimeZoneProvider(() => 'Invalid/Timezone')
|
||||
|
||||
expect(formatReservationDateTime('2026-07-09T05:56:56Z')).toBe('2026-07-09 12:56:56')
|
||||
})
|
||||
|
||||
it('falls back safely for empty or invalid timestamps', () => {
|
||||
expect(formatReservationDateTime(null)).toBe('-')
|
||||
expect(formatReservationDateTime(undefined)).toBe('-')
|
||||
expect(formatReservationDateTime('not-a-date')).toBe('not-a-date')
|
||||
})
|
||||
|
||||
it('keeps hotel business date ranges as local dates without timezone conversion', () => {
|
||||
expect(formatReservationDateRange('2026-07-09', '2026-07-10')).toBe('2026-07-09 / 2026-07-10')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user