v1.11.0: hide open-package rows with no grounded plane at the origin (ISS-159)
CI / build + unit + e2e (pull_request) Successful in 5m25s
CI / build + unit + e2e (pull_request) Successful in 5m25s
This commit is contained in:
@@ -46,6 +46,15 @@ export function loadEligiblePlanes(state: StateSnapshot, pkg: PackageState): Pla
|
||||
});
|
||||
}
|
||||
|
||||
// v1.11.0 (ISS-159): the open packages the market list shows — hidden while no GROUNDED plane sits at
|
||||
// their origin ("jobs for planes that are in air" disappear until landing). Payload-blocked rows stay:
|
||||
// a grounded plane at the origin keeps the row visible with its disabled Load button.
|
||||
export function visibleOpenPackages(state: StateSnapshot): PackageState[] {
|
||||
return state.packages.filter(
|
||||
(p) => p.status === 'open' && state.planes.some((pl) => pl.status === 'available' && pl.locationIcao === p.originIcao),
|
||||
);
|
||||
}
|
||||
|
||||
// Load controls for one open package: a single Load button when exactly one plane
|
||||
// is eligible (it acts on that plane directly), a small plane picker + Load when
|
||||
// several are, and a disabled button with the reason otherwise. Each row owns its
|
||||
@@ -141,7 +150,7 @@ export default function RightPane({ state, loading, applySnapshot, onHover, onEr
|
||||
if (!state) return null;
|
||||
|
||||
const clockMs = state.simState.clockMs;
|
||||
const open = state.packages.filter((p) => p.status === 'open');
|
||||
const open = visibleOpenPackages(state);
|
||||
|
||||
const catalog = state.catalog;
|
||||
const buyEntry = catalog.find((e) => e.model === buyModelId) ?? catalog[0] ?? null;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { cargoWeightFor, loadEligiblePlanes } from './RightPane';
|
||||
import { cargoWeightFor, loadEligiblePlanes, visibleOpenPackages } from './RightPane';
|
||||
import type { PackageState, PlaneState, StateSnapshot } from '@/lib/game/state';
|
||||
|
||||
// v0.12.0 (weight model v0.27.0) — the package-model picker rules: a plane can LOAD a
|
||||
@@ -134,3 +134,39 @@ describe('loadEligiblePlanes (Load button eligibility)', () => {
|
||||
expect(loadEligiblePlanes(s, pkg({ id: 'x' }))).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('visibleOpenPackages (market list row filter, ISS-159)', () => {
|
||||
it('shows an open package when a grounded plane sits at its origin', () => {
|
||||
const s = snap(
|
||||
[plane({ id: 'at-origin' })],
|
||||
[pkg({ id: 'x' }), pkg({ id: 'onboard', status: 'loaded', planeId: 'at-origin' })], // non-open statuses never listed
|
||||
);
|
||||
expect(visibleOpenPackages(s).map((p) => p.id)).toEqual(['x']);
|
||||
});
|
||||
|
||||
it('hides an open package when only a flying plane is at its origin (in air, not grounded)', () => {
|
||||
const s = snap([plane({ id: 'en-route', status: 'flying', destIcao: 'LEMD' })], [pkg({ id: 'x' })]);
|
||||
expect(visibleOpenPackages(s)).toEqual([]);
|
||||
});
|
||||
|
||||
it('hides an open package when the grounded plane is elsewhere and another flies to its origin', () => {
|
||||
const s = snap(
|
||||
[
|
||||
plane({ id: 'grounded-elsewhere', locationIcao: 'LEMD' }),
|
||||
plane({ id: 'en-route', status: 'flying', destIcao: 'EDDF' }), // flying TO the package's origin — not grounded there yet
|
||||
],
|
||||
[pkg({ id: 'x' })],
|
||||
);
|
||||
expect(visibleOpenPackages(s)).toEqual([]);
|
||||
});
|
||||
|
||||
it('keeps a payload-blocked row visible when a grounded plane at the origin has no room (disabled Load path preserved)', () => {
|
||||
const packages = [
|
||||
...Array.from({ length: 4 }, (_, i) => pkg({ id: `fill-${i}`, status: 'loaded', planeId: 'full', weightKg: 1_200 })), // 4 × 1200 = 4800 — full
|
||||
pkg({ id: 'x' }),
|
||||
];
|
||||
const s = snap([plane({ id: 'full' })], packages);
|
||||
expect(visibleOpenPackages(s).map((p) => p.id)).toEqual(['x']); // row stays…
|
||||
expect(loadEligiblePlanes(s, s.packages.find((p) => p.id === 'x')!)).toEqual([]); // …with Load disabled
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user