Files
Flight-Ops/components/right-pane.test.ts
T

67 lines
2.3 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { dispatchSelection } from './RightPane';
import type { ContractState, PlaneState } from '@/lib/game/state';
// v0.10.1 — the per-contract dispatch picker rule: a row's effective selection is the user's
// explicit pick while it stays eligible (available AND at the contract origin), else NOTHING
// (placeholder). The old "auto-track first eligible" fallback made every accepted-contract row
// display the same plane, so selections looked shared across contracts.
const contract: ContractState = {
id: 'contract-a',
originIcao: 'EDDF',
originName: 'Frankfurt Main',
destIcao: 'EDDM',
destName: 'Munich',
reward: 1000,
cargoType: 'mail',
cargoCount: 4,
deadlineSimTime: 1_000_000,
status: 'accepted',
planeId: null,
createdSimTime: 0,
};
function plane(over: Partial<PlaneState> & Pick<PlaneState, 'id'>): PlaneState {
return {
model: 'atr72',
status: 'available',
fuel: 100,
maxFuel: 100,
locationIcao: 'EDDF',
locationName: 'Frankfurt Main',
contractId: null,
departureSimTime: null,
lat: 50,
lon: 8.5,
...over,
};
}
describe('dispatchSelection (per-contract dispatch picker rule)', () => {
it('defaults to the placeholder — no auto-selection of the first eligible plane', () => {
const planes = [plane({ id: 'p1' }), plane({ id: 'p2' })]; // both eligible at EDDF
expect(dispatchSelection(planes, contract, null)).toBeNull();
});
it('returns the user pick while it stays eligible (available AND at the origin)', () => {
const planes = [plane({ id: 'p1' }), plane({ id: 'p2', locationIcao: 'EDDM' })];
expect(dispatchSelection(planes, contract, 'p1')?.id).toBe('p1');
});
it('drops to the placeholder when a poll makes the pick ineligible (flew away)', () => {
const planes = [plane({ id: 'p1', status: 'flying' })];
expect(dispatchSelection(planes, contract, 'p1')).toBeNull();
});
it('drops to the placeholder when a poll moves the pick off the origin', () => {
const planes = [plane({ id: 'p1', locationIcao: 'EDDM' })];
expect(dispatchSelection(planes, contract, 'p1')).toBeNull();
});
it('unknown selection id resolves to the placeholder', () => {
const planes = [plane({ id: 'p1' })];
expect(dispatchSelection(planes, contract, 'no-such-plane')).toBeNull();
});
});