executePermissionPreview.test.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { createElement } from "react";
  2. import { renderToStaticMarkup } from "react-dom/server";
  3. import { describe, expect, it } from "vitest";
  4. import { ExecuteToolCallBlock } from "@/ToolCallBlocks/renderers/execute.js";
  5. import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js";
  6. import type { ToolCallBlockRenderContext } from "@/ToolCallBlocks/shared.js";
  7. function renderPreview(isPermissionPreview: boolean) {
  8. return renderToStaticMarkup(
  9. createElement(
  10. ZCodeIntlProvider,
  11. { initialLocale: "zh-CN" },
  12. createElement(ExecuteToolCallBlock, {
  13. toolCallNode: {
  14. toolCall: {
  15. toolId: "command",
  16. kind: "execute",
  17. status: "completed",
  18. input: { command: "echo hello" },
  19. },
  20. childToolCalls: [],
  21. },
  22. workspacePath: "/workspace",
  23. rawFileSummaries: [],
  24. isRunning: false,
  25. statusLabel: "",
  26. childToolList: null,
  27. forceOpen: true,
  28. isPermissionPreview,
  29. } as ToolCallBlockRenderContext),
  30. ),
  31. );
  32. }
  33. describe("execute permission preview", () => {
  34. it("does not describe an unexecuted permission request as empty output", () => {
  35. expect(renderPreview(true)).not.toContain("没有输出。");
  36. });
  37. it("retains the empty-output hint for completed execution", () => {
  38. expect(renderPreview(false)).toContain("没有输出。");
  39. });
  40. });