// @vitest-environment node import { describe, expect, it } from "vitest"; import { MENU_HEIGHT, MENU_MARGIN, MENU_WIDTH, clampMenuPosition, } from "@/lib/npc-dialogue/markupMenu"; const viewport = { width: 1500, height: 1000 }; describe("markup menu placement", () => { it("sits exactly at the pointer away from the edges", () => { expect(clampMenuPosition(750, 308, viewport)).toEqual({ left: 750, top: 308 }); }); it("pulls back from the right and bottom edges so every item stays reachable", () => { const point = clampMenuPosition(1499, 999, viewport); expect(point.left).toBe(viewport.width - MENU_WIDTH - MENU_MARGIN); expect(point.top).toBe(viewport.height - MENU_HEIGHT - MENU_MARGIN); expect(point.left + MENU_WIDTH).toBeLessThanOrEqual(viewport.width); expect(point.top + MENU_HEIGHT).toBeLessThanOrEqual(viewport.height); }); it("keeps the margin when the viewport is smaller than the menu", () => { const small = { width: 120, height: 100 }; expect(clampMenuPosition(119, 99, small)).toEqual({ left: MENU_MARGIN, top: MENU_MARGIN, }); }); it("never returns a negative offset for a pointer outside the window", () => { const point = clampMenuPosition(-40, -40, viewport); expect(point.left).toBeGreaterThanOrEqual(MENU_MARGIN); expect(point.top).toBeGreaterThanOrEqual(MENU_MARGIN); }); });