opencode-config/.opencode/draw-image/tests/render.optional.test.ts
Sergey 0d16b028fa
fix(draw-image): optional badge/subtitle + self-healing docker entrypoint (#144)
* fix(draw-image): conditional slot bg + optional subtitle in buildSvg

* test(draw-image): optional badge/subtitle unit+integration+e2e

* feat(docker): self-healing entrypoint shim + .dockerignore

* test(draw-image): pytest assert --subtitle omitted when absent

* docs(handoff): optional badge/subtitle + docker entrypoint handoff+ADR

* docs(handoff): set PR number 144

* docs(project-map): fix PR refs 143 to 144

---------

Co-authored-by: opencode-agent <agent@opencode.local>
2026-07-30 01:23:25 +03:00

56 lines
2.1 KiB
TypeScript

import { describe, test, expect } from "vitest"
import path from "node:path"
import { fileURLToPath } from "node:url"
import { loadBrand } from "../src/config"
import { loadTemplate, buildSvg } from "../src/render"
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 = loadTemplate(DRAW_IMAGE_DIR, "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 = loadTemplate(DRAW_IMAGE_DIR, "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 = loadTemplate(DRAW_IMAGE_DIR, "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 = loadTemplate(DRAW_IMAGE_DIR, "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")
})
})