v4PendingCommandRecoveryBanner.test.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { createElement } from "react";
  2. import { renderToStaticMarkup } from "react-dom/server";
  3. import { describe, expect, it, vi } from "vitest";
  4. import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js";
  5. import { PendingCommandRecoveryBanner } from "@/v4/PendingCommandRecoveryBanner.js";
  6. import type { PendingCommandEntry } from "@/v4/pendingCommandRegistry.js";
  7. function render(entry: PendingCommandEntry): string {
  8. return renderToStaticMarkup(
  9. createElement(
  10. ZCodeIntlProvider,
  11. { initialLocale: "zh-CN" },
  12. createElement(PendingCommandRecoveryBanner, {
  13. entry,
  14. onResend: entry.replay.kind === "input" ? vi.fn() : undefined,
  15. onDismiss: vi.fn(),
  16. }),
  17. ),
  18. );
  19. }
  20. describe("PendingCommandRecoveryBanner", () => {
  21. it("discarded 普通输入提供显式重新发送按钮", () => {
  22. const html = render({
  23. commandId: "command-1",
  24. clientId: "client-1",
  25. sessionId: "session-1",
  26. issuedAt: 1,
  27. expiresAt: 2,
  28. recovery: "discarded",
  29. replay: { kind: "input", type: "sendText", payload: { text: "hello" } },
  30. });
  31. expect(html).toContain("CLI 重启前已提交的输入没有进入对话");
  32. expect(html).toContain("重新发送");
  33. });
  34. });