|
|
@ -1,6 +1,7 @@ |
|
|
import { describe, expect, it, vi } from "vitest"; |
|
|
import { describe, expect, it, vi } from "vitest"; |
|
|
import ChaseScene from "../../src/stages/page_chase"; |
|
|
import ChaseScene from "../../src/stages/page_chase"; |
|
|
import InitScene from "../../src/stages/page_init"; |
|
|
import InitScene from "../../src/stages/page_init"; |
|
|
|
|
|
import { sceneManager } from "../../src/scene/SceneManager"; |
|
|
import { Text } from "pixi.js"; |
|
|
import { Text } from "pixi.js"; |
|
|
|
|
|
|
|
|
function createSceneState() { |
|
|
function createSceneState() { |
|
|
@ -250,4 +251,34 @@ describe("chase stage skeleton", () => { |
|
|
scene.update(0, "chase", {} as any); |
|
|
scene.update(0, "chase", {} as any); |
|
|
expect((scene as any).seedInputElement).toBeUndefined(); |
|
|
expect((scene as any).seedInputElement).toBeUndefined(); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it("detaches seed input immediately on stage change callback", () => { |
|
|
|
|
|
const fakeDocument = createFakeDocument(); |
|
|
|
|
|
const getState = vi.fn().mockReturnValue(createSceneState()); |
|
|
|
|
|
let stageChangeHandler: ((current: { name: string }) => void) | undefined; |
|
|
|
|
|
let unsubscribed = false; |
|
|
|
|
|
const onStageChangeSpy = vi |
|
|
|
|
|
.spyOn(sceneManager, "onStageChange") |
|
|
|
|
|
.mockImplementation((cb: any) => { |
|
|
|
|
|
stageChangeHandler = cb; |
|
|
|
|
|
return () => { |
|
|
|
|
|
unsubscribed = true; |
|
|
|
|
|
}; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const scene = new ChaseScene({ |
|
|
|
|
|
documentRef: fakeDocument as any, |
|
|
|
|
|
model: { getState, moveThief: vi.fn(), newRound: vi.fn() } as any, |
|
|
|
|
|
}); |
|
|
|
|
|
void (scene as any).onSceneLayout(); |
|
|
|
|
|
(scene as any).onSceneEnter(); |
|
|
|
|
|
expect((scene as any).seedInputElement).toBeTruthy(); |
|
|
|
|
|
|
|
|
|
|
|
stageChangeHandler?.({ name: "init" }); |
|
|
|
|
|
expect((scene as any).seedInputElement).toBeUndefined(); |
|
|
|
|
|
|
|
|
|
|
|
(scene as any).onSceneExit(); |
|
|
|
|
|
expect(unsubscribed).toBe(true); |
|
|
|
|
|
onStageChangeSpy.mockRestore(); |
|
|
|
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|