feedbackTimeline.test.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { createElement } from "react";
  2. import { renderToStaticMarkup } from "react-dom/server";
  3. import { describe, expect, it } from "vitest";
  4. import { FeedbackTimeline } from "@/feedback/feedbackTimeline.js";
  5. import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js";
  6. import type { FeedbackTicketEvent } from "@zcode/shared";
  7. function renderTimeline(events: FeedbackTicketEvent[], locale: "zh-CN" | "en-US" = "en-US") {
  8. return renderToStaticMarkup(
  9. createElement(
  10. ZCodeIntlProvider,
  11. { initialLocale: locale },
  12. createElement(FeedbackTimeline, {
  13. events,
  14. comments: [],
  15. showDurations: true,
  16. }),
  17. ),
  18. );
  19. }
  20. describe("FeedbackTimeline", () => {
  21. it("localizes known backend event summaries when the app locale is English", () => {
  22. const html = renderTimeline([
  23. {
  24. id: 1,
  25. ticket_id: 1,
  26. type: "created",
  27. summary: "反馈已提交",
  28. payload: {},
  29. created_at: "2026-06-07T04:00:00.000Z",
  30. },
  31. {
  32. id: 2,
  33. ticket_id: 1,
  34. type: "user_replied",
  35. summary: "你补充了信息",
  36. payload: {},
  37. created_at: "2026-06-07T04:00:30.000Z",
  38. },
  39. {
  40. id: 3,
  41. ticket_id: 1,
  42. type: "status_changed",
  43. summary: "状态更新为「开发中」",
  44. payload: { to: "开发中" },
  45. created_at: "2026-06-07T04:01:00.000Z",
  46. },
  47. {
  48. id: 4,
  49. ticket_id: 1,
  50. type: "status_changed",
  51. summary: "进度更新(状态→已解决):修复完成,等待验证",
  52. payload: { to: "已解决" },
  53. created_at: "2026-06-07T04:02:00.000Z",
  54. },
  55. ]);
  56. expect(html).toContain("Feedback submitted");
  57. expect(html).toContain("You added information");
  58. expect(html).toContain("Status changed to In development");
  59. expect(html).toContain("Progress updated (status to Resolved): 修复完成,等待验证");
  60. expect(html).not.toContain("反馈已提交");
  61. expect(html).not.toContain("你补充了信息");
  62. expect(html).not.toContain("状态更新为");
  63. expect(html).not.toContain("进度更新");
  64. });
  65. });