v4SessionSubscriptionErrorPanel.test.ts 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // @vitest-environment jsdom
  2. import type { IPlatformService } from "@zcode/shared";
  3. import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
  4. import { createElement } from "react";
  5. import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
  6. import { useFeedbackStore } from "@/feedback/feedbackStore.js";
  7. import { PlatformProvider } from "@/hooks/usePlatform.js";
  8. import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js";
  9. import { SessionSubscriptionErrorPanel } from "@/v4/SessionSubscriptionErrorPanel.js";
  10. const screenshot = {
  11. filename: "session-subscription-error.png",
  12. contentType: "image/png",
  13. dataBase64: "c2NyZWVuc2hvdA==",
  14. size: 10,
  15. };
  16. const captureWindowScreenshot = vi.fn(async () => screenshot);
  17. const platform = {
  18. captureWindowScreenshot,
  19. } as unknown as IPlatformService;
  20. function renderPanel() {
  21. return render(
  22. createElement(
  23. ZCodeIntlProvider,
  24. { initialLocale: "zh-CN" },
  25. createElement(
  26. PlatformProvider,
  27. { platform },
  28. createElement(SessionSubscriptionErrorPanel, {
  29. error: "EPERM: operation not permitted",
  30. sessionId: "session-1",
  31. workspacePath: "F:\\ZCode_data",
  32. onReconnect: vi.fn(),
  33. }),
  34. ),
  35. ),
  36. );
  37. }
  38. beforeEach(() => {
  39. useFeedbackStore.setState({
  40. open: false,
  41. featureRequestOpen: false,
  42. tab: "submit",
  43. submitDraft: null,
  44. submissionJobId: null,
  45. selectedTicketId: null,
  46. });
  47. });
  48. afterEach(() => {
  49. cleanup();
  50. vi.clearAllMocks();
  51. });
  52. describe("SessionSubscriptionErrorPanel", () => {
  53. it("shows the subscription error with report and reconnect actions", () => {
  54. renderPanel();
  55. expect(screen.getByText("EPERM: operation not permitted")).toBeTruthy();
  56. expect(screen.getByRole("button", { name: "反馈问题" })).toBeTruthy();
  57. expect(screen.getByRole("button", { name: "重新连接" })).toBeTruthy();
  58. });
  59. it("opens a feedback draft with the subscription error context", async () => {
  60. renderPanel();
  61. fireEvent.click(screen.getByRole("button", { name: "反馈问题" }));
  62. await waitFor(() => expect(useFeedbackStore.getState().open).toBe(true));
  63. expect(useFeedbackStore.getState().submitDraft).toMatchObject({
  64. title: "EPERM: operation not permitted",
  65. type: "bug",
  66. module: "Agent任务执行失败",
  67. severity: "P2-中",
  68. includeLogs: true,
  69. screenshots: [],
  70. });
  71. expect(useFeedbackStore.getState().submitDraft?.description).toContain(
  72. "报错摘要:EPERM: operation not permitted",
  73. );
  74. expect(useFeedbackStore.getState().submitDraft?.description).toContain("任务 ID: session-1");
  75. expect(useFeedbackStore.getState().submitDraft?.description).toContain(
  76. "工作区: F:\\ZCode_data",
  77. );
  78. });
  79. });