import { describe, expect, it } from "vitest"; import { detectMaterialDraftStart, insertMaterialDraftToken, nextMaterialDraftToken, normalizeMaterialDraftToken } from "@/lib/prompt/material-draft"; describe("material draft input", () => { it("starts a temporary draft only for a single typed @", () => { expect(detectMaterialDraftStart("以商品为主体", "以@商品为主体", 2)).toEqual({ text: "以商品为主体", index: 1 }); expect(detectMaterialDraftStart("以商品为主体", "以@@商品为主体", 3)).toBeNull(); expect(detectMaterialDraftStart("以商品为主体", "以@图片1商品为主体", 5)).toBeNull(); }); it("normalizes confirmed material placeholder names", () => { const prompt = "参考 @图片1 和 @视频1"; expect(normalizeMaterialDraftToken("图片", prompt)).toBe("@图片2"); expect(normalizeMaterialDraftToken("图3", prompt)).toBe("@图片3"); expect(normalizeMaterialDraftToken("视频", prompt)).toBe("@视频2"); expect(normalizeMaterialDraftToken("音频1", prompt)).toBe("@音频1"); expect(normalizeMaterialDraftToken("图片这种普通文字", prompt)).toBeNull(); }); it("inserts confirmed tokens with text boundaries", () => { expect(insertMaterialDraftToken("以主体生成", 1, "@图片1")).toEqual({ text: "以 @图片1 主体生成", cursor: 7 }); expect(insertMaterialDraftToken("以主体生成", 5, "@视频1")).toEqual({ text: "以主体生成 @视频1 ", cursor: 11 }); expect(nextMaterialDraftToken("image", "@图片1 @图片2")).toBe("@图片3"); }); });