1
0

chat-layout.test.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { readFileSync } from "node:fs"
  2. import { resolve } from "node:path"
  3. import { describe, expect, it } from "vitest"
  4. import { getNextChatExpanded } from "./chat-layout"
  5. const chatPanelSource = readFileSync(resolve(__dirname, "..", "chat", "chat-panel.tsx"), "utf8")
  6. const previewPanelSource = readFileSync(resolve(__dirname, "preview-panel.tsx"), "utf8")
  7. describe("chat layout", () => {
  8. it("左侧主导航 AI会话按钮可以切换打开和关闭", () => {
  9. expect(getNextChatExpanded(false)).toBe(true)
  10. expect(getNextChatExpanded(true)).toBe(false)
  11. })
  12. it("预览面板源碼包含 handleDeAiSaveDraft 表明另存草稿存在", () => {
  13. expect(previewPanelSource).toContain("handleDeAiSaveDraft")
  14. })
  15. it("发送消息时接入去AI味默认模式", () => {
  16. expect(chatPanelSource).toContain("injectDeAiDirective")
  17. expect(chatPanelSource).toContain("deAiMode")
  18. })
  19. it("章节生成类对话会接入 QM-QUAI skill", () => {
  20. expect(chatPanelSource).toContain("buildQmQuaiSystemPrompt")
  21. expect(chatPanelSource).toContain("routeTask")
  22. expect(chatPanelSource).toContain("effectiveTaskRoute")
  23. expect(chatPanelSource).toContain('effectiveTaskRoute.intent === "write_chapter"')
  24. expect(chatPanelSource).toContain('effectiveTaskRoute.intent === "continue_chapter"')
  25. expect(chatPanelSource).toContain('effectiveTaskRoute.intent === "rewrite_chapter"')
  26. })
  27. it("小说写作不再弹出角色灵魂确认窗口", () => {
  28. expect(chatPanelSource).not.toContain("pendingSoulDialog")
  29. expect(chatPanelSource).not.toContain("本次写作将注入角色灵魂上下文")
  30. expect(chatPanelSource).not.toContain("requestSoulDialog")
  31. expect(chatPanelSource).toContain("pendingChapterPlan")
  32. expect(chatPanelSource).toContain("ChapterPlanConfirmDialog")
  33. expect(chatPanelSource).not.toContain("window.confirm")
  34. })
  35. it("预览面板中去AI味按钮出现在AI会话按钮后面", () => {
  36. const aiSessionIdx = previewPanelSource.indexOf("AI会话")
  37. const deAiIdx = previewPanelSource.lastIndexOf("去AI味")
  38. expect(aiSessionIdx).toBeGreaterThan(-1)
  39. expect(deAiIdx).toBeGreaterThan(-1)
  40. expect(deAiIdx).toBeGreaterThan(aiSessionIdx)
  41. })
  42. it("去AI味按钮点击后打开 Skill 选择,不再显示旧下拉菜单项", () => {
  43. expect(previewPanelSource).toContain("openDeAiSkillPicker")
  44. expect(previewPanelSource).toContain("openDeAiSkillPicker(null, e.currentTarget)")
  45. expect(previewPanelSource).toContain("选择去AI味技能")
  46. expect(previewPanelSource).not.toContain("处理当前内容")
  47. expect(previewPanelSource).not.toContain("设为默认")
  48. })
  49. })