test(ui): migrate suite to the app-shell (state-driven navigation)

- Unit: repoint moved screen imports (lib/screens, lib/game), mock
  $lib/app-nav (appScreen/activeView) instead of $app/navigation, drop the
  removed gameId props, assert screen/view selection.
- e2e: add a dev-only window.__galaxyNav affordance; specs enter a game via
  enterGame(...) instead of a /games/:id URL; URL assertions become content
  assertions (the URL stays /game/); reload uses waitUntil:"commit" (shallow
  routing) and mocks /rpc on game entry.
- Remove the obsolete report scroll-restore test (it relied on a SvelteKit
  route Snapshot that no longer exists); update the missing-membership test
  to the new lobby-redirect+toast behaviour. Fix a stale report.svelte
  docstring.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ilia Denisov
2026-05-23 20:49:35 +02:00
parent 80545e9f9d
commit 4e0058d46c
36 changed files with 707 additions and 343 deletions
+23 -21
View File
@@ -33,19 +33,16 @@ import { EMPTY_SHIP_GROUPS } from "./helpers/empty-ship-groups";
const GAME_ID = "11111111-2222-3333-4444-555555555555";
const pageMock = vi.hoisted(() => ({
url: new URL("http://localhost/games/g1/designer/science"),
params: { id: "g1" } as Record<string, string>,
}));
// The science designer reads its target science from the `scienceId`
// prop (the single-URL app-shell passes view sub-parameters as props,
// not URL segments) and returns to the sciences table by switching the
// active in-game view via `activeView.select("table", …)`. Mock the
// nav store so the spy captures the view switch and no real `pushState`
// runs.
const activeViewSelectMock = vi.hoisted(() => vi.fn());
const gotoMock = vi.hoisted(() => vi.fn());
vi.mock("$app/state", () => ({
page: pageMock,
}));
vi.mock("$app/navigation", () => ({
goto: gotoMock,
vi.mock("$lib/app-nav.svelte", () => ({
activeView: { select: activeViewSelectMock },
}));
import DesignerScience from "../src/lib/active-view/designer-science.svelte";
@@ -62,8 +59,7 @@ beforeEach(async () => {
draft = new OrderDraftStore();
await draft.init({ cache, gameId: GAME_ID });
i18n.resetForTests("en");
pageMock.params = { id: "g1" };
gotoMock.mockClear();
activeViewSelectMock.mockClear();
});
afterEach(async () => {
@@ -113,9 +109,6 @@ function mountDesigner(opts: {
report?: GameReport | null;
}) {
const report = opts.report ?? makeReport();
pageMock.params = opts.scienceId
? { id: "g1", scienceId: opts.scienceId }
: { id: "g1" };
const renderedReport = {
get report() {
return report;
@@ -125,7 +118,10 @@ function mountDesigner(opts: {
[ORDER_DRAFT_CONTEXT_KEY, draft],
[RENDERED_REPORT_CONTEXT_KEY, renderedReport],
]);
return render(DesignerScience, { context });
return render(DesignerScience, {
props: opts.scienceId ? { scienceId: opts.scienceId } : {},
context,
});
}
describe("science designer (new mode)", () => {
@@ -172,7 +168,9 @@ describe("science designer (new mode)", () => {
expect(cmd.shields).toBeCloseTo(0.25, 12);
expect(cmd.cargo).toBeCloseTo(0.25, 12);
await waitFor(() =>
expect(gotoMock).toHaveBeenCalledWith("/games/g1/table/sciences"),
expect(activeViewSelectMock).toHaveBeenCalledWith("table", {
tableEntity: "sciences",
}),
);
});
@@ -238,7 +236,9 @@ describe("science designer (new mode)", () => {
const ui = mountDesigner({});
await fireEvent.click(ui.getByTestId("designer-science-cancel"));
expect(draft.commands).toHaveLength(0);
expect(gotoMock).toHaveBeenCalledWith("/games/g1/table/sciences");
expect(activeViewSelectMock).toHaveBeenCalledWith("table", {
tableEntity: "sciences",
});
});
});
@@ -286,7 +286,9 @@ describe("science designer (view mode)", () => {
if (cmd.kind !== "removeScience") throw new Error("wrong kind");
expect(cmd.name).toBe("FirstStep");
await waitFor(() =>
expect(gotoMock).toHaveBeenCalledWith("/games/g1/table/sciences"),
expect(activeViewSelectMock).toHaveBeenCalledWith("table", {
tableEntity: "sciences",
}),
);
});