- 冲突「采纳改法」:有补丁瞬时改入终稿并选中;无补丁但可定位则采纳时调 AI(refiner)重写该段套入;定位不到提示手改 - 正文改为行内高亮叠层编辑器(与页面同底色、随内容增高、无滚动条),点冲突卡/锚点整页滚到并选中+闪烁 - 仅对可在正文定位的冲突显示「跳转」/锚点;locate 支持从 where 引号抽原文,杜绝定位失败刷屏 - 伏笔建议卡:新埋一键登记(预填表单)/ 疑似回收一键标记 CLOSED(复用现有端点) - 审稿页草稿自动保存(防抖 PUT /draft),与「验收本章」解耦,刷新不丢 - 写作路由带章号 ?chapter=N + 验收成功面板/大纲页「写下一章」入口;写作目录从大纲列出全部章节 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
149 lines
4.6 KiB
TypeScript
149 lines
4.6 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import type { ForeshadowView } from "@/lib/api/types";
|
|
import {
|
|
buildRegisterRequest,
|
|
buildTransitionRequest,
|
|
extractReason,
|
|
groupByStatus,
|
|
isWindowApproaching,
|
|
suggestForeshadowCode,
|
|
validationReasonMessage,
|
|
} from "./board";
|
|
|
|
describe("suggestForeshadowCode", () => {
|
|
it("prefers the suggestion's own code when present", () => {
|
|
expect(suggestForeshadowCode("F-007", 3)).toBe("F-007");
|
|
expect(suggestForeshadowCode(" F-008 ", 3)).toBe("F-008");
|
|
});
|
|
|
|
it("falls back to FS-<2-digit index> when code is empty/null", () => {
|
|
expect(suggestForeshadowCode(null, 0)).toBe("FS-01");
|
|
expect(suggestForeshadowCode("", 4)).toBe("FS-05");
|
|
expect(suggestForeshadowCode(" ", 11)).toBe("FS-12");
|
|
});
|
|
});
|
|
|
|
const view = (over: Partial<ForeshadowView>): ForeshadowView => ({
|
|
code: "F-001",
|
|
title: "线索",
|
|
status: "OPEN",
|
|
...over,
|
|
});
|
|
|
|
describe("groupByStatus", () => {
|
|
it("splits items into four lanes preserving order", () => {
|
|
const lanes = groupByStatus([
|
|
view({ code: "F-001", status: "OPEN" }),
|
|
view({ code: "F-002", status: "OVERDUE" }),
|
|
view({ code: "F-003", status: "OPEN" }),
|
|
view({ code: "F-004", status: "CLOSED" }),
|
|
view({ code: "F-005", status: "PARTIAL" }),
|
|
]);
|
|
expect(lanes.OPEN.map((v) => v.code)).toEqual(["F-001", "F-003"]);
|
|
expect(lanes.OVERDUE.map((v) => v.code)).toEqual(["F-002"]);
|
|
expect(lanes.CLOSED.map((v) => v.code)).toEqual(["F-004"]);
|
|
expect(lanes.PARTIAL.map((v) => v.code)).toEqual(["F-005"]);
|
|
});
|
|
|
|
it("falls back unknown status to OPEN and handles undefined", () => {
|
|
const lanes = groupByStatus([view({ status: "WEIRD" })]);
|
|
expect(lanes.OPEN).toHaveLength(1);
|
|
expect(groupByStatus(undefined).OPEN).toEqual([]);
|
|
});
|
|
});
|
|
|
|
describe("isWindowApproaching", () => {
|
|
it("is true when current chapter is inside [from,to] for OPEN/PARTIAL", () => {
|
|
const f = view({
|
|
status: "PARTIAL",
|
|
expected_close_from: 40,
|
|
expected_close_to: 60,
|
|
});
|
|
expect(isWindowApproaching(f, 50)).toBe(true);
|
|
expect(isWindowApproaching(f, 39)).toBe(false);
|
|
expect(isWindowApproaching(f, 61)).toBe(false);
|
|
});
|
|
|
|
it("never flags CLOSED/OVERDUE or items without a window", () => {
|
|
expect(
|
|
isWindowApproaching(
|
|
view({ status: "CLOSED", expected_close_to: 60 }),
|
|
50,
|
|
),
|
|
).toBe(false);
|
|
expect(isWindowApproaching(view({ status: "OPEN" }), 50)).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("buildRegisterRequest", () => {
|
|
it("trims and omits empty optionals", () => {
|
|
expect(
|
|
buildRegisterRequest({
|
|
projectId: "p1",
|
|
code: " F-007 ",
|
|
title: " 旧誓约 ",
|
|
content: " ",
|
|
expectedCloseTo: 110,
|
|
}),
|
|
).toEqual({ code: "F-007", title: "旧誓约", expected_close_to: 110 });
|
|
});
|
|
|
|
it("keeps numeric and non-empty string optionals", () => {
|
|
expect(
|
|
buildRegisterRequest({
|
|
projectId: "p1",
|
|
code: "F-1",
|
|
title: "t",
|
|
plantedAt: 8,
|
|
content: "线索",
|
|
expectedCloseFrom: 40,
|
|
importance: "主线",
|
|
}),
|
|
).toEqual({
|
|
code: "F-1",
|
|
title: "t",
|
|
planted_at: 8,
|
|
content: "线索",
|
|
expected_close_from: 40,
|
|
importance: "主线",
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("buildTransitionRequest", () => {
|
|
it("includes only provided fields", () => {
|
|
expect(buildTransitionRequest({ projectId: "p1", toStatus: "PARTIAL" })).toEqual({
|
|
to_status: "PARTIAL",
|
|
});
|
|
expect(
|
|
buildTransitionRequest({
|
|
projectId: "p1",
|
|
progressEntry: { chapter: 23, note: "发光" },
|
|
}),
|
|
).toEqual({ progress_entry: { chapter: 23, note: "发光" } });
|
|
expect(buildTransitionRequest({ projectId: "p1" })).toEqual({});
|
|
expect(
|
|
buildTransitionRequest({ projectId: "p1", progressEntry: {} }),
|
|
).toEqual({});
|
|
});
|
|
});
|
|
|
|
describe("validationReasonMessage / extractReason", () => {
|
|
it("maps known reasons to friendly text", () => {
|
|
expect(validationReasonMessage("duplicate")).toContain("已存在");
|
|
expect(validationReasonMessage("invalid_transition")).toContain("终态");
|
|
expect(validationReasonMessage("empty_update")).toContain("进展");
|
|
expect(validationReasonMessage("invalid_status")).toContain("筛选");
|
|
expect(validationReasonMessage(undefined)).toContain("校验");
|
|
});
|
|
|
|
it("extracts details.reason from envelope", () => {
|
|
expect(
|
|
extractReason({ error: { details: { reason: "duplicate" } } }),
|
|
).toBe("duplicate");
|
|
expect(extractReason({ error: { details: null } })).toBeUndefined();
|
|
expect(extractReason("oops")).toBeUndefined();
|
|
});
|
|
});
|