feedbackTicketsView.test.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { createElement } from "react";
  2. import { renderToStaticMarkup } from "react-dom/server";
  3. import { describe, expect, it, vi } from "vitest";
  4. import type { IFeedbackService } from "@zcode/services";
  5. import type { FeedbackTicketSummary } from "@zcode/shared";
  6. import { FeedbackTicketList, TicketsView } from "@/feedback/TicketsView.js";
  7. import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js";
  8. function createFeedbackService(): IFeedbackService {
  9. return {
  10. getDeviceSnapshot: vi.fn(),
  11. create: vi.fn(),
  12. list: vi.fn(async () => ({ items: [], total: 0 })),
  13. get: vi.fn(),
  14. comment: vi.fn(),
  15. uploadAttachmentData: vi.fn(),
  16. uploadAttachmentWithProgress: vi.fn(),
  17. prepareCompactLogArchive: vi.fn(),
  18. cleanupPreparedLogArchive: vi.fn(),
  19. onDynamicUploadProgress: vi.fn(),
  20. cancelCreate: vi.fn(),
  21. cancelUpload: vi.fn(),
  22. onDynamicUpdate: vi.fn(),
  23. } as unknown as IFeedbackService;
  24. }
  25. function renderTicketsView(locale: "zh-CN" | "en-US") {
  26. return renderToStaticMarkup(
  27. createElement(
  28. ZCodeIntlProvider,
  29. { initialLocale: locale },
  30. createElement(TicketsView, {
  31. feedbackService: createFeedbackService(),
  32. onCreateNew: vi.fn(),
  33. }),
  34. ),
  35. );
  36. }
  37. describe("TicketsView", () => {
  38. it("uses English copy for the initial feedback list loading state without a detail placeholder", () => {
  39. const html = renderTicketsView("en-US");
  40. expect(html).toContain("Loading...");
  41. expect(html).not.toContain("Select feedback to view details");
  42. expect(html).not.toContain("加载中");
  43. });
  44. it("renders ticket IDs with a copy action in the list", () => {
  45. const ticket: FeedbackTicketSummary = {
  46. id: "ZC-123",
  47. title: "Cannot submit prompt",
  48. type: "bug",
  49. status: "已提交",
  50. created_at: new Date().toISOString(),
  51. updated_at: new Date().toISOString(),
  52. };
  53. const html = renderToStaticMarkup(
  54. createElement(
  55. ZCodeIntlProvider,
  56. { initialLocale: "en-US" },
  57. createElement(FeedbackTicketList, {
  58. items: [ticket],
  59. selectedTicketId: null,
  60. copiedTicketId: null,
  61. onCopyTicketId: vi.fn(),
  62. }),
  63. ),
  64. );
  65. expect(html).toContain("ZC-123");
  66. expect(html).toContain("Issue #");
  67. expect(html).toContain("Copy issue ID");
  68. expect(html).toContain("Cannot submit prompt");
  69. });
  70. });