| 12345678910111213141516171819202122 |
- import { describe, expect, it } from "vitest";
- import type { Entity } from "@nengine/core";
- import { labelPosition, LABEL_ABOVE_OFFSET } from "../src/labels.js";
- const entity = (overrides: Partial<Entity> = {}): Entity => ({ id: "npc:mayor", type: "npc", x: 6, y: 3, ...overrides });
- describe("labelPosition (pure entity → px label anchor)", () => {
- it("anchors at the tile's horizontal center, offset above its top edge", () => {
- const pos = labelPosition(entity(), 32);
- expect(pos).toEqual({ x: 6 * 32 + 16, y: 3 * 32 - LABEL_ABOVE_OFFSET });
- });
- it("follows the tile size", () => {
- const pos = labelPosition(entity(), 48);
- expect(pos).toEqual({ x: 6 * 48 + 24, y: 3 * 48 - LABEL_ABOVE_OFFSET });
- });
- it("falls back to 0,0 for an entity without coordinates", () => {
- const pos = labelPosition(entity({ x: undefined, y: undefined }), 32);
- expect(pos).toEqual({ x: 16, y: -LABEL_ABOVE_OFFSET });
- });
- });
|