import { describe, expect, test } from "vitest";
import { parseForm } from "@/shared/forms/validation";
import { prettyDisplayIDGrantSchema } from "./schema";

describe("pretty display ID grant schema", () => {
    test("accepts arbitrary Unicode display content", () => {
        // 管理端只保留展示文本的非空和长度约束，避免 Unicode 字体、符号和 emoji 被客户端正则错误拦截。
        const payload = parseForm(prettyDisplayIDGrantSchema, {
            displayUserId: "  𝕸⃝é中⚡️™  ",
            durationDays: "1",
            reason: "Unicode 靓号",
            targetUserId: "163001",
        });

        expect(payload.displayUserId).toBe("𝕸⃝é中⚡️™");
    });

    test("counts supplementary Unicode characters as one character", () => {
        const payload = parseForm(prettyDisplayIDGrantSchema, {
            displayUserId: "😀".repeat(64),
            durationDays: "",
            reason: "",
            targetUserId: "163001",
        });

        expect(Array.from(payload.displayUserId)).toHaveLength(64);
    });
});
