import { describe, expect, it } from "vitest"; import { SceneStateMachine } from "@/scene/SceneStateMachine"; describe("SceneStateMachine", () => { it("starts in idle state for every new instance", () => { const machine = new SceneStateMachine(); const anotherMachine = new SceneStateMachine(); expect(machine.getState()).toBe("idle"); expect(anotherMachine.getState()).toBe("idle"); }); it("allows legal transitions defined by the state machine", () => { const machine = new SceneStateMachine(); machine.transitionTo("loading"); expect(machine.getState()).toBe("loading"); machine.transitionTo("idle"); expect(machine.getState()).toBe("idle"); }); it("throws on illegal transitions and keeps current state", () => { const machine = new SceneStateMachine(); expect(() => machine.transitionTo("idle")).toThrowError( 'Invalid scene transition: "idle" -> "idle"' ); expect(machine.getState()).toBe("idle"); machine.transitionTo("loading"); expect(machine.getState()).toBe("loading"); expect(() => machine.transitionTo("loading")).toThrowError( 'Invalid scene transition: "loading" -> "loading"' ); expect(machine.getState()).toBe("loading"); }); });