refactor(frontend): clarify toVM/PROCEED 提取到 clarify.ts 共享(WFW-9 M2)
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
PROCEED,
|
||||
foldClarifications,
|
||||
needsClarifyGate,
|
||||
toVM,
|
||||
type ClarifyAnswer,
|
||||
} from "./clarify";
|
||||
|
||||
@@ -67,6 +69,70 @@ describe("foldClarifications", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("toVM", () => {
|
||||
it("snake_case ClarifyDecision → camelCase VM,逐字段映射", () => {
|
||||
const vm = toVM({
|
||||
need_clarification: true,
|
||||
questions: [
|
||||
{
|
||||
question: "想更冷峻还是更抒情?",
|
||||
options: [
|
||||
{ label: "冷峻", value: "改得更冷峻克制" },
|
||||
{ label: "抒情", value: "改得更抒情" },
|
||||
],
|
||||
allow_free_text: true,
|
||||
},
|
||||
],
|
||||
verification: "我这样理解对吗",
|
||||
});
|
||||
|
||||
expect(vm).toEqual({
|
||||
needClarification: true,
|
||||
questions: [
|
||||
{
|
||||
question: "想更冷峻还是更抒情?",
|
||||
options: [
|
||||
{ label: "冷峻", value: "改得更冷峻克制" },
|
||||
{ label: "抒情", value: "改得更抒情" },
|
||||
],
|
||||
allowFreeText: true,
|
||||
},
|
||||
],
|
||||
verification: "我这样理解对吗",
|
||||
});
|
||||
});
|
||||
|
||||
it("字段缺省时取安全默认(空/false/undefined),不信任外部数据", () => {
|
||||
const vm = toVM({});
|
||||
expect(vm).toEqual({
|
||||
needClarification: false,
|
||||
questions: [],
|
||||
verification: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
it("questions/options 内字段缺省时逐项补默认", () => {
|
||||
const vm = toVM({
|
||||
need_clarification: true,
|
||||
questions: [{ question: undefined, options: [{}], allow_free_text: undefined }],
|
||||
verification: null,
|
||||
});
|
||||
expect(vm).toEqual({
|
||||
needClarification: true,
|
||||
questions: [
|
||||
{ question: "", options: [{ label: "", value: "" }], allowFreeText: false },
|
||||
],
|
||||
verification: undefined,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("PROCEED", () => {
|
||||
it("放行常量:不反问、无问题", () => {
|
||||
expect(PROCEED).toEqual({ needClarification: false, questions: [] });
|
||||
});
|
||||
});
|
||||
|
||||
describe("needsClarifyGate", () => {
|
||||
it("去空白后长度小于 minChars 时需要预检", () => {
|
||||
expect(needsClarifyGate("改一下", 8)).toBe(true);
|
||||
|
||||
Reference in New Issue
Block a user