mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 17:41:51 +00:00
fix(planner): show each leg's own seat on a flight with a stop
A flight with a stop saves a seat per leg, but every view read the booking's flat seat, which mirrors the first leg's. A seat booked only on the second leg showed nowhere, and one on the first leg showed on both. #2701 had fixed this for trains only. - getFlightLegs reads each leg's seat. The first leg falls back to the flat seat, as the booking form does, so older bookings keep theirs. - bookingSeats lists the seat of every leg that has one with its route. The detail views (the phone's transport sheet, the booking detail) show each leg's seat under its route ("Seat IST → JFK"), and a leg opened from its row shows its own. The cards and field grids (bookings list, the phone's Bookings and Transports tabs, the day plan's transport detail) hold every seat in one Seat cell, so a card cutting its grid short no longer drops the second leg's. - The day plan's flight leg rows carry their seat, and the PDF prints a flight's seat, direct or per leg. - The watch and the Wallet pass name every leg's seat of the booking. - A legs-only MCP update sets the flat seat, airline and flight number (train number and platform) again from the new first leg, so a seat taken off the first leg does not live on in the flat seat. A flat value the stored first leg never had stays. Closes #3158
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { getFlightLegs, getTrainLegs, isMultiLegTrain, stripAirportCode, usesStationRoute } from './flightLegs'
|
||||
import { bookingSeats, getFlightLegs, getTrainLegs, isMultiLegTrain, seatCells, seatLabel, stripAirportCode, usesStationRoute } from './flightLegs'
|
||||
import type { Reservation } from '../types'
|
||||
|
||||
function res(partial: Partial<Reservation>): Reservation {
|
||||
@@ -97,6 +97,42 @@ describe('per-segment booking references (#1943)', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('the seats of a booking with a stop', () => {
|
||||
const stopover = (legs: object[], extra: Record<string, unknown> = {}) =>
|
||||
res({ type: 'flight', metadata: JSON.stringify({ ...extra, legs }) })
|
||||
|
||||
it('reads each flight leg its own seat, so one booked only on the second leg is not lost', () => {
|
||||
const r = stopover([{ from: 'MXP', to: 'IST' }, { from: 'IST', to: 'JFK', seat: '14C' }])
|
||||
expect(getFlightLegs(r).map(l => l.seat)).toEqual([undefined, '14C'])
|
||||
expect(bookingSeats(r)).toEqual([{ route: 'IST → JFK', seat: '14C' }])
|
||||
})
|
||||
|
||||
it('gives the first leg the flat seat when it has none of its own, as the booking form does', () => {
|
||||
const r = stopover([{ from: 'MXP', to: 'IST' }, { from: 'IST', to: 'JFK' }], { seat: '3A' })
|
||||
expect(getFlightLegs(r).map(l => l.seat)).toEqual(['3A', undefined])
|
||||
expect(bookingSeats(r)).toEqual([{ route: 'MXP → IST', seat: '3A' }])
|
||||
})
|
||||
|
||||
it('lists a train with a stop leg by leg too', () => {
|
||||
const r = res({ metadata: JSON.stringify({ legs: [{ from: 'Takayama', to: 'Nagoya', seat: '10-4C' }, { from: 'Nagoya', to: 'Kyoto', seat: '4-5A' }] }) })
|
||||
expect(bookingSeats(r)).toEqual([{ route: 'Takayama → Nagoya', seat: '10-4C' }, { route: 'Nagoya → Kyoto', seat: '4-5A' }])
|
||||
})
|
||||
|
||||
it('gives a booking of one leg, of any type, its own seat without a route', () => {
|
||||
expect(bookingSeats(res({ type: 'flight', metadata: JSON.stringify({ seat: '31A' }) }))).toEqual([{ route: null, seat: '31A' }])
|
||||
expect(bookingSeats(res({ type: 'event', metadata: JSON.stringify({ seat: 'Row 4' }) }))).toEqual([{ route: null, seat: 'Row 4' }])
|
||||
expect(bookingSeats(res({ type: 'flight', metadata: null }))).toEqual([])
|
||||
})
|
||||
|
||||
it('labels a leg seat with its route and a booking seat plainly', () => {
|
||||
expect(seatLabel('Seat', 'IST → JFK')).toBe('Seat IST → JFK')
|
||||
expect(seatLabel('Seat', null)).toBe('Seat')
|
||||
const r = stopover([{ from: 'MXP', to: 'IST', seat: '3A' }, { from: 'IST', to: 'JFK', seat: '14C' }])
|
||||
expect(seatCells(r, 'Seat', ' · Economy')).toEqual([{ label: 'Seat', value: '3A, 14C · Economy' }])
|
||||
expect(seatCells(res({ type: 'flight', metadata: null }), 'Seat')).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
describe('stripAirportCode', () => {
|
||||
it('drops the code the forms and the airport backfill append, and nothing else', () => {
|
||||
expect(stripAirportCode('Paris Charles de Gaulle (CDG)')).toBe('Paris Charles de Gaulle')
|
||||
|
||||
Reference in New Issue
Block a user