24c68e9846
Tests · UI / test (push) Has been cancelled
Tests · Go / test (pull_request) Successful in 2m6s
Tests · Go / test (push) Successful in 2m6s
Tests · Integration / integration (pull_request) Successful in 1m51s
Tests · UI / test (pull_request) Successful in 3m53s
Issue #48 п.32 ("Stationed ship groups") shipped with a fragile race fallback: when a foreign group sat on a non-`other`-kind planet the inspector printed a generic "foreign" label, which collapsed the race dropdown to a single uninformative bucket. The engine FBS contract did not carry per-group race either, so live games hit the same gap. This patch carries race authoritatively from the engine through every layer down to the inspector. Wire format & engine - `pkg/schema/fbs/report.fbs`: add `race:string` to `OtherGroup` and `LocalGroup` (additive — old clients ignore). - `pkg/schema/fbs/report/`: regenerated Go bindings. - `ui/frontend/src/proto/galaxy/fbs/report/`: regenerated TS bindings. - `pkg/model/report.OtherGroup.Race`: new field; carried through `LocalGroup` via the embedded `OtherGroup`. - `pkg/transcoder/report.go`: encode + decode `race` on both `LocalGroup` and `OtherGroup`. - `game/internal/controller/report.go.otherGroup`: set `v.Race` from `c.g.Race[c.RaceIndex(sg.OwnerID)].Name` so every emitted group — own or foreign — carries the resolved race name. Legacy parser - `tools/local-dev/legacy-report/parser.go`: capture the `<Race> Groups` header into `pendingOtherGroup.race`, fill local group `Race` from `p.rep.Race`, propagate both into the `report.OtherGroup` rows. - Tests + smoke counts updated; regenerated `KNNTS{039,041}.json` fixtures so the synthetic loader carries the new field. UI - `ui/frontend/src/api/`: `ReportShipGroupBase.race` field; synthetic loader + FBS decoder populate it. - `ui/frontend/src/lib/inspectors/planet/ship-groups.svelte`: the stationed-groups inspector picks race directly from `group.race` (own falls back to `localRace`, both finally to the `race.unknown` placeholder). The planet-owner / "foreign" heuristic is gone. - Row label changes from "N ships mass M" to a compact `<class>` | `<N ×>` | `<mass>` three-column layout: the count cell is right-aligned tabular, the mass cell is right-aligned monospace + tabular, matching the inspector / calculator number conventions. Stale i18n keys removed (`ship_groups.row.count`, `.row.mass`, `.race.foreign`). - All affected unit tests (8 files) carry the new `race` field. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
234 lines
6.6 KiB
TypeScript
234 lines
6.6 KiB
TypeScript
// Vitest component coverage for the Phase 19 read-only ship-group
|
|
// inspector. The inspector dispatches on the selection variant —
|
|
// local / other / incoming / unidentified — and renders a fixed set
|
|
// of fields per branch. The tests assert each branch surfaces the
|
|
// fields the acceptance criteria call out, plus the
|
|
// "no destination resolution" fallback.
|
|
|
|
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 {
|
|
ReportIncomingShipGroup,
|
|
ReportLocalShipGroup,
|
|
ReportOtherShipGroup,
|
|
ReportPlanet,
|
|
ReportUnidentifiedShipGroup,
|
|
} from "../src/api/game-state";
|
|
import ShipGroup, {
|
|
type ShipGroupSelection,
|
|
} from "../src/lib/inspectors/ship-group.svelte";
|
|
|
|
const PLANETS: ReportPlanet[] = [
|
|
{
|
|
number: 17,
|
|
name: "Castle",
|
|
x: 100,
|
|
y: 100,
|
|
kind: "local",
|
|
owner: null,
|
|
size: 1000,
|
|
resources: 10,
|
|
industryStockpile: 0,
|
|
materialsStockpile: 0,
|
|
industry: 1000,
|
|
population: 1000,
|
|
colonists: 0,
|
|
production: "Capital",
|
|
freeIndustry: 1000,
|
|
},
|
|
{
|
|
number: 99,
|
|
name: "Outpost",
|
|
x: 200,
|
|
y: 200,
|
|
kind: "other",
|
|
owner: "Foreign",
|
|
size: 500,
|
|
resources: 5,
|
|
industryStockpile: 0,
|
|
materialsStockpile: 0,
|
|
industry: 500,
|
|
population: 500,
|
|
colonists: 0,
|
|
production: "Capital",
|
|
freeIndustry: 500,
|
|
},
|
|
];
|
|
|
|
beforeEach(() => {
|
|
i18n.resetForTests("en");
|
|
});
|
|
|
|
function localGroup(
|
|
overrides: Partial<ReportLocalShipGroup> = {},
|
|
): ReportLocalShipGroup {
|
|
return {
|
|
id: "uuid-1",
|
|
count: 2,
|
|
class: "Frontier",
|
|
tech: { drive: 5, weapons: 0, shields: 0, cargo: 1 },
|
|
cargo: "NONE",
|
|
load: 0,
|
|
destination: 17,
|
|
origin: null,
|
|
range: null,
|
|
speed: 0,
|
|
mass: 12,
|
|
state: "In_Orbit",
|
|
fleet: null,
|
|
race: "Earthlings",
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
describe("ship-group inspector", () => {
|
|
test("renders the on-planet local group with all required fields", () => {
|
|
const selection: ShipGroupSelection = {
|
|
variant: "local",
|
|
group: localGroup(),
|
|
};
|
|
const ui = render(ShipGroup, { props: { selection, planets: PLANETS } });
|
|
expect(ui.getByTestId("inspector-ship-group-class")).toHaveTextContent(
|
|
"Frontier",
|
|
);
|
|
expect(ui.getByTestId("inspector-ship-group-field-count")).toHaveTextContent(
|
|
"2",
|
|
);
|
|
expect(ui.getByTestId("inspector-ship-group-field-drive")).toHaveTextContent(
|
|
"5",
|
|
);
|
|
expect(
|
|
ui.getByTestId("inspector-ship-group-field-location"),
|
|
).toHaveTextContent("Castle");
|
|
expect(ui.getByTestId("inspector-ship-group-field-state")).toHaveTextContent(
|
|
"In_Orbit",
|
|
);
|
|
expect(
|
|
ui.queryByTestId("inspector-ship-group-field-distance"),
|
|
).toBeNull();
|
|
});
|
|
|
|
test("renders the in-hyperspace local group with from / to / distance", () => {
|
|
const selection: ShipGroupSelection = {
|
|
variant: "local",
|
|
group: localGroup({
|
|
origin: 17,
|
|
range: 4.5,
|
|
destination: 99,
|
|
state: "In_Space",
|
|
}),
|
|
};
|
|
const ui = render(ShipGroup, { props: { selection, planets: PLANETS } });
|
|
expect(ui.getByTestId("inspector-ship-group-field-from")).toHaveTextContent(
|
|
"Castle",
|
|
);
|
|
expect(ui.getByTestId("inspector-ship-group-field-to")).toHaveTextContent(
|
|
"Outpost",
|
|
);
|
|
expect(
|
|
ui.getByTestId("inspector-ship-group-field-distance"),
|
|
).toHaveTextContent("4.5");
|
|
expect(
|
|
ui.queryByTestId("inspector-ship-group-field-location"),
|
|
).toBeNull();
|
|
});
|
|
|
|
test("renders cargo type and amount when the group is loaded", () => {
|
|
const selection: ShipGroupSelection = {
|
|
variant: "local",
|
|
group: localGroup({ cargo: "COL", load: 1.05 }),
|
|
};
|
|
const ui = render(ShipGroup, { props: { selection, planets: PLANETS } });
|
|
const cargo = ui.getByTestId("inspector-ship-group-field-cargo-load");
|
|
expect(cargo).toHaveTextContent("colonists");
|
|
expect(cargo).toHaveTextContent("1.05");
|
|
});
|
|
|
|
test("renders foreign group without fleet/state but with full tech", () => {
|
|
const group: ReportOtherShipGroup = {
|
|
count: 5,
|
|
class: "Cruiser",
|
|
tech: { drive: 8, weapons: 4, shields: 3, cargo: 1 },
|
|
cargo: "NONE",
|
|
load: 0,
|
|
destination: 99,
|
|
origin: null,
|
|
range: null,
|
|
speed: 0,
|
|
mass: 50,
|
|
race: "Klingons",
|
|
};
|
|
const selection: ShipGroupSelection = { variant: "other", group };
|
|
const ui = render(ShipGroup, { props: { selection, planets: PLANETS } });
|
|
expect(ui.getByTestId("inspector-ship-group-class")).toHaveTextContent(
|
|
"Cruiser",
|
|
);
|
|
expect(ui.queryByTestId("inspector-ship-group-field-fleet")).toBeNull();
|
|
expect(ui.queryByTestId("inspector-ship-group-field-state")).toBeNull();
|
|
});
|
|
|
|
test("incoming group surfaces ETA and trajectory fields", () => {
|
|
const group: ReportIncomingShipGroup = {
|
|
origin: 99,
|
|
destination: 17,
|
|
distance: 80,
|
|
speed: 25,
|
|
mass: 4,
|
|
};
|
|
const selection: ShipGroupSelection = { variant: "incoming", group };
|
|
const ui = render(ShipGroup, { props: { selection, planets: PLANETS } });
|
|
expect(ui.getByTestId("inspector-ship-group-field-from")).toHaveTextContent(
|
|
"Outpost",
|
|
);
|
|
expect(ui.getByTestId("inspector-ship-group-field-to")).toHaveTextContent(
|
|
"Castle",
|
|
);
|
|
// ETA = ceil(80 / 25) = 4.
|
|
expect(ui.getByTestId("inspector-ship-group-field-eta")).toHaveTextContent(
|
|
"4",
|
|
);
|
|
expect(
|
|
ui.getByTestId("inspector-ship-group-field-distance"),
|
|
).toHaveTextContent("80");
|
|
});
|
|
|
|
test("incoming group with zero speed renders ETA as the dash placeholder", () => {
|
|
const group: ReportIncomingShipGroup = {
|
|
origin: 99,
|
|
destination: 17,
|
|
distance: 80,
|
|
speed: 0,
|
|
mass: 4,
|
|
};
|
|
const selection: ShipGroupSelection = { variant: "incoming", group };
|
|
const ui = render(ShipGroup, { props: { selection, planets: PLANETS } });
|
|
expect(ui.getByTestId("inspector-ship-group-field-eta")).toHaveTextContent(
|
|
"—",
|
|
);
|
|
});
|
|
|
|
test("unidentified group renders coordinates and the no-data hint", () => {
|
|
const group: ReportUnidentifiedShipGroup = { x: 555.5, y: 222.25 };
|
|
const selection: ShipGroupSelection = { variant: "unidentified", group };
|
|
const ui = render(ShipGroup, { props: { selection, planets: PLANETS } });
|
|
const coords = ui.getByTestId("inspector-ship-group-field-coordinates");
|
|
expect(coords).toHaveTextContent("555.5");
|
|
expect(coords).toHaveTextContent("222.25");
|
|
expect(ui.getByTestId("inspector-ship-group-no-data")).toBeInTheDocument();
|
|
});
|
|
|
|
test("planet name resolves to '#NN' when missing from the planet list", () => {
|
|
const selection: ShipGroupSelection = {
|
|
variant: "local",
|
|
group: localGroup({ destination: 999 }),
|
|
};
|
|
const ui = render(ShipGroup, { props: { selection, planets: PLANETS } });
|
|
expect(
|
|
ui.getByTestId("inspector-ship-group-field-location"),
|
|
).toHaveTextContent("#999");
|
|
});
|
|
});
|