progress-text.test.ts 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. formatImportCompletionLines,
  4. formatImportDiscoveryLine,
  5. formatImportResumeLine,
  6. formatWriteCompletionLines,
  7. formatWriteDoneLine,
  8. formatWriteStartLine,
  9. } from "../progress-text.js";
  10. describe("CLI progress text", () => {
  11. it("formats Chinese write progress lines", () => {
  12. expect(formatWriteStartLine("zh", 1, 3, "demo-book")).toBe('[1/3] 为「demo-book」撰写章节...');
  13. expect(formatWriteCompletionLines("zh", {
  14. chapterNumber: 7,
  15. title: "潮声夜渡",
  16. wordCount: 2345,
  17. passedAudit: false,
  18. revised: true,
  19. status: "audit-failed",
  20. issues: [
  21. { severity: "warning", category: "continuity", description: "时间线略有跳变" },
  22. ],
  23. })).toEqual([
  24. " 第7章:潮声夜渡",
  25. " 字数:2345字",
  26. " 审计:需复核",
  27. " 自动修正:已执行(已修复关键问题)",
  28. " 状态:audit-failed",
  29. " 问题:",
  30. " [warning] continuity: 时间线略有跳变",
  31. "",
  32. ]);
  33. expect(formatWriteDoneLine("zh")).toBe("完成。");
  34. });
  35. it("formats English write progress lines", () => {
  36. expect(formatWriteStartLine("en", 2, 5, "demo-book")).toBe('[2/5] Writing chapter for "demo-book"...');
  37. expect(formatWriteCompletionLines("en", {
  38. chapterNumber: 7,
  39. title: "Harbor Wake",
  40. wordCount: 2310,
  41. passedAudit: true,
  42. revised: false,
  43. status: "ready-for-review",
  44. issues: [],
  45. })).toEqual([
  46. " Chapter 7: Harbor Wake",
  47. " Length: 2310 words",
  48. " Audit: PASSED",
  49. " Status: ready-for-review",
  50. "",
  51. ]);
  52. expect(formatWriteDoneLine("en")).toBe("Done.");
  53. });
  54. it("formats Chinese import progress lines", () => {
  55. expect(formatImportDiscoveryLine("zh", 12, "demo-book")).toBe('发现 12 章,准备导入到「demo-book」。');
  56. expect(formatImportResumeLine("zh", 8)).toBe("从第 8 章继续导入。");
  57. expect(formatImportCompletionLines("zh", {
  58. importedCount: 12,
  59. totalCountLabel: "24000字",
  60. nextChapter: 13,
  61. bookId: "demo-book",
  62. })).toEqual([
  63. "导入完成:",
  64. " 已导入章节:12",
  65. " 总长度:24000字",
  66. " 下一章编号:13",
  67. '',
  68. '运行 "inkos write next demo-book" 继续写作。',
  69. ]);
  70. });
  71. it("formats English import progress lines", () => {
  72. expect(formatImportDiscoveryLine("en", 12, "demo-book")).toBe('Found 12 chapters to import into "demo-book".');
  73. expect(formatImportResumeLine("en", 8)).toBe("Resuming from chapter 8.");
  74. expect(formatImportCompletionLines("en", {
  75. importedCount: 12,
  76. totalCountLabel: "24000 words",
  77. nextChapter: 13,
  78. bookId: "demo-book",
  79. })).toEqual([
  80. "Import complete:",
  81. " Chapters imported: 12",
  82. " Total length: 24000 words",
  83. " Next chapter number: 13",
  84. '',
  85. 'Run "inkos write next demo-book" to continue writing.',
  86. ]);
  87. });
  88. });