feedbackTicketDetail.test.ts 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import { createElement } from "react";
  2. import { renderToStaticMarkup } from "react-dom/server";
  3. import { describe, expect, it, vi } from "vitest";
  4. import type { FeedbackTicketDetail } from "@zcode/shared";
  5. import type { IFeedbackService } from "@zcode/services";
  6. import { TicketDetailView } from "@/feedback/TicketDetail.js";
  7. import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js";
  8. function createTicket(): FeedbackTicketDetail {
  9. return {
  10. id: "ticket-1",
  11. title: "312312",
  12. type: "bug",
  13. status: "已提交",
  14. created_at: "2026-06-07T04:00:00.000Z",
  15. updated_at: "2026-06-07T04:01:00.000Z",
  16. description: "desc",
  17. attachments: [],
  18. comments: [],
  19. events: [
  20. {
  21. id: 1,
  22. ticket_id: 1,
  23. type: "created",
  24. summary: "反馈已提交",
  25. payload: {},
  26. created_at: "2026-06-07T04:00:00.000Z",
  27. },
  28. {
  29. id: 2,
  30. ticket_id: 1,
  31. type: "user_replied",
  32. summary: "你补充了信息",
  33. payload: {},
  34. created_at: "2026-06-07T04:01:00.000Z",
  35. },
  36. ],
  37. };
  38. }
  39. describe("TicketDetailView", () => {
  40. it("localizes the latest process summary card in English", () => {
  41. const html = renderToStaticMarkup(
  42. createElement(
  43. ZCodeIntlProvider,
  44. { initialLocale: "en-US" },
  45. createElement(TicketDetailView, {
  46. ticket: createTicket(),
  47. feedbackService: {} as IFeedbackService,
  48. onRefresh: vi.fn(),
  49. onOpenProcess: vi.fn(),
  50. }),
  51. ),
  52. );
  53. expect(html).toContain("You added information");
  54. expect(html).not.toContain("你补充了信息");
  55. });
  56. it("shows the localized issue id prefix with a copy action", () => {
  57. const html = renderToStaticMarkup(
  58. createElement(
  59. ZCodeIntlProvider,
  60. { initialLocale: "zh-CN" },
  61. createElement(TicketDetailView, {
  62. ticket: createTicket(),
  63. feedbackService: {} as IFeedbackService,
  64. onRefresh: vi.fn(),
  65. onOpenProcess: vi.fn(),
  66. }),
  67. ),
  68. );
  69. expect(html).toContain("ID");
  70. expect(html).toContain("ticket-1");
  71. expect(html).toContain('aria-label="复制 issue 编号"');
  72. });
  73. it("uses the English issue id prefix in English", () => {
  74. const html = renderToStaticMarkup(
  75. createElement(
  76. ZCodeIntlProvider,
  77. { initialLocale: "en-US" },
  78. createElement(TicketDetailView, {
  79. ticket: createTicket(),
  80. feedbackService: {} as IFeedbackService,
  81. onRefresh: vi.fn(),
  82. onOpenProcess: vi.fn(),
  83. }),
  84. ),
  85. );
  86. expect(html).toContain("Issue #");
  87. expect(html).toContain("ticket-1");
  88. expect(html).toContain('aria-label="Copy issue ID"');
  89. });
  90. });