feedbackTicketsView.test.ts 2.8 KB

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