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,135 @@
// Vitest coverage for the Phase 23 Report View's bombings section.
// Representative for grid-shape sections (foreign/uninhabited
// planets, fleets, ship-groups, ships-in-production). Three
// scenarios — empty list, populated row, wiped row with badge —
// cover the empty-state copy and the conditional row state.
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,
ReportBombing,
} 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 SectionBombings from "../src/lib/active-view/report/section-bombings.svelte";
beforeEach(() => {
i18n.resetForTests("en");
});
function bombing(
overrides: Partial<ReportBombing> &
Pick<ReportBombing, "planetNumber" | "planet" | "attacker">,
): ReportBombing {
return {
owner: "Owner",
production: "Capital",
industry: 0,
population: 0,
colonists: 0,
industryStockpile: 0,
materialsStockpile: 0,
attackPower: 0,
wiped: false,
...overrides,
};
}
function makeReport(rows: ReportBombing[]): GameReport {
return {
turn: 1,
mapWidth: 1000,
mapHeight: 1000,
planetCount: 0,
planets: [],
race: "Self",
localShipClass: [],
routes: [],
localPlayerDrive: 0,
localPlayerWeapons: 0,
localPlayerShields: 0,
localPlayerCargo: 0,
...EMPTY_SHIP_GROUPS,
bombings: rows,
};
}
function mountSection(report: GameReport | null) {
const context = new Map<unknown, unknown>([
[RENDERED_REPORT_CONTEXT_KEY, { get report() {
return report;
} }],
]);
return render(SectionBombings, { context });
}
describe("report bombings section", () => {
test("renders the loading placeholder before the report lands", () => {
const ui = mountSection(null);
expect(ui.getByTestId("report-section-bombings")).toHaveTextContent(
"loading report",
);
});
test("renders the empty-state copy when there are no bombings", () => {
const ui = mountSection(makeReport([]));
expect(ui.getByTestId("bombings-empty")).toBeInTheDocument();
});
test("renders a non-wiped row without the wiped badge", () => {
const ui = mountSection(
makeReport([
bombing({
planetNumber: 17,
planet: "Castle",
attacker: "Ricksha",
owner: "Earthlings",
production: "Capital",
industry: 500.25,
population: 200,
colonists: 12,
industryStockpile: 30,
materialsStockpile: 5,
attackPower: 250,
wiped: false,
}),
]),
);
const rows = ui.getAllByTestId("report-bombing-row");
expect(rows).toHaveLength(1);
expect(rows[0]).toHaveAttribute("data-planet", "17");
expect(rows[0]).toHaveAttribute("data-wiped", "false");
expect(rows[0]).not.toHaveClass("wiped");
expect(rows[0]).toHaveTextContent("#17 (Castle)");
expect(rows[0]).toHaveTextContent("Ricksha");
expect(ui.queryByTestId("report-bombing-wiped-badge")).not.toBeInTheDocument();
});
test("renders a wiped row with the wiped badge and the row state", () => {
const ui = mountSection(
makeReport([
bombing({
planetNumber: 20,
planet: "DW-1207",
attacker: "Ricksha",
owner: "KnightErrants",
production: "Dron",
industry: 1.5,
attackPower: 7.62,
wiped: true,
}),
]),
);
const row = ui.getByTestId("report-bombing-row");
expect(row).toHaveAttribute("data-wiped", "true");
expect(row).toHaveClass("wiped");
expect(ui.getByTestId("report-bombing-wiped-badge")).toHaveTextContent(
"wiped",
);
});
});