feat(web): F1/F2/F3 前端——拆书入库为规则 / 续写式链选择 / 模板库
- gen:api 纳入 /templates、chain continue_volume、teardown rules ingest 端点 - F1:GeneratorRunner 识别拆书为单对象入库(整 preview 作一条 teardown), ingestTable(BookTeardownResult)=rules,buildIngestRequest 组装 teardown 体, 按 isSingleObjectIngest 隐藏勾选框、改文案「入库为规则」 - F2:ChainStarter 加链类型单选(draft_volume 从头写 / continue_volume 续写), chain_key 作 path 参传给 run(CHAIN_KINDS 对齐后端 SUPPORTED_CHAINS) - F3:模板库页 app/templates + 全局 nav 入口 + TemplatesManager(列/建/删,乐观更新回滚); GeneratorRunner 加 TemplateFiller「从模板填入」(body 填进 brief/text,纯前端) - vitest 覆盖 templates/ingest teardown/templateFillTarget/CHAIN_KINDS 纯逻辑
This commit is contained in:
62
apps/web/lib/templates/templates.test.ts
Normal file
62
apps/web/lib/templates/templates.test.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
buildTemplateCreateRequest,
|
||||
EMPTY_TEMPLATE_DRAFT,
|
||||
isTemplateDraftValid,
|
||||
type TemplateDraft,
|
||||
} from "./templates";
|
||||
|
||||
const draft = (over: Partial<TemplateDraft>): TemplateDraft => ({
|
||||
...EMPTY_TEMPLATE_DRAFT,
|
||||
...over,
|
||||
});
|
||||
|
||||
describe("isTemplateDraftValid", () => {
|
||||
it("returns true when title and body are both non-empty", () => {
|
||||
expect(isTemplateDraftValid(draft({ title: "标题", body: "正文" }))).toBe(
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
it("returns false when title is blank", () => {
|
||||
expect(isTemplateDraftValid(draft({ title: " ", body: "正文" }))).toBe(
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
it("returns false when body is blank", () => {
|
||||
expect(isTemplateDraftValid(draft({ title: "标题", body: "" }))).toBe(false);
|
||||
});
|
||||
|
||||
it("returns false for the empty draft", () => {
|
||||
expect(isTemplateDraftValid(EMPTY_TEMPLATE_DRAFT)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildTemplateCreateRequest", () => {
|
||||
it("trims title and body and includes optional fields", () => {
|
||||
const body = buildTemplateCreateRequest(
|
||||
draft({
|
||||
title: " 脑洞模板 ",
|
||||
body: " 写一个穿越故事 ",
|
||||
category: " 脑洞 ",
|
||||
toolKey: " idea ",
|
||||
}),
|
||||
);
|
||||
expect(body).toEqual({
|
||||
title: "脑洞模板",
|
||||
body: "写一个穿越故事",
|
||||
category: "脑洞",
|
||||
tool_key: "idea",
|
||||
});
|
||||
});
|
||||
|
||||
it("nulls out blank category and tool_key", () => {
|
||||
const body = buildTemplateCreateRequest(
|
||||
draft({ title: "t", body: "b", category: " ", toolKey: "" }),
|
||||
);
|
||||
expect(body.category).toBeNull();
|
||||
expect(body.tool_key).toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user