Files
youtube-generator/tests/engine/title-builder.test.ts
T
poli0981andClaude Opus 4.6 a763f7c78a feat: Phase 1 MVP scaffold — core engine, i18n, UI, CI/CD
Complete Phase 1 implementation of YTDescGen:
- Project setup: Vite 5 + React 18 + TypeScript strict + Tailwind CSS dark theme
- Config layer: 7 video types, 10 genres, 7 platforms, rig/social fields
- i18n: EN/VI/JA with separate UI and template namespaces + validation script
- Core engine: title-builder, description-builder, tag-generator (pure TS, zero React)
- 42 unit tests covering all engine functions
- Zustand stores: editor + settings with localStorage persistence
- UI: 6 primitives, 11 editor components, 4 output components, 3 layout components
- Pages: Editor (form + quick preview) and Output (title/desc/tags + copy)
- CI/CD: GitHub Actions for lint/typecheck/test/build + GitHub Pages deploy

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 21:46:59 +07:00

119 lines
3.8 KiB
TypeScript

import { describe, it, expect } from "vitest";
import { buildTitle, checkTitleWarning } from "@engine/title-builder";
import { createMockT } from "../helpers/mock-t";
import type { GeneratorInput } from "@engine/types";
function makeInput(overrides: Partial<GeneratorInput> = {}): GeneratorInput {
return {
videoType: "full",
language: "en",
genre: "action",
gameName: "Elden Ring",
channelName: "TestChannel",
platform: "steam",
spoilerWarning: false,
matureWarning: false,
storeLinks: {},
social: {},
rig: {},
...overrides,
};
}
describe("buildTitle", () => {
it("generates full gameplay title in English", () => {
const t = createMockT("en");
const result = buildTitle(makeInput(), t);
expect(result).toBe("Elden Ring — Gameplay No Commentary");
});
it("generates part title with number", () => {
const t = createMockT("en");
const result = buildTitle(makeInput({ videoType: "part", partNumber: "5" }), t);
expect(result).toBe("Elden Ring — Part 5 — Gameplay No Commentary");
});
it("generates boss title with boss name", () => {
const t = createMockT("en");
const result = buildTitle(
makeInput({ videoType: "boss", bossName: "Margit" }),
t,
);
expect(result).toBe("Elden Ring — Margit Boss Fight — Gameplay No Commentary");
});
it("generates boss no hit title", () => {
const t = createMockT("en");
const result = buildTitle(
makeInput({ videoType: "boss_nohit", bossName: "Margit" }),
t,
);
expect(result).toBe("Elden Ring — Margit Boss No Hit — Gameplay No Commentary");
});
it("generates ending title", () => {
const t = createMockT("en");
const result = buildTitle(makeInput({ videoType: "ending" }), t);
expect(result).toBe("Elden Ring — Ending — Gameplay No Commentary");
});
it("generates speedrun title", () => {
const t = createMockT("en");
const result = buildTitle(makeInput({ videoType: "speedrun" }), t);
expect(result).toBe("Elden Ring — Speedrun — Gameplay No Commentary");
});
it("generates 100% title", () => {
const t = createMockT("en");
const result = buildTitle(makeInput({ videoType: "100percent" }), t);
expect(result).toBe("Elden Ring — 100% Completion — Gameplay No Commentary");
});
it("generates boss title in Japanese", () => {
const t = createMockT("ja");
const input = makeInput({
videoType: "boss",
bossName: "マルギット",
gameName: "エルデンリング",
language: "ja",
});
const result = buildTitle(input, t);
expect(result).toBe("エルデンリング — マルギット ボス戦 — Gameplay No Commentary");
});
it("generates part title in Vietnamese", () => {
const t = createMockT("vi");
const result = buildTitle(
makeInput({ videoType: "part", partNumber: "3", language: "vi" }),
t,
);
expect(result).toBe("Elden Ring — Phần 3 — Gameplay No Commentary");
});
it("uses localized game name when available", () => {
const t = createMockT("ja");
const input = makeInput({
language: "ja",
gameName: "Elden Ring",
gameNameLocalized: { ja: "エルデンリング" },
});
const result = buildTitle(input, t);
expect(result).toBe("エルデンリング — Gameplay No Commentary");
});
});
describe("checkTitleWarning", () => {
it("returns null for title under limit", () => {
expect(checkTitleWarning("Short title")).toBeNull();
});
it("returns warning for title exceeding 100 chars", () => {
const longTitle = "A".repeat(101);
const warning = checkTitleWarning(longTitle);
expect(warning).not.toBeNull();
expect(warning!.field).toBe("title");
expect(warning!.current).toBe(101);
expect(warning!.limit).toBe(100);
});
});