Skip to content

Open-source AI podcast clipper. Generate vertical clips with face tracking and burned-in captions. CLI, MCP server, web app.

4.6 KB
Raw Blame
import { describe, expect, it } from "vitest";
import { ENTRANCES, FONT_IDS, MOTIONS, PACKS, ROLES, resolveTheme } from "./theme";
import type { PackId, ThemeInput } from "./theme";

const isPackId = (id: string): id is PackId => id in PACKS;
const isMotionId = (id: string): id is keyof typeof MOTIONS => id in MOTIONS;
const packIds = Object.keys(PACKS).filter(isPackId);
const motionIds = Object.keys(MOTIONS).filter(isMotionId);

describe("resolveTheme", () => {
  it("returns null without a style", () => {
    expect(resolveTheme(null)).toBeNull();
  });

  it("starts from the pack and its own motion", () => {
    const theme = resolveTheme({ pack: "editorial" });
    expect(theme?.color.accent).toBe(PACKS.editorial.color.accent);
    expect(theme?.motion).toEqual(MOTIONS.highlighter);
  });

  it("swaps the motion without touching the look", () => {
    const theme = resolveTheme({ pack: "collage", motion: "kinetic" });
    expect(theme?.motion.camera).toBe("punch");
    expect(theme?.edge.kind).toBe("torn");
  });

  it("applies overrides on top of the motion preset", () => {
    const theme = resolveTheme({ pack: "clean", motion: "calm", overrides: { motion: { frames: 20 } } });
    expect(theme?.motion.frames).toBe(20);
    expect(theme?.motion.roles.title).toBe("fade");
  });

  it("refuses gradients and image urls in overrides", () => {
    const theme = resolveTheme({
      pack: "clean",
      overrides: { color: { ground: "linear-gradient(red, blue)", accent: "url(x.png)", ink: "#FFFFFF" } },
    });

    expect(theme?.color.ground).toBe(PACKS.clean.color.ground);
    expect(theme?.color.accent).toBe(PACKS.clean.color.accent);
    expect(theme?.color.ink).toBe("#FFFFFF");
  });

  it("carries no gradient anywhere in the packs or presets", () => {
    const text = JSON.stringify({ PACKS, MOTIONS });
    expect(text).not.toMatch(/gradient/i);
  });
});

describe("caption choice", () => {
  it("keeps the pack's caption skin by default", () => {
    expect(resolveTheme({ pack: "collage" })?.captions).toBe("pack");
  });

  it("takes any caption preset on its own", () => {
    expect(resolveTheme({ pack: "collage", motion: "kinetic", overrides: { captions: "hormozi" } })?.captions).toBe("hormozi");
  });

  it("closes every motion preset with a fade rather than a cut", () => {
    for (const motion of Object.values(MOTIONS)) expect(motion.exit).toBe("fade");
  });
});

describe("motion presets", () => {
  it("name an entrance for every role and leave by fading", () => {
    for (const [id, motion] of Object.entries(MOTIONS)) {
      expect(Object.keys(motion.roles).sort(), id).toEqual([...ROLES].sort());

      for (const entrance of Object.values(motion.roles)) expect(ENTRANCES, id).toContain(entrance);
      expect(motion.exit, id).toBe("fade");
    }
  });

  it("resolve on every pack", () => {
    for (const pack of packIds) {
      for (const motion of motionIds) {
        expect(resolveTheme({ pack, motion })?.motion).toEqual(MOTIONS[motion]);
      }
    }
  });
});

describe("fonts picked to match a reference", () => {
  it("swap the display and label faces and leave the rest of the pack", () => {
    const theme = resolveTheme({ pack: "clean", fonts: { display: "condensed", label: "mono" } });
    expect(theme?.type.display.family).toContain("Barlow Condensed");
    expect(theme?.type.label.family).toContain("Courier Prime");
    expect(theme?.color).toEqual(PACKS.clean.color);
  });

  it("keep the pack's faces when none are picked", () => {
    expect(resolveTheme({ pack: "editorial" })?.type).toEqual(PACKS.editorial.type);
  });

  it("offer every font on every pack", () => {
    for (const font of FONT_IDS) {
      expect(resolveTheme({ pack: "riso", fonts: { display: font } })?.type.display.family).toBeTruthy();
    }
  });
});

describe("card placement", () => {
  it("draws cards as full pages unless a style asks otherwise", () => {
    for (const pack of packIds) {
      expect(resolveTheme({ pack })?.placement).toBe("page");
    }
  });

  it("sets cards over the video when the style asks", () => {
    expect(resolveTheme({ pack: "swiss", placement: "overlay" })?.placement).toBe("overlay");
  });

  it("takes a placement given through overrides", () => {
    expect(resolveTheme({ pack: "swiss", overrides: { placement: "overlay" } })?.placement).toBe("overlay");
  });

  it("ignores a placement the renderer does not know", () => {
    // A template arrives as JSON, so an unknown placement is a value the types cannot rule out.
    const input: ThemeInput = JSON.parse('{ "pack": "poster", "placement": "corner" }');
    const theme = resolveTheme(input);
    expect(theme?.placement).toBe("page");
  });
});