Files
writer-work-flow/apps/web/lib/workbench/directive.test.ts
Yaojia Wang cc0aabdd9a feat(ux): T4-b 前端 — 本章指令框 + 风格快捷预设传入 draft 生成
新 lib/workbench/directive.ts (STYLE_PRESETS + composeDirective 纯函数+测);useDraftStream.start 加 directive 参数(非空时 POST JSON body);Workbench 加「本章指令」textarea + 风格预设 chips,写本章时 composeDirective 传入。TDD: directive 测。前端门禁绿。docs(progress): 记 Tier4 完成。
2026-06-20 18:27:47 +02:00

27 lines
1005 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { describe, expect, it } from "vitest";
import { composeDirective, STYLE_PRESETS } from "./directive";
describe("composeDirective", () => {
it("returns empty string when nothing selected", () => {
expect(composeDirective("", [])).toBe("");
expect(composeDirective(" ", [])).toBe("");
});
it("uses free text only when no presets", () => {
expect(composeDirective("多写战斗", [])).toBe("多写战斗");
});
it("combines presets (in canonical order) then free text", () => {
const result = composeDirective("多写战斗", ["fast-pace", "less-ai"]);
const lessAi = STYLE_PRESETS.find((p) => p.id === "less-ai")!.text;
const fastPace = STYLE_PRESETS.find((p) => p.id === "fast-pace")!.text;
expect(result).toBe(`${lessAi}${fastPace};多写战斗`);
});
it("ignores unknown preset ids", () => {
const lessAi = STYLE_PRESETS.find((p) => p.id === "less-ai")!.text;
expect(composeDirective("", ["nope", "less-ai"])).toBe(lessAi);
});
});