chatErrorBannerHook.test.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { createElement } from "react";
  2. import { renderToStaticMarkup } from "react-dom/server";
  3. import { type IPlatformService } from "@zcode/shared";
  4. import { TID_CHAT_ERROR_DETAILS_BUTTON, TID_CHAT_ERROR_HOOK_ICON } from "@zcode/shared/test-ids";
  5. import { describe, expect, it, vi } from "vitest";
  6. import { ChatErrorBanner } from "@/ChatErrorBanner.js";
  7. import { PlatformProvider } from "@/hooks/usePlatform.js";
  8. import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js";
  9. vi.mock("@/components/ui/toast.js", () => ({
  10. toast: vi.fn(),
  11. }));
  12. const mockPlatform = {
  13. captureWindowScreenshot: vi.fn(async () => null),
  14. } as unknown as IPlatformService;
  15. describe("ChatErrorBanner Hook errors", () => {
  16. it("renders the Hook icon and details action for a blocked Hook error", () => {
  17. const html = renderToStaticMarkup(
  18. createElement(
  19. ZCodeIntlProvider,
  20. { initialLocale: "zh-CN" },
  21. createElement(
  22. PlatformProvider,
  23. { platform: mockPlatform },
  24. createElement(ChatErrorBanner, {
  25. error: {
  26. code: "fault.runtime.hookBlocked",
  27. message: "hooks_prompt_block: python3: missing file",
  28. detail: "Hook block reason: hooks_prompt_block\nHook error: python3: missing file",
  29. },
  30. }),
  31. ),
  32. ),
  33. );
  34. expect(html).toContain("hooks_prompt_block: python3: missing file");
  35. expect(html).toContain(`data-testid="${TID_CHAT_ERROR_DETAILS_BUTTON}"`);
  36. expect(html).toContain("展开详情");
  37. expect(html).toContain(`data-testid="${TID_CHAT_ERROR_HOOK_ICON}"`);
  38. });
  39. });