30 lines
1.5 KiB
TypeScript
30 lines
1.5 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { calculateBookingTotalDays, normalizeOptionalText, resolveReturnLocation } from './BookingForm'
|
|
|
|
describe('BookingForm helpers', () => {
|
|
it('calculates booking nights from date-only inputs', () => {
|
|
expect(calculateBookingTotalDays('2026-06-09', '2026-06-10')).toBe(1)
|
|
expect(calculateBookingTotalDays('2026-06-09', '2026-06-16')).toBe(7)
|
|
})
|
|
|
|
it('never returns a negative total for reversed or incomplete dates', () => {
|
|
expect(calculateBookingTotalDays('2026-06-16', '2026-06-09')).toBe(0)
|
|
expect(calculateBookingTotalDays('', '2026-06-09')).toBe(0)
|
|
expect(calculateBookingTotalDays('2026-06-09', '')).toBe(0)
|
|
})
|
|
|
|
it('uses pickup location for same-location returns', () => {
|
|
expect(resolveReturnLocation({ dropoffMode: 'same', pickupLocation: 'Marrakesh Airport', returnLocation: 'Casablanca' })).toBe('Marrakesh Airport')
|
|
})
|
|
|
|
it('uses the explicit return location for different dropoffs and preserves an unset optional value', () => {
|
|
expect(resolveReturnLocation({ dropoffMode: 'different', pickupLocation: 'Marrakesh', returnLocation: 'Casablanca' })).toBe('Casablanca')
|
|
expect(resolveReturnLocation({ dropoffMode: 'different', pickupLocation: 'Marrakesh', returnLocation: '' })).toBeUndefined()
|
|
})
|
|
|
|
it('normalizes optional free-text fields without leaking empty strings into payloads', () => {
|
|
expect(normalizeOptionalText(' flight lands at 9 ')).toBe('flight lands at 9')
|
|
expect(normalizeOptionalText(' ')).toBeUndefined()
|
|
})
|
|
})
|