fix(web): 大纲生成只替换目标卷+重排确认+窗口徽标用lucide + 伏笔看板中文化/单一登记入口/Field表单
This commit is contained in:
@@ -11,8 +11,8 @@ const toast = vi.fn();
|
||||
vi.mock("@/lib/api/client", () => ({ api: { POST: (...a: unknown[]) => post(...a) } }));
|
||||
vi.mock("@/components/Toast", () => ({ useToast: () => toast }));
|
||||
|
||||
function makeChapter(no: number): OutlineChapterView {
|
||||
return { no, volume: 1 };
|
||||
function makeChapter(no: number, volume = 1): OutlineChapterView {
|
||||
return { no, volume };
|
||||
}
|
||||
|
||||
describe("useOutline", () => {
|
||||
@@ -51,6 +51,25 @@ describe("useOutline", () => {
|
||||
expect(toast).toHaveBeenCalledWith("大纲已生成", "success");
|
||||
});
|
||||
|
||||
it("生成只替换目标卷,保留其它卷的已存章节", async () => {
|
||||
const initial = [makeChapter(1, 1), makeChapter(2, 1), makeChapter(80, 2)];
|
||||
const regenerated = [makeChapter(1, 1), makeChapter(2, 1), makeChapter(3, 1)];
|
||||
post.mockResolvedValue({ data: { chapters: regenerated }, error: null });
|
||||
|
||||
const { result } = renderHook(() => useOutline(initial));
|
||||
await act(async () => {
|
||||
await result.current.generate("p1", 1);
|
||||
});
|
||||
|
||||
// 卷 2 的第 80 章不被整列覆盖;卷 1 替换为新生成的三章。
|
||||
expect(result.current.chapters).toEqual([
|
||||
makeChapter(80, 2),
|
||||
makeChapter(1, 1),
|
||||
makeChapter(2, 1),
|
||||
makeChapter(3, 1),
|
||||
]);
|
||||
});
|
||||
|
||||
it("data.chapters 为空时章节回退为空数组", async () => {
|
||||
post.mockResolvedValue({ data: { chapters: null }, error: null });
|
||||
const { result } = renderHook(() => useOutline([]));
|
||||
|
||||
Reference in New Issue
Block a user