chatPlaceholder.test.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. resolveChatPlaceholderKey,
  4. shouldDeferChatPlaceholder,
  5. } from "../src/lib/chatPlaceholder.js";
  6. import enUS from "../src/i18n/locales/en-US.js";
  7. import zhCN from "../src/i18n/locales/zh-CN.js";
  8. describe("resolveChatPlaceholderKey", () => {
  9. it("returns newTask for empty conversation", () => {
  10. expect(
  11. resolveChatPlaceholderKey({
  12. hasHistoryMessages: false,
  13. isTaskProcessing: false,
  14. }),
  15. ).toBe("chat.placeholder.newTask");
  16. });
  17. it("returns compact newTask copy for an empty mobile remote conversation", () => {
  18. expect(
  19. resolveChatPlaceholderKey({
  20. hasHistoryMessages: false,
  21. isTaskProcessing: false,
  22. compactNewTask: true,
  23. }),
  24. ).toBe("chat.placeholder.newTaskMobile");
  25. expect(enUS["chat.placeholder.newTaskMobile"]).toBe("Ask ZCode anything…");
  26. expect(zhCN["chat.placeholder.newTaskMobile"]).toBe("向 ZCode 提问…");
  27. });
  28. it("returns newTask while first turn is processing", () => {
  29. expect(
  30. resolveChatPlaceholderKey({
  31. hasHistoryMessages: false,
  32. isTaskProcessing: true,
  33. }),
  34. ).toBe("chat.placeholder.newTask");
  35. });
  36. it("returns followUpAsk when conversation is idle", () => {
  37. expect(
  38. resolveChatPlaceholderKey({
  39. hasHistoryMessages: true,
  40. isTaskProcessing: false,
  41. }),
  42. ).toBe("chat.placeholder.followUpAsk");
  43. });
  44. it("returns followUpQueue when follow-up can be queued", () => {
  45. expect(
  46. resolveChatPlaceholderKey({
  47. hasHistoryMessages: true,
  48. isTaskProcessing: true,
  49. }),
  50. ).toBe("chat.placeholder.followUpQueue");
  51. });
  52. });
  53. describe("shouldDeferChatPlaceholder", () => {
  54. it("defers placeholder while bound task is creating", () => {
  55. expect(
  56. shouldDeferChatPlaceholder({
  57. hasBoundTask: true,
  58. taskStatus: "creating",
  59. }),
  60. ).toBe(true);
  61. });
  62. it("defers placeholder while bound task is restoring", () => {
  63. expect(
  64. shouldDeferChatPlaceholder({
  65. hasBoundTask: true,
  66. taskStatus: "restoring",
  67. }),
  68. ).toBe(true);
  69. });
  70. it("does not defer placeholder after task becomes ready", () => {
  71. expect(
  72. shouldDeferChatPlaceholder({
  73. hasBoundTask: true,
  74. taskStatus: "ready",
  75. }),
  76. ).toBe(false);
  77. });
  78. it("does not defer placeholder in draft mode", () => {
  79. expect(
  80. shouldDeferChatPlaceholder({
  81. hasBoundTask: false,
  82. taskStatus: "creating",
  83. }),
  84. ).toBe(false);
  85. });
  86. });