opencode-config/.opencode/draw-image/tests/render.optional.test.ts
Sergey 66f0afa58b
refactor(draw-image): decouple tests from production cover.svg (#197)
* refactor(draw-image): add tests/fixtures/cover.svg and loadFixture helper

* feat(draw-image): add --template-dir flag to cli for test isolation

* refactor(draw-image): switch tests from templates/cover to fixtures

* chore(draw-image): simplify production cover.svg now decoupled from tests

* docs(handoff): add handoff + ADR for issue #196

* docs(handoff): set PR number

* docs(project-map): update after structural changes

---------

Co-authored-by: opencode-agent <agent@opencode.local>
2026-08-01 01:22:15 +03:00

57 lines
2 KiB
TypeScript

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")
})
})