84 lines
3.2 KiB
TypeScript
84 lines
3.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
buildDetailModulePrompt,
|
|
buildEcommerceImagePrompt,
|
|
buildSetSubPrompt,
|
|
setCountLabels,
|
|
type EcommercePromptDetailModule,
|
|
} from "./promptBuilder";
|
|
|
|
const detailModules: EcommercePromptDetailModule[] = [
|
|
{ id: "hero", title: "首页焦点图", desc: "集中呈现核心利益点" },
|
|
{ id: "usage", title: "使用情境图", desc: "还原实际使用画面" },
|
|
{ id: "spec", title: "参数信息表", desc: "整理商品关键数据" },
|
|
];
|
|
|
|
describe("buildDetailModulePrompt", () => {
|
|
it("uses the complete-detail prompt when no modules are selected", () => {
|
|
expect(buildDetailModulePrompt([], detailModules)).toContain("complete A+ detail layout");
|
|
});
|
|
|
|
it("includes only selected modules", () => {
|
|
const prompt = buildDetailModulePrompt(["hero", "spec"], detailModules);
|
|
expect(prompt).toContain("首页焦点图: 集中呈现核心利益点");
|
|
expect(prompt).toContain("参数信息表: 整理商品关键数据");
|
|
expect(prompt).not.toContain("使用情境图");
|
|
});
|
|
|
|
it("returns an empty prompt for unknown selected ids", () => {
|
|
expect(buildDetailModulePrompt(["missing"], detailModules)).toBe("");
|
|
});
|
|
});
|
|
|
|
describe("buildSetSubPrompt", () => {
|
|
it("builds white-background prompts with strict background guidance", () => {
|
|
const prompt = buildSetSubPrompt("white", 0, 1, "淘宝/天猫", "1:1", "中文", "中国");
|
|
expect(prompt).toContain(setCountLabels.white.label);
|
|
expect(prompt).toContain("clean white-background product image");
|
|
expect(prompt).toContain("Platform: 淘宝/天猫. Aspect ratio: 1:1. Language/copy: 中文. Market: 中国.");
|
|
});
|
|
|
|
it("adds variant guidance when generating multiple images", () => {
|
|
expect(buildSetSubPrompt("scene", 1, 3, "Amazon", "3:4", "英文", "美国")).toContain("variant 2 of 3");
|
|
});
|
|
});
|
|
|
|
describe("buildEcommerceImagePrompt", () => {
|
|
it("builds detail prompts with selected A+ modules", () => {
|
|
const prompt = buildEcommerceImagePrompt(
|
|
"detail",
|
|
"突出轻量化",
|
|
"京东",
|
|
"3:4",
|
|
"中文",
|
|
"中国",
|
|
{ detailModules: ["usage"] },
|
|
detailModules,
|
|
);
|
|
expect(prompt).toContain("professional A+ detail page");
|
|
expect(prompt).toContain("使用情境图: 还原实际使用画面");
|
|
expect(prompt).toContain("Additional user requirements: 突出轻量化");
|
|
});
|
|
|
|
it("builds model prompts with model attributes and scenes", () => {
|
|
const prompt = buildEcommerceImagePrompt(
|
|
"model",
|
|
"",
|
|
"Shopee",
|
|
"3:4",
|
|
"英文",
|
|
"美国",
|
|
{ gender: "女", age: "青年", ethnicity: "亚洲人", body: "标准", appearance: "短发", scenes: ["都市街头"], smartScene: true },
|
|
);
|
|
expect(prompt).toContain("Model gender: 女.");
|
|
expect(prompt).toContain("Background scenes: 都市街头.");
|
|
expect(prompt).toContain("Use smart scene matching");
|
|
});
|
|
|
|
it("builds hot-replication prompts", () => {
|
|
const prompt = buildEcommerceImagePrompt("hot", "", "TikTok Shop", "9:16", "英文", "美国");
|
|
expect(prompt).toContain("closely replicates the style");
|
|
expect(prompt).toContain("TikTok Shop marketplace standards");
|
|
});
|
|
});
|