ui/phase-14: rename planet end-to-end + order read-back

Wires the first end-to-end command through the full pipeline:
inspector rename action → local order draft → user.games.order
submit → optimistic overlay on map / inspector → server hydration
on cache miss via the new user.games.order.get message type.

Backend: GET /api/v1/user/games/{id}/orders forwards to engine
GET /api/v1/order. Gateway parses the engine PUT response into the
extended UserGamesOrderResponse FBS envelope and adds
executeUserGamesOrderGet for the read-back path. Frontend ports
ValidateTypeName to TS, lands the inline rename editor + Submit
button, and exposes a renderedReport context so consumers see the
overlay-applied snapshot.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Ilia Denisov
2026-05-09 11:50:09 +02:00
parent 381e41b325
commit f80c623a74
86 changed files with 7505 additions and 138 deletions
+123 -1
View File
@@ -5,12 +5,19 @@
// drive it with synthetic `ReportPlanet` literals — no store.
import "@testing-library/jest-dom/vitest";
import { render } from "@testing-library/svelte";
import "fake-indexeddb/auto";
import { fireEvent, render } from "@testing-library/svelte";
import { beforeEach, describe, expect, test } from "vitest";
import { i18n } from "../src/lib/i18n/index.svelte";
import type { ReportPlanet } from "../src/api/game-state";
import Planet from "../src/lib/inspectors/planet.svelte";
import {
ORDER_DRAFT_CONTEXT_KEY,
OrderDraftStore,
} from "../src/sync/order-draft.svelte";
import { IDBCache } from "../src/platform/store/idb-cache";
import { openGalaxyDB } from "../src/platform/store/idb";
beforeEach(() => {
i18n.resetForTests("en");
@@ -192,6 +199,121 @@ describe("planet inspector", () => {
expect(ui.queryByTestId("inspector-planet-field-natural_resources")).toBeNull();
});
test("Rename action is hidden for non-local planets", () => {
const ui = render(Planet, {
props: {
planet: makePlanet({
number: 9,
name: "Far",
kind: "other",
owner: "Federation",
size: 100,
resources: 5,
}),
},
});
expect(ui.queryByTestId("inspector-planet-rename-action")).toBeNull();
});
test("Rename action opens an inline editor and validates locally", async () => {
const dbName = `galaxy-rename-${crypto.randomUUID()}`;
const db = await openGalaxyDB(dbName);
const cache = new IDBCache(db);
const draft = new OrderDraftStore();
await draft.init({ cache, gameId: "00000000-0000-0000-0000-000000000abc" });
const context = new Map<unknown, unknown>([
[ORDER_DRAFT_CONTEXT_KEY, draft],
]);
const ui = render(Planet, {
props: {
planet: makePlanet({
number: 7,
name: "Earth",
kind: "local",
size: 100,
resources: 5,
population: 100,
colonists: 0,
industry: 0,
industryStockpile: 0,
materialsStockpile: 0,
production: "drive",
freeIndustry: 0,
}),
},
context,
});
const action = ui.getByTestId("inspector-planet-rename-action");
await fireEvent.click(action);
const input = ui.getByTestId("inspector-planet-rename-input") as HTMLInputElement;
expect(input.value).toBe("Earth");
const confirm = ui.getByTestId("inspector-planet-rename-confirm");
expect(confirm).not.toBeDisabled();
await fireEvent.input(input, { target: { value: " " } });
expect(ui.getByTestId("inspector-planet-rename-error")).toBeVisible();
expect(confirm).toBeDisabled();
await fireEvent.input(input, { target: { value: "New Earth!" } });
// Whitespace inside disallowed
expect(ui.getByTestId("inspector-planet-rename-error")).toBeVisible();
expect(confirm).toBeDisabled();
await fireEvent.input(input, { target: { value: "Mars-2" } });
expect(ui.queryByTestId("inspector-planet-rename-error")).toBeNull();
expect(confirm).not.toBeDisabled();
await fireEvent.click(confirm);
expect(draft.commands).toHaveLength(1);
const cmd = draft.commands[0]!;
expect(cmd.kind).toBe("planetRename");
if (cmd.kind !== "planetRename") return;
expect(cmd.planetNumber).toBe(7);
expect(cmd.name).toBe("Mars-2");
draft.dispose();
db.close();
});
test("Cancel closes the editor without adding to the draft", async () => {
const dbName = `galaxy-rename-${crypto.randomUUID()}`;
const db = await openGalaxyDB(dbName);
const cache = new IDBCache(db);
const draft = new OrderDraftStore();
await draft.init({ cache, gameId: "00000000-0000-0000-0000-000000000abc" });
const context = new Map<unknown, unknown>([
[ORDER_DRAFT_CONTEXT_KEY, draft],
]);
const ui = render(Planet, {
props: {
planet: makePlanet({
number: 1,
name: "Earth",
kind: "local",
size: 100,
resources: 5,
population: 1,
colonists: 0,
industry: 0,
industryStockpile: 0,
materialsStockpile: 0,
production: "drive",
freeIndustry: 0,
}),
},
context,
});
await fireEvent.click(ui.getByTestId("inspector-planet-rename-action"));
await fireEvent.click(ui.getByTestId("inspector-planet-rename-cancel"));
expect(ui.queryByTestId("inspector-planet-rename")).toBeNull();
expect(draft.commands).toEqual([]);
draft.dispose();
db.close();
});
test("missing production string falls back to the localised placeholder", () => {
const ui = render(Planet, {
props: {