import { describe, test, expect } from "vitest" import path from "node:path" import { fileURLToPath } from "node:url" import { loadBrand } from "../src/config" import { buildSvg } from "../src/render" import { loadFixture } from "./helpers/fixtures" const __dirname = path.dirname(fileURLToPath(import.meta.url)) const DRAW_IMAGE_DIR = path.resolve(__dirname, "..") const BADGE_RECT = 'x="780" y="780" width="180" height="180"' const SUBTITLE_Y = 'y="930"' describe("unit — optional badge background", () => { test("empty badge slot renders no bg/border rect", () => { const brand = loadBrand(DRAW_IMAGE_DIR) const templateSvg = loadFixture("cover") const svg = buildSvg(templateSvg, brand, { template: "cover", title: "No Badge" }, DRAW_IMAGE_DIR) expect(svg).not.toContain(BADGE_RECT) expect(svg).not.toContain('x="780" y="780"') }) test("filled badge slot renders bg/border rect", () => { const brand = loadBrand(DRAW_IMAGE_DIR) const templateSvg = loadFixture("cover") const svg = buildSvg(templateSvg, brand, { template: "cover", title: "With Badge", slots: { badge: "mic" }, }, DRAW_IMAGE_DIR) expect(svg).toContain(BADGE_RECT) expect(svg).toContain('fill="#121212"') expect(svg).toContain('stroke="#ccff00"') }) }) describe("unit — optional subtitle", () => { test("empty subtitle removes the subtitle text line", () => { const brand = loadBrand(DRAW_IMAGE_DIR) const templateSvg = loadFixture("cover") const svg = buildSvg(templateSvg, brand, { template: "cover", title: "No Sub" }, DRAW_IMAGE_DIR) expect(svg).not.toContain(SUBTITLE_Y) expect(svg).not.toContain("{{subtitle}}") }) test("set subtitle keeps the subtitle text line", () => { const brand = loadBrand(DRAW_IMAGE_DIR) const templateSvg = loadFixture("cover") const svg = buildSvg(templateSvg, brand, { template: "cover", title: "Main", subtitle: "My Sub", }, DRAW_IMAGE_DIR) expect(svg).toContain(SUBTITLE_Y) expect(svg).toContain("My Sub") }) })