Files
youtube-generator/tests/engine/quick-entry-engine.test.ts
T
poli0981andClaude Opus 5.5 3c985a07d6 feat(editor): quick start, next part, store links pasted anywhere, more stores and platforms
Editor:
- Quick start at the top: pick the channel profile and the game preset
  (remembered per device); replacing fields that hold something else asks
  first, everything offers Undo; "Update profile / preset" appears when the
  editor drifts from the one in use.
- Next part (number + 1) and New video (same game) clear what belonged to
  the last video: boss, timestamps, endings, pinned comment, sponsor…
  Applying a preset for another game or a template does the same first.
- Start over replaces Clear Draft and keeps the channel (profile fields);
  a new draft starts in the Default Output Language (it was always "en").
- A store link pasted anywhere — the page, the Game name field, another
  store's field — lands in the right store field, sets the platform for a
  game's first link and names the game from it (Roman numerals and
  well-known possessives restored: "Final Fantasy VII", "Baldur's Gate 3").
  Steam links keep their name slug and drop tracking parameters.
- Game-name suggestions from presets and history.

Catalogs:
- Stores: EA app, Ubisoft, Battle.net, Google Play, App Store, Meta Quest.
- Social: YouTube, Threads, Kick, Reddit, Bilibili; "X (Twitter)" with the
  X mark; threads.net and youtu.be links accepted.
- Cross-posting: YouTube Shorts, X (counted the way X counts — CJK,
  Vietnamese letters with diacritics and emoji count twice), Threads (one
  topic tag), Bluesky; hashtag caps per platform.
- Banks: MBV, VCBNeo, Vikki Bank (renamed OceanBank, CBBank, DongA Bank —
  saved old names get a one-click switch), Cake by VPBank, Timo.

Output:
- An empty channel name no longer leaves "…of Hades on ." — the channel
  phrase is dropped per language (8 locales, every template tested).
- Title alternatives are real title shapes with the user's separator and
  badge case; "Use this shape" sets them (new Title order setting:
  game first / video first); over-long ones can't be copied.
- Copy All can include the tags (setting); Batch picks Part or Demo part
  and continues from the editor's part number; Ctrl/Cmd+S saves the
  output to History.
- Social editor headings and hints translated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 22:29:44 +07:00

123 lines
4.3 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { buildTitle } from "@engine/title-builder";
import { buildTitleVariants } from "@engine/title-variants";
import { buildSocialPost, xWeightedLength } from "@engine/social-post-builder";
import { copyAllText, isCopyAllBlocked } from "@engine/limits";
import { SOCIAL_PLATFORMS } from "@config/social-platforms";
import type { GeneratorInput } from "@engine/types";
import { createMockT } from "../helpers/mock-t";
function input(overrides: Partial<GeneratorInput> = {}): GeneratorInput {
return {
videoType: "part",
language: "en",
genres: ["action"],
gameName: "Hades",
channelName: "Skullmute",
platform: "steam",
partNumber: "3",
resolution: "1440p",
fps: "60",
spoilerWarning: false,
matureWarning: false,
storeLinks: {},
social: {},
rig: {},
...overrides,
};
}
describe("title order", () => {
const t = createMockT("en");
it("puts the video first when asked, with every badge position", () => {
expect(buildTitle(input(), t, { order: "typeFirst" })).toBe(
"Part 3 — Hades [2K] — Gameplay No Commentary",
);
expect(buildTitle(input(), t, { order: "typeFirst", badgePosition: "prefix" })).toBe(
"[2K] Part 3 — Hades — Gameplay No Commentary",
);
expect(buildTitle(input(), t, { order: "typeFirst", badgePosition: "suffix" })).toBe(
"Part 3 — Hades — [2K] Gameplay No Commentary",
);
});
it("treats a missing option as the default instead of undefined", () => {
expect(buildTitle(input(), t, { order: undefined, badgePosition: undefined })).toBe(
buildTitle(input(), t),
);
});
it("builds variants with the user's separator, and says which format each is", () => {
const variants = buildTitleVariants(input(), t, { separator: "pipe", showQualityBadge: true });
expect(variants.map((v) => v.format)).toEqual([
{ order: "gameFirst", badgePosition: "middle" },
{ order: "typeFirst", badgePosition: "middle" },
{ order: "gameFirst", badgePosition: "prefix" },
]);
for (const v of variants) expect(v.title).toContain(" | ");
});
});
describe("X's weighted length", () => {
it("counts Latin once and CJK, Vietnamese diacritics and emoji twice", () => {
expect(xWeightedLength("Hades")).toBe(5);
expect(xWeightedLength("日本")).toBe(4);
expect(xWeightedLength("Việt")).toBe(5); // ệ is in Latin Extended Additional
expect(xWeightedLength("🎮")).toBe(2);
expect(xWeightedLength("👩‍🚀")).toBe(2);
expect(xWeightedLength("“quotes”")).toBe(8);
});
});
describe("social posts for the new platforms", () => {
const t = createMockT("en");
const platform = (id: string) => {
const found = SOCIAL_PLATFORMS.find((p) => p.id === id);
if (!found) throw new Error(id);
return found;
};
it("caps hashtags per platform", () => {
const threads = platform("threads");
const post = buildSocialPost(input(), t, {
charLimit: threads.charLimit,
popularHashtags: threads.popularHashtags,
maxHashtags: threads.maxHashtags,
});
const tags = post.text.split(/\s+/).filter((w) => w.startsWith("#"));
expect(tags).toEqual(["#Hades"]);
});
it("fits X with its own count", () => {
const x = platform("x");
const post = buildSocialPost(input({ rig: { cpu: "AMD Ryzen 7 9800X3D" } }), t, {
charLimit: x.charLimit,
popularHashtags: x.popularHashtags,
maxHashtags: x.maxHashtags,
countMode: x.countMode,
});
expect(post.charCount).toBe(xWeightedLength(post.text));
expect(post.isOver).toBe(false);
});
});
describe("Copy All", () => {
const output = { title: "T", description: "D", tagString: "a, b" };
const over = (field: "title" | "description" | "tags") => ({
overflows: [{ field, current: 999, limit: 1 }],
});
it("adds the tags only when asked", () => {
expect(copyAllText(output, false)).toBe("T\n\nD");
expect(copyAllText(output, true)).toBe("T\n\nD\n\na, b");
expect(copyAllText({ ...output, tagString: "" }, true)).toBe("T\n\nD");
});
it("is blocked by the tags only when it includes them", () => {
expect(isCopyAllBlocked(over("tags") as never, false)).toBe(false);
expect(isCopyAllBlocked(over("tags") as never, true)).toBe(true);
expect(isCopyAllBlocked(over("title") as never, false)).toBe(true);
});
});