diff --git a/tests/int/npc-dialogue-interpolate.int.spec.ts b/tests/int/npc-dialogue-interpolate.int.spec.ts index ff5942a7..7406d8ee 100644 --- a/tests/int/npc-dialogue-interpolate.int.spec.ts +++ b/tests/int/npc-dialogue-interpolate.int.spec.ts @@ -1,9 +1,12 @@ import { getPayload, Payload } from "payload"; import config from "@/payload.config"; +import { createElement } from "react"; +import { renderToStaticMarkup } from "react-dom/server"; import { afterAll, beforeAll, describe, expect, it } from "vitest"; import type { DialogueNode } from "@/lib/npc-dialogue/dialogue"; +import { DialogueText } from "@/lib/npc-dialogue/DialogueText"; import { collectNodeTokens, extractFlagTokens, @@ -159,3 +162,59 @@ describe("text flags (player-flags collection)", () => { expect(formatFlagValue(updated)).toBe("{amber}REDACTED{/}"); }); }); + +describe("inline images in dialogue markup", () => { + const render = (text: string) => + renderToStaticMarkup(createElement(DialogueText, { text })); + + it("renders site-relative and absolute-http images as inline icons", () => { + const html = render("Pay 5 ![coin](/api/media/file/coin.png) now"); + expect(html).toContain('coin { + // Protocol-relative and scheme-less/bad URLs never become . + expect(render("![x](//evil.com/a.png)")).not.toContain(" { + const html = render("**b** {green}g{/} ![c](/c.png) `code`"); + expect(html).toContain(" { + it("collects tokens from tooltips and resolves them index-aligned", () => { + const node: DialogueNode = { + id: "n", + type: "choice", + position: { x: 0, y: 0 }, + data: { + choices: [ + { label: "A", target: "t", tooltip: "Cost {{cost}} ![coin](/i.png)" }, + { label: "B", target: "u" }, + ], + }, + }; + expect(collectNodeTokens(node)).toContain("cost"); + const resolved = resolveNodeTexts(node, { cost: "5" }); + expect(resolved.tooltips?.[0]).toBe("Cost 5 ![coin](/i.png)"); + expect(resolved.tooltips?.[1]).toBe(""); + }); + + it("omits the tooltips array when no choice has a tooltip", () => { + const node: DialogueNode = { + id: "n", + type: "choice", + position: { x: 0, y: 0 }, + data: { choices: [{ label: "A", target: "t" }] }, + }; + expect(resolveNodeTexts(node, {}).tooltips).toBeUndefined(); + }); +});