ui/phase-23: turn-report view with twenty sections and TOC

Replaces the Phase 10 report stub with a scrollable orchestrator that
renders every FBS array as a dedicated section (galaxy summary, votes,
player status, my/foreign sciences, my/foreign ship classes, battles,
bombings, approaching groups, my/foreign/uninhabited/unknown planets,
ships in production, cargo routes, my fleets, my/foreign/unidentified
ship groups). A sticky table of contents (a <select> on mobile),
"back to map" affordance, IntersectionObserver-driven active-section
highlight, and SvelteKit Snapshot-based scroll save/restore round out
the view.

GameReport gains six new fields (players, otherScience, otherShipClass,
battleIds, bombings, shipProductions); decodeReport, the synthetic-
report loader, the e2e fixture builder, and EMPTY_SHIP_GROUPS extend
in lockstep. ~90 new i18n keys land in en + ru together.

The legacy-report parser is extended to populate the new sections from
the dg/gplus text formats (Your Sciences, <Race> Sciences, <Race> Ship
Types, Bombings, Ships In Production). Ships-in-production prod_used
is derived through a new pkg/calc.ShipBuildCost helper; the engine's
controller.ProduceShip refactors to call the same helper without any
behaviour change (engine tests stay unchanged and green). Battles
remain in the parser's Skipped list — the legacy text carries no
stable per-battle UUID.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Ilia Denisov
2026-05-11 14:33:56 +02:00
parent 81d8be08b2
commit c58027c034
48 changed files with 5368 additions and 103 deletions
@@ -0,0 +1,88 @@
// Vitest coverage for the Phase 23 Report View's galaxy summary
// section. Representative for kv-list-shape sections (votes,
// player-status row markers). Mounts the component against a
// synthetic `RenderedReportSource` so the test focuses on shape,
// not on the live store wiring.
import "@testing-library/jest-dom/vitest";
import { render } from "@testing-library/svelte";
import { beforeEach, describe, expect, test } from "vitest";
import { i18n } from "../src/lib/i18n/index.svelte";
import type { GameReport } from "../src/api/game-state";
import { RENDERED_REPORT_CONTEXT_KEY } from "../src/lib/rendered-report.svelte";
import { EMPTY_SHIP_GROUPS } from "./helpers/empty-ship-groups";
import SectionGalaxySummary from "../src/lib/active-view/report/section-galaxy-summary.svelte";
beforeEach(() => {
i18n.resetForTests("en");
});
function makeReport(overrides: Partial<GameReport> = {}): GameReport {
return {
turn: 0,
mapWidth: 0,
mapHeight: 0,
planetCount: 0,
planets: [],
race: "",
localShipClass: [],
routes: [],
localPlayerDrive: 0,
localPlayerWeapons: 0,
localPlayerShields: 0,
localPlayerCargo: 0,
...EMPTY_SHIP_GROUPS,
...overrides,
};
}
function mountSection(report: GameReport | null) {
const context = new Map<unknown, unknown>([
[RENDERED_REPORT_CONTEXT_KEY, { get report() {
return report;
} }],
]);
return render(SectionGalaxySummary, { context });
}
describe("report galaxy summary section", () => {
test("renders the loading placeholder before the report lands", () => {
const ui = mountSection(null);
expect(
ui.getByTestId("report-section-galaxy-summary"),
).toHaveTextContent("loading report");
});
test("renders every kv pair for a populated report", () => {
const ui = mountSection(
makeReport({
turn: 42,
mapWidth: 1234,
mapHeight: 4321,
planetCount: 700,
race: "KnightErrants",
}),
);
expect(ui.getByTestId("galaxy-summary-field-turn")).toHaveTextContent("42");
expect(ui.getByTestId("galaxy-summary-field-size")).toHaveTextContent(
"1234 × 4321",
);
expect(ui.getByTestId("galaxy-summary-field-planets")).toHaveTextContent(
"700",
);
expect(ui.getByTestId("galaxy-summary-field-race")).toHaveTextContent(
"KnightErrants",
);
});
test("zero-value boot state still mounts every field", () => {
const ui = mountSection(makeReport());
// Loading state must be gone — the kv-list takes over.
const section = ui.getByTestId("report-section-galaxy-summary");
expect(section).not.toHaveTextContent("loading report");
expect(ui.getByTestId("galaxy-summary-field-turn")).toHaveTextContent("0");
expect(ui.getByTestId("galaxy-summary-field-race")).toHaveTextContent("");
});
});