Files
healer-man/src/platform/hudSnapshot.test.ts
T
2026-09-14 13:20:20 -04:00

55 lines
3.0 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { currentHudSnapshot } from "./hudSnapshot";
import { executeCompanionCommand } from "./dualScreenSync";
import { useGameStore } from "../game/store";
import { useUiLayoutStore } from "../game/uiLayoutStore";
import { normalizeUiPreferences } from "../game/uiLayout";
import { BOSS_TESTING_CATALOG, createBossTestingRoom } from "../game/bossTesting";
import { clearBossTestingDungeons, registerBossTestingDungeon, requireDungeonDefinition } from "../game/dungeonRegistry";
describe("remote HUD presentation", () => {
it("carries the isolated boss room to the lower display without simulation methods", () => {
const original = useGameStore.getState();
const boss = BOSS_TESTING_CATALOG.find((entry) => entry.dungeonId === "wailing-caverns")!;
const room = createBossTestingRoom(requireDungeonDefinition(boss.dungeonId), boss);
try {
registerBossTestingDungeon(room.definition, boss.dungeonId);
useGameStore.getState().activateDungeon(room.definition.id, undefined, { bossTest: room.session, gmTestMode: true });
const snapshot = structuredClone(currentHudSnapshot());
expect(snapshot.bossTestingDungeon?.definition).toEqual(room.definition);
expect(snapshot.game.bossTest).toEqual(room.session);
clearBossTestingDungeons();
registerBossTestingDungeon(snapshot.bossTestingDungeon!.definition, snapshot.bossTestingDungeon!.sourceDungeonId);
expect(requireDungeonDefinition(snapshot.game.activeDungeonId).staticSpawns).toHaveLength(1);
} finally {
useGameStore.setState(original);
clearBossTestingDungeons();
}
});
it("contains cloneable presentation data without simulation methods", () => {
const snapshot = currentHudSnapshot();
expect(() => structuredClone(snapshot)).not.toThrow();
expect(snapshot.combat).not.toHaveProperty("tick");
expect(snapshot.game).not.toHaveProperty("activateDungeon");
expect(snapshot.party).not.toHaveProperty("recallParty");
});
it("accepts bounded moves only while the authoritative editor is open", () => {
const originalUi = useUiLayoutStore.getState();
const originalGame = useGameStore.getState();
try {
const draft = normalizeUiPreferences(null).current.mobile;
useUiLayoutStore.setState({ draft });
useGameStore.setState({ overlay: null });
executeCompanionCommand({ name: "editHudElement", id: "party", update: { position: { x: .8, y: .7 } } });
expect(useUiLayoutStore.getState().draft).toBe(draft);
useGameStore.setState({ overlay: "ui-layout" });
executeCompanionCommand({ name: "editHudElement", id: "party", update: { position: { x: 5, y: -1 }, width: 99999, screen: "hidden" } });
expect(useUiLayoutStore.getState().draft?.elements.party).toMatchObject({ position: { x: 1, y: 0 }, width: 2000, visible: true });
expect(useUiLayoutStore.getState().draft?.elements.party.screen).toBeUndefined();
} finally {
useUiLayoutStore.setState(originalUi);
useGameStore.setState(originalGame);
}
});
});