feat(ui): F8-05 — game-mode chrome cleanup + inspector compact rows (#48)
Drains six F8 polish items (parent #43) in one feature: а) Chrome cleanup - п.6 — remove the AccountMenu (settings/sessions/theme/language/logout ∼ rudimentary in-game) and replace it with a single icon-button light/dark theme toggle. The toggle flips an in-memory `theme.override`; game-shell unmount calls `theme.clearOverride()` so the lobby (and any re-entry) re-projects the persisted lobby choice. - п.8 — remove the wrap-scrolling radio from the map gear popover. The per-game `wrapMode` store and the renderer's no-wrap path stay in place for a future engine-side topology feature; only the UI surface is dropped (wrap is a server-side concept, not a per-session UI affordance). б) Inspector compact rows (single idiom: select + ✓ apply / ✗ cancel, or contextual edit/remove/add) - п.13 — planet name is now click-to-edit: clicking the name opens an inline `<input>` + ✓ confirm icon; Escape cancels; the explicit Rename action button and Cancel button are gone. - п.14 — production becomes one row: primary `<select>` picks industry/materials/research/ship, conditional secondary `<select>` picks the target (tech / science / ship class) for research and ship contexts. Apply is gated until row state differs from the planet's current effective production; auto-submit-on-click is replaced by the apply-gate. - п.16 — cargo routes collapse to one row: a single dropdown (COL/CAP/MAT/EMP plus a placeholder that absorbs the old section title) and contextual action buttons (add / edit + remove) to the right. After a successful pick or remove the dropdown stays on the type the user just acted on. - п.32 — stationed ship groups hoist the race column into a dropdown above the table. The dropdown seeds with the player's own race when local groups are stationed here, otherwise the first race alphabetically; rendered only when more than one race is in orbit. The race column is dropped in both single- and multi-race modes — the dropdown's value already names the active race. Tests: unit and Playwright e2e updated for every changed test-id and flow; new coverage added for `theme.override`, the in-game toggle, the apply-gate behaviour, and the stationed-race dropdown. i18n keys for the removed menu items, the wrap radios, the cargo title, and the explicit `rename.cancel` are dropped from both locales; new `game.shell.theme_toggle.*`, `production.main/target.*`, `production.apply/cancel`, `cargo.placeholder`, and `ship_groups.race_filter.aria` keys land. Docs synced: `docs/FUNCTIONAL.md` §6.7 + `docs/FUNCTIONAL_ru.md` mirror drop the torus / no-wrap radio mention; `ui/docs/design-system.md` documents the lobby-owned persisted picker + the in-game ephemeral override channel. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
// Vitest component coverage for the Phase 16 cargo-routes
|
||||
// subsection of the planet inspector. Drives the component against
|
||||
// a real `OrderDraftStore` (with `fake-indexeddb` standing in for
|
||||
// the browser IDB factory) and a stub `MapPickService` whose
|
||||
// `pick(...)` resolves to a script-controlled answer. The tests
|
||||
// assert the four-slot rendering, the picker invocation, the
|
||||
// per-(source, loadType) collapse rule, and the cancel path.
|
||||
// Vitest component coverage for the F8-05 cargo-routes subsection of
|
||||
// the planet inspector. Pre-F8-05 the surface rendered all four
|
||||
// COL/CAP/MAT/EMP slots side-by-side; F8-05 collapsed it into a
|
||||
// single `<select>` with a placeholder (absorbing the old section
|
||||
// title) and contextual `add` / `edit` + `remove` buttons that only
|
||||
// appear once the player picks a type. The tests drive the component
|
||||
// against a real `OrderDraftStore` (with `fake-indexeddb` standing
|
||||
// in for the browser IDB factory) and a stub `MapPickService` whose
|
||||
// `pick(...)` resolves to a script-controlled answer.
|
||||
|
||||
import "@testing-library/jest-dom/vitest";
|
||||
import "fake-indexeddb/auto";
|
||||
@@ -129,39 +131,48 @@ function mount(
|
||||
return { ui, pick };
|
||||
}
|
||||
|
||||
async function selectType(
|
||||
ui: ReturnType<typeof mount>["ui"],
|
||||
value: string,
|
||||
): Promise<void> {
|
||||
const select = ui.getByTestId(
|
||||
"inspector-planet-cargo-type",
|
||||
) as HTMLSelectElement;
|
||||
await fireEvent.change(select, { target: { value } });
|
||||
}
|
||||
|
||||
describe("planet inspector — cargo routes", () => {
|
||||
test("renders four slots in COL/CAP/MAT/EMP order", () => {
|
||||
const { ui, pick } = mount(
|
||||
test("dropdown exposes COL/CAP/MAT/EMP plus the placeholder; nothing else is rendered until a type is picked", () => {
|
||||
const { ui } = mount(
|
||||
makePlanet({ number: 1, name: "Earth", x: 100, y: 100 }),
|
||||
[makePlanet({ number: 1, name: "Earth", x: 100, y: 100 })],
|
||||
);
|
||||
const slots = ui.container.querySelectorAll(
|
||||
"[data-testid^='inspector-planet-cargo-slot-']",
|
||||
);
|
||||
const slotIds = Array.from(slots).map((el) =>
|
||||
el.getAttribute("data-testid"),
|
||||
);
|
||||
// Each slot generates several test ids (label + body items);
|
||||
// pick the row data-testid (slot itself, no suffix).
|
||||
const rowIds = slotIds.filter((id) =>
|
||||
/^inspector-planet-cargo-slot-(col|cap|mat|emp)$/.test(id ?? ""),
|
||||
);
|
||||
expect(rowIds).toEqual([
|
||||
"inspector-planet-cargo-slot-col",
|
||||
"inspector-planet-cargo-slot-cap",
|
||||
"inspector-planet-cargo-slot-mat",
|
||||
"inspector-planet-cargo-slot-emp",
|
||||
const select = ui.getByTestId(
|
||||
"inspector-planet-cargo-type",
|
||||
) as HTMLSelectElement;
|
||||
expect(Array.from(select.options).map((o) => o.value)).toEqual([
|
||||
"",
|
||||
"COL",
|
||||
"CAP",
|
||||
"MAT",
|
||||
"EMP",
|
||||
]);
|
||||
expect(select.value).toBe("");
|
||||
// No action buttons surface before a type is picked.
|
||||
expect(
|
||||
ui.queryByTestId("inspector-planet-cargo-slot-col-add"),
|
||||
).toBeNull();
|
||||
expect(
|
||||
ui.queryByTestId("inspector-planet-cargo-slot-col-destination"),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
test("an empty slot exposes the Add button and the (no route) marker", () => {
|
||||
const { ui, pick } = mount(
|
||||
test("selecting an empty type reveals the Add button", async () => {
|
||||
const { ui } = mount(
|
||||
makePlanet({ number: 1, name: "Earth", x: 100, y: 100 }),
|
||||
[makePlanet({ number: 1, name: "Earth", x: 100, y: 100 })],
|
||||
);
|
||||
expect(
|
||||
ui.getByTestId("inspector-planet-cargo-slot-col-empty"),
|
||||
).toBeInTheDocument();
|
||||
await selectType(ui, "COL");
|
||||
expect(
|
||||
ui.getByTestId("inspector-planet-cargo-slot-col-add"),
|
||||
).toBeInTheDocument();
|
||||
@@ -170,8 +181,8 @@ describe("planet inspector — cargo routes", () => {
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
test("a filled slot shows the destination name plus Edit and Remove", () => {
|
||||
const { ui, pick } = mount(
|
||||
test("selecting a filled type shows the destination plus Edit and Remove", async () => {
|
||||
const { ui } = mount(
|
||||
makePlanet({ number: 1, name: "Earth", x: 100, y: 100 }),
|
||||
[
|
||||
makePlanet({ number: 1, name: "Earth", x: 100, y: 100 }),
|
||||
@@ -184,6 +195,7 @@ describe("planet inspector — cargo routes", () => {
|
||||
},
|
||||
],
|
||||
);
|
||||
await selectType(ui, "COL");
|
||||
expect(
|
||||
ui.getByTestId("inspector-planet-cargo-slot-col-destination"),
|
||||
).toHaveTextContent("Mars");
|
||||
@@ -211,7 +223,10 @@ describe("planet inspector — cargo routes", () => {
|
||||
[],
|
||||
2,
|
||||
);
|
||||
await fireEvent.click(ui.getByTestId("inspector-planet-cargo-slot-col-add"));
|
||||
await selectType(ui, "COL");
|
||||
await fireEvent.click(
|
||||
ui.getByTestId("inspector-planet-cargo-slot-col-add"),
|
||||
);
|
||||
await waitFor(() => expect(pick.invocations.length).toBe(1));
|
||||
const invocation = pick.invocations[0]!;
|
||||
expect(invocation.request.sourcePlanetNumber).toBe(1);
|
||||
@@ -222,11 +237,7 @@ describe("planet inspector — cargo routes", () => {
|
||||
});
|
||||
|
||||
test("the reachable set spans every planet kind in range, not only own", async () => {
|
||||
// Reach = 40 * 1.5 = 60. Each candidate at distance 50 — in
|
||||
// reach. The picker must include the foreign-race planet,
|
||||
// the uninhabited rock, and the unidentified target so the
|
||||
// engine's "destinations may be any planet" rule is honoured
|
||||
// (route.go: only the source's ownership is enforced).
|
||||
// Reach = 40 * 1.5 = 60. Each candidate at distance 50 — in reach.
|
||||
const { ui, pick } = mount(
|
||||
makePlanet({
|
||||
number: 1,
|
||||
@@ -269,7 +280,10 @@ describe("planet inspector — cargo routes", () => {
|
||||
[],
|
||||
1.5,
|
||||
);
|
||||
await fireEvent.click(ui.getByTestId("inspector-planet-cargo-slot-col-add"));
|
||||
await selectType(ui, "COL");
|
||||
await fireEvent.click(
|
||||
ui.getByTestId("inspector-planet-cargo-slot-col-add"),
|
||||
);
|
||||
await waitFor(() => expect(pick.invocations.length).toBe(1));
|
||||
expect(
|
||||
Array.from(pick.invocations[0]!.request.reachableIds).sort(),
|
||||
@@ -304,7 +318,10 @@ describe("planet inspector — cargo routes", () => {
|
||||
[],
|
||||
1.5,
|
||||
);
|
||||
await fireEvent.click(ui.getByTestId("inspector-planet-cargo-slot-mat-add"));
|
||||
await selectType(ui, "MAT");
|
||||
await fireEvent.click(
|
||||
ui.getByTestId("inspector-planet-cargo-slot-mat-add"),
|
||||
);
|
||||
await waitFor(() => expect(pick.invocations.length).toBe(1));
|
||||
pick.invocations[0]!.resolve(9);
|
||||
await waitFor(() => expect(draft.commands).toHaveLength(1));
|
||||
@@ -325,7 +342,10 @@ describe("planet inspector — cargo routes", () => {
|
||||
[],
|
||||
2,
|
||||
);
|
||||
await fireEvent.click(ui.getByTestId("inspector-planet-cargo-slot-cap-add"));
|
||||
await selectType(ui, "CAP");
|
||||
await fireEvent.click(
|
||||
ui.getByTestId("inspector-planet-cargo-slot-cap-add"),
|
||||
);
|
||||
await waitFor(() => expect(pick.invocations.length).toBe(1));
|
||||
pick.invocations[0]!.resolve(2);
|
||||
await waitFor(() => expect(draft.commands).toHaveLength(1));
|
||||
@@ -342,6 +362,29 @@ describe("planet inspector — cargo routes", () => {
|
||||
);
|
||||
});
|
||||
|
||||
test("dropdown stays on the just-picked type after add resolves", async () => {
|
||||
const { ui, pick } = mount(
|
||||
makePlanet({ number: 1, name: "Earth", x: 100, y: 100 }),
|
||||
[
|
||||
makePlanet({ number: 1, name: "Earth", x: 100, y: 100 }),
|
||||
makePlanet({ number: 2, name: "Mars", x: 150, y: 100 }),
|
||||
],
|
||||
[],
|
||||
2,
|
||||
);
|
||||
await selectType(ui, "CAP");
|
||||
await fireEvent.click(
|
||||
ui.getByTestId("inspector-planet-cargo-slot-cap-add"),
|
||||
);
|
||||
await waitFor(() => expect(pick.invocations.length).toBe(1));
|
||||
pick.invocations[0]!.resolve(2);
|
||||
await waitFor(() => expect(draft.commands).toHaveLength(1));
|
||||
const select = ui.getByTestId(
|
||||
"inspector-planet-cargo-type",
|
||||
) as HTMLSelectElement;
|
||||
expect(select.value).toBe("CAP");
|
||||
});
|
||||
|
||||
test("cancel resolves null and emits no command", async () => {
|
||||
const { ui, pick } = mount(
|
||||
makePlanet({ number: 1, name: "Earth", x: 100, y: 100 }),
|
||||
@@ -350,7 +393,10 @@ describe("planet inspector — cargo routes", () => {
|
||||
makePlanet({ number: 2, name: "Mars", x: 150, y: 100 }),
|
||||
],
|
||||
);
|
||||
await fireEvent.click(ui.getByTestId("inspector-planet-cargo-slot-mat-add"));
|
||||
await selectType(ui, "MAT");
|
||||
await fireEvent.click(
|
||||
ui.getByTestId("inspector-planet-cargo-slot-mat-add"),
|
||||
);
|
||||
await waitFor(() => expect(pick.invocations.length).toBe(1));
|
||||
pick.invocations[0]!.resolve(null);
|
||||
await waitFor(() =>
|
||||
@@ -361,8 +407,8 @@ describe("planet inspector — cargo routes", () => {
|
||||
expect(draft.commands).toHaveLength(0);
|
||||
});
|
||||
|
||||
test("Remove emits removeCargoRoute for the slot", async () => {
|
||||
const { ui, pick } = mount(
|
||||
test("Remove emits removeCargoRoute for the selected type", async () => {
|
||||
const { ui } = mount(
|
||||
makePlanet({ number: 1, name: "Earth", x: 100, y: 100 }),
|
||||
[
|
||||
makePlanet({ number: 1, name: "Earth", x: 100, y: 100 }),
|
||||
@@ -375,6 +421,7 @@ describe("planet inspector — cargo routes", () => {
|
||||
},
|
||||
],
|
||||
);
|
||||
await selectType(ui, "EMP");
|
||||
await fireEvent.click(
|
||||
ui.getByTestId("inspector-planet-cargo-slot-emp-remove"),
|
||||
);
|
||||
@@ -401,13 +448,14 @@ describe("planet inspector — cargo routes", () => {
|
||||
},
|
||||
],
|
||||
);
|
||||
await selectType(ui, "COL");
|
||||
await fireEvent.click(
|
||||
ui.getByTestId("inspector-planet-cargo-slot-col-edit"),
|
||||
);
|
||||
await waitFor(() => expect(pick.invocations.length).toBe(1));
|
||||
pick.invocations[0]!.resolve(3);
|
||||
await waitFor(() => expect(draft.commands).toHaveLength(1));
|
||||
// Then a second edit to a different planet — collapse keeps a
|
||||
// A second edit to a different planet — collapse keeps a
|
||||
// single row.
|
||||
await fireEvent.click(
|
||||
ui.getByTestId("inspector-planet-cargo-slot-col-edit"),
|
||||
@@ -429,11 +477,17 @@ describe("planet inspector — cargo routes", () => {
|
||||
makePlanet({ number: 2, name: "Mars", x: 150, y: 100 }),
|
||||
],
|
||||
);
|
||||
await fireEvent.click(ui.getByTestId("inspector-planet-cargo-slot-col-add"));
|
||||
await selectType(ui, "COL");
|
||||
await fireEvent.click(
|
||||
ui.getByTestId("inspector-planet-cargo-slot-col-add"),
|
||||
);
|
||||
await waitFor(() => expect(pick.invocations.length).toBe(1));
|
||||
pick.invocations[0]!.resolve(2);
|
||||
await waitFor(() => expect(draft.commands).toHaveLength(1));
|
||||
await fireEvent.click(ui.getByTestId("inspector-planet-cargo-slot-cap-add"));
|
||||
await selectType(ui, "CAP");
|
||||
await fireEvent.click(
|
||||
ui.getByTestId("inspector-planet-cargo-slot-cap-add"),
|
||||
);
|
||||
await waitFor(() => expect(pick.invocations.length).toBe(2));
|
||||
pick.invocations[1]!.resolve(2);
|
||||
await waitFor(() => expect(draft.commands).toHaveLength(2));
|
||||
@@ -444,8 +498,8 @@ describe("planet inspector — cargo routes", () => {
|
||||
expect(types).toEqual(["CAP", "COL"]);
|
||||
});
|
||||
|
||||
test("no_destinations message appears when reach is positive but every planet is out of range", () => {
|
||||
const { ui, pick } = mount(
|
||||
test("no_destinations message appears once a type is picked and every planet is out of range", async () => {
|
||||
const { ui } = mount(
|
||||
makePlanet({ number: 1, name: "Earth", x: 100, y: 100 }),
|
||||
[
|
||||
makePlanet({ number: 1, name: "Earth", x: 100, y: 100 }),
|
||||
@@ -454,6 +508,11 @@ describe("planet inspector — cargo routes", () => {
|
||||
[],
|
||||
0.1, // reach 4 — far less than 5000 distance
|
||||
);
|
||||
// Hidden until the player engages with the dropdown.
|
||||
expect(
|
||||
ui.queryByTestId("inspector-planet-cargo-no-destinations"),
|
||||
).toBeNull();
|
||||
await selectType(ui, "COL");
|
||||
expect(
|
||||
ui.getByTestId("inspector-planet-cargo-no-destinations"),
|
||||
).toBeInTheDocument();
|
||||
|
||||
Reference in New Issue
Block a user