import { act, renderHook } from "@testing-library/react"; import { describe, expect, it } from "vitest"; import type { OrganId } from "../types"; import { useOrganInteraction } from "../useOrganInteraction"; describe("useOrganInteraction hook", () => { it("keeps hover state when deselecting a hovered organ", () => { const organId: OrganId = "head"; const { result } = renderHook(() => useOrganInteraction()); act(() => { result.current.handlers.handleMouseEnter(organId); }); expect(result.current.state.hoveredOrgan).toBe(organId); act(() => { result.current.handlers.handleClick(organId); }); expect(result.current.state.selectedOrgan).toBe(organId); expect(result.current.state.hoveredOrgan).toBe(organId); act(() => { result.current.handlers.handleClick(organId); }); expect(result.current.state.selectedOrgan).toBeNull(); expect(result.current.state.hoveredOrgan).toBe(organId); }); });