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:
@@ -31,19 +31,15 @@ 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/table/sciences"),
|
||||
params: { id: "g1" } as Record<string, string>,
|
||||
}));
|
||||
// The sciences table opens the science designer by switching the
|
||||
// active in-game view via `activeView.select("designer-science", …)`
|
||||
// (the single-URL app-shell has no `/games/:id/designer/...` route).
|
||||
// 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 TableSciences from "../src/lib/active-view/table-sciences.svelte";
|
||||
@@ -60,8 +56,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 () => {
|
||||
@@ -188,14 +183,14 @@ describe("sciences table", () => {
|
||||
expect(names).toEqual(["Beta", "Gamma", "Alpha"]);
|
||||
});
|
||||
|
||||
test("dblclick on a row navigates to the designer for that science", async () => {
|
||||
test("dblclick on a row opens the designer for that science", async () => {
|
||||
const ui = mountTable(
|
||||
makeReport([science({ name: "FirstStep", drive: 1 })]),
|
||||
);
|
||||
await fireEvent.dblClick(ui.getByTestId("sciences-row"));
|
||||
expect(gotoMock).toHaveBeenCalledWith(
|
||||
"/games/g1/designer/science/FirstStep",
|
||||
);
|
||||
expect(activeViewSelectMock).toHaveBeenCalledWith("designer-science", {
|
||||
scienceId: "FirstStep",
|
||||
});
|
||||
});
|
||||
|
||||
test("delete button adds a removeScience to the draft", async () => {
|
||||
@@ -207,9 +202,9 @@ describe("sciences table", () => {
|
||||
expect(cmd.name).toBe("FirstStep");
|
||||
});
|
||||
|
||||
test("new button navigates to the empty designer", async () => {
|
||||
test("new button opens the empty designer", async () => {
|
||||
const ui = mountTable(makeReport([]));
|
||||
await fireEvent.click(ui.getByTestId("sciences-new"));
|
||||
expect(gotoMock).toHaveBeenCalledWith("/games/g1/designer/science");
|
||||
expect(activeViewSelectMock).toHaveBeenCalledWith("designer-science");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user