election-game/backend/packages/content/test/custom-avatar.test.ts

22 lines
1.3 KiB
TypeScript
Raw Permalink Normal View History

import { describe, expect, it } from "vitest";
import { CUSTOM_ID, SCENARIOS, withCustomCandidate } from "../src/index.ts";
const avatar = { skin: "#eebd98", hair: "short", hairColor: "#1f1b18", outfit: "suit", suit: "#24324a", shirt: "#f7f5f0", tie: "#b3262d", glasses: false, beard: false, bg: "#dfe8f0" };
const custom = (a: Record<string, unknown>) => ({ name: "測試人", party: null, background: "律師" as const, stats: { fame: 5, eloquence: 5, strategy: 5, wealth: 5, network: 5 }, avatar: a as typeof avatar, replace: null });
describe("自創角色的頭像(docs/24)", () => {
const scenario = SCENARIOS[0]!;
it("舊存檔的頭像原封不動放進劇本", () => {
const s = withCustomCandidate(scenario, custom(avatar), new Set());
expect(s.candidates.find((c) => c.id === CUSTOM_ID)?.avatar).toEqual(avatar);
});
it("看不懂的部件代號換成預設、不擋開局", () => {
const s = withCustomCandidate(scenario, custom({ ...avatar, hair: "hair-from-2030", wear: { hat: "hat-campaign-cap", pet: "pet-dragon" }, style: "oil-paint" }), new Set());
const a = s.candidates.find((c) => c.id === CUSTOM_ID)?.avatar;
expect(a?.hair).toBe("short");
expect(a?.wear).toEqual({ hat: "hat-campaign-cap" });
expect(a?.style).toBeUndefined();
});
});