import assert from "node:assert/strict"; import { describe, it } from "node:test"; import { captionChunks, countUp, hudClock, hudValueTone } from "../src/overlays"; import { SAMPLE } from "../src/sample"; import { frameCount, validateSpec } from "../src/spec"; describe("spec do Cartoon", () => { it("o exemplo é válido", () => assert.deepEqual(validateSpec(SAMPLE), [])); it("recusa versão, cena, ícone e tamanhos inválidos", () => { const bad = { ...SAMPLE, schemaVersion: 2, width: 1081, scene: { kind: "lua" }, props: [{ icon: "foguete", x: 0.5, y: 0.5 }] }; const errors = validateSpec(bad).join(" | "); assert.match(errors, /schemaVersion/); assert.match(errors, /width\/height/); assert.match(errors, /scene.kind/); assert.match(errors, /foguete/); }); it("card precisa de título; palavra com fim antes do início é recusada", () => { assert.match(validateSpec({ ...SAMPLE, scene: { kind: "card" } }).join(), /card.title/); assert.match(validateSpec({ ...SAMPLE, words: [{ text: "oi", startS: 2, endS: 1 }] }).join(), /words\[0\]/); }); it("quadros arredondam para cima (o vídeo nunca fica mais curto que o áudio)", () => { assert.equal(frameCount({ durationS: 2.01, fps: 30 }), 61); }); it("legenda em blocos de até 3 palavras, quebrando depois de pontuação", () => { const w = (text: string) => ({ text, startS: 0, endS: 0 }); const chunks = captionChunks(["Num", "apagão,", "a", "casa", "acesa", "chama", "atenção."].map(w)).map((c) => c.map((x) => x.text).join(" ")); assert.deepEqual(chunks, ["Num apagão,", "a casa acesa", "chama atenção."]); }); }); describe("grafismo do Cartoon: cartelas, cartão de nome e HUD", () => { const ok = (texts: unknown[], extra: Record = {}) => validateSpec({ ...SAMPLE, ...extra, texts }); const base = { x: 0.5, y: 0.4, atS: 0.2 }; it("aceita os kinds novos bem formados (e o stat/lista sem título)", () => { assert.deepEqual(ok([ { kind: "namecard", text: "Seu Amaro", lines: ["Roupeiro há 38 anos", "7 meses sem salário"], ...base }, { kind: "stat", text: "No caixa", value: "R$ 0", tone: "danger", panel: true, ...base }, { kind: "stat", text: "", value: 61, ...base }, { kind: "counter", text: "Na fila", value: "297", ...base }, { kind: "checklist", text: "", size: 0.5, items: [{ text: "Funcionários", state: "checked" }, { text: "Elenco", state: "crossed" }, { text: "Registro" }], ...base }, { kind: "table", text: "", highlight: 1, items: [{ text: "Atlético", value: "31" }, { text: "Vila Nova", value: "4" }], ...base }, { kind: "progress", text: "Talento", value: 97, ...base }, { kind: "progress", text: "Talento", value: "97%", ...base }, { kind: "grid", text: "Com contrato", value: 4, total: 18, ...base }, ]), []); }); it("recusa kind desconhecido, lista vazia, estado, destaque, porcentagem e grade inválidos", () => { const errors = ok([ { kind: "slide", text: "x", ...base }, { kind: "checklist", text: "", items: [], ...base }, { kind: "checklist", text: "", items: [{ text: "a", state: "talvez" }], ...base }, { kind: "table", text: "", items: [{ text: "a", value: "1" }], highlight: 3, ...base }, { kind: "progress", text: "Talento", value: 140, ...base }, { kind: "grid", text: "Com contrato", value: 20, total: 18, ...base }, { kind: "stat", text: "No caixa", ...base }, { kind: "namecard", text: "", ...base }, { kind: "grid", text: "g", value: 1, total: 4, size: 9, ...base }, ]).join(" | "); for (const re of [/texts\[0\]: kind/, /texts\[1\]: items/, /texts\[2\]\.items\[0\]: state/, /texts\[3\]: highlight/, /texts\[4\]: progress/, /texts\[5\]: grid/, /texts\[6\]: stat precisa de value/, /texts\[7\]: texto vazio/, /texts\[8\]: size/]) assert.match(errors, re); }); it("HUD: campos antigos continuam valendo; novos são opcionais e conferidos", () => { assert.deepEqual(validateSpec({ ...SAMPLE, hud: { badge: "DIA 3", label: "Vila Nova" } }), []); assert.deepEqual(validateSpec({ ...SAMPLE, hud: { badge: "Dia 1", label: "x", clock: "10:06", clockMinutesPerSecond: 1, place: "Vila Nova (MG)", value: "R$ 0,00", valueLabel: "Caixa", valueTone: "danger", note: "Estreia em 30 dias" } }), []); assert.match(validateSpec({ ...SAMPLE, hud: { badge: "Dia 1", label: "x", valueTone: "roxo" } }).join(), /hud.valueTone/); assert.match(validateSpec({ ...SAMPLE, hud: { badge: 3, label: "x" } }).join(), /hud: badge/); }); it("número contando, hora andando e cor do valor do HUD são funções puras", () => { assert.equal(countUp("R$ 134.273", 0.5), "R$ 67.137"); assert.equal(countUp("R$ 134.273", 1), "R$ 134.273"); assert.equal(countUp("-R$ 47.312.904", 0), "-R$ 0"); assert.equal(countUp("R$ 0", 0.3), "R$ 0"); assert.equal(countUp("Vila Nova", 0.3), "Vila Nova"); assert.equal(hudClock("10:06", 2.5, 2), "10:11"); assert.equal(hudClock("23:59", 1, 2), "00:01"); assert.equal(hudClock("10:06", 9), "10:06"); assert.equal(hudValueTone("R$ 0,00"), "danger"); assert.equal(hudValueTone("-12"), "danger"); assert.equal(hudValueTone("R$ 800"), undefined); assert.equal(hudValueTone("R$ 800", "info"), "info"); }); });