import { describe, expect, it } from "vitest"; import { DEFAULT_THREAT_METER_POSITION, clampHudPositionToViewport, normalizeHudPosition, } from "./hudLayout"; describe("movable HUD positioning", () => { it("normalizes invalid and out-of-range saved positions", () => { expect(normalizeHudPosition(null)).toBe(DEFAULT_THREAT_METER_POSITION); expect(normalizeHudPosition({ x: -4, y: 3 })).toEqual({ x: 0, y: 1 }); expect(normalizeHudPosition({ x: Number.NaN, y: 0.4 })).toEqual({ x: DEFAULT_THREAT_METER_POSITION.x, y: 0.4, }); }); it("keeps a center-anchored widget completely inside desktop and mobile viewports", () => { expect(clampHudPositionToViewport( { x: 1, y: 0 }, { width: 1_280, height: 720 }, { width: 156, height: 92 }, )).toEqual({ x: (1_280 - 84) / 1_280, y: 52 / 720, }); expect(clampHudPositionToViewport( { x: 1, y: 1 }, { width: 390, height: 844 }, { width: 156, height: 92 }, )).toEqual({ x: (390 - 84) / 390, y: (844 - 52) / 844, }); }); });