chatErrorBannerHook.test.ts 1.5 KB

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