Files
healer-man/src/game/dungeonSessionAssetCache.test.ts
T
2026-08-14 15:56:39 -04:00

32 lines
1.3 KiB
TypeScript

import { useGLTF } from "@react-three/drei";
import { afterEach, describe, expect, it, vi } from "vitest";
import { dungeonGltfUrls } from "./dungeonAssets";
import { dungeonDefinitionById } from "./dungeonRegistry";
import { activateDungeonSession } from "./dungeonSession";
import { useGameStore } from "./store";
describe("dungeon session asset eviction", () => {
afterEach(() => {
vi.restoreAllMocks();
useGameStore.getState().activateDungeon("wailing-caverns");
});
it("evicts the previous dungeon before publishing the next session", () => {
const previous = dungeonDefinitionById("auchenai-crypts")!;
useGameStore.getState().activateDungeon(previous.id);
const clear = vi.spyOn(useGLTF, "clear").mockImplementation(() => undefined);
expect(activateDungeonSession("wailing-caverns")).toBe(true);
expect(clear.mock.calls.map(([url]) => url)).toEqual(dungeonGltfUrls(previous));
expect(useGameStore.getState().activeDungeonId).toBe("wailing-caverns");
});
it("does not evict the active dungeon when the destination is invalid", () => {
const clear = vi.spyOn(useGLTF, "clear").mockImplementation(() => undefined);
expect(activateDungeonSession("not-a-dungeon")).toBe(false);
expect(clear).not.toHaveBeenCalled();
});
});