import { describe, expect, it } from "vitest";
import { compose } from "./compose.js";
import type { Effect } from "./library.js";
const TEMPLATE = `
`;
const counter: Effect = {
id: "counter",
name: "Counter",
folder: "",
meta: { duration_s: { min: 1, max: 4 } },
skill: "",
template: TEMPLATE,
slots: ["main"],
needs: [],
min: 1,
usual: 2,
max: 4,
};
const composed = (params: Record) =>
compose(
counter,
{ path: "clip.mp4", seconds: 2, width: 1080, height: 1920, sourceIn: 0 },
{ unit: "+ keyframes" },
params,
).html;
const styleOf = (page: string) => page.slice(page.indexOf(""));
describe("an effect's values in its own page", () => {
it("writes each custom property it is given into the template's styles, wherever it is declared", () => {
const page = composed({
"--accent": "#ffd23f",
"--glow": "rgba(255,210,63,0.9)",
"--font-display": "Inter",
});
const style = styleOf(page);
expect(style).toContain("--accent:#ffd23f;");
expect(style).toContain("--glow:rgba(255,210,63,0.9) }");
expect(style).toContain("--font-display:Inter;");
expect(style).toContain("--accent-2:#00ff00;");
expect(page).toContain('const kept = "--accent:#1fff3a";');
expect(style).toContain("/* --accent: the brand colour */ a{b:c}");
});
it("takes a quoted value whole, and leaves a comment as it was", () => {
const style = styleOf(composed({ "--bg": "none", "--f": "Inter", "--accent": "red" }));
expect(style).toContain("--bg:none;");
expect(style).toContain("--f:Inter;");
expect(style).toContain("--accent:red;");
expect(style).toContain("/* --accent: the brand colour */ a{b:c}");
expect(style).toContain("#counter{ color:var(--accent);");
});
it.each(["red; } body { display:none", "rgba(1,2", '"Inter', "", "red /* note"])(
"leaves a declaration as it was for a value that would not close: %j",
(value) => {
const style = styleOf(composed({ "--accent": value }));
expect(style).toContain("--accent:#1fff3a;");
expect(style).toContain("#counter{ color:var(--accent);");
},
);
it("empties a text slot given null, and fills one given text", () => {
const page = composed({ currency: null });
expect(page).toContain('');
expect(page).toContain('+ keyframes');
});
it("empties only what the caller gave as null, not a value compose turns off itself", () => {
expect(composed({ words: ["a"] })).toContain('P');
});
});