import { act, renderHook } from "@testing-library/react"; import type * as React from "react"; import { describe, expect, it } from "vitest"; import type { ToolcraftExternalStore } from "../../state/toolcraft-external-store"; import { ToolcraftRoot } from "./toolcraft-root"; import { useToolcraftStore } from "./toolcraft-store-context"; import { runtimePublicApiSchema } from "./runtime-public-api-test-support"; import { useToolcraftViewportInteractionActive } from "./use-toolcraft-viewport-interaction-active"; describe("useToolcraftViewportInteractionActive", () => { it("follows the authoritative viewport transient overlay", () => { let store: ToolcraftExternalStore | undefined; function StoreCapture() { store = useToolcraftStore(); return null; } function Wrapper({ children }: { children: React.ReactNode }) { return ( {children} ); } const { result } = renderHook( () => useToolcraftViewportInteractionActive(), { wrapper: Wrapper }, ); expect(result.current).toBe(false); act(() => { store?.dispatchTransient({ offset: { x: 10, y: 20 }, type: "canvas.setOffset", }); }); expect(result.current).toBe(true); act(() => { store?.commitTransient("viewport"); }); expect(result.current).toBe(false); }); });