v4PendingCommandRecoveryBanner.test.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. expect(html).toContain("mb-3");
  34. expect(html).toContain("w-full");
  35. expect(html).toContain("shrink-0");
  36. expect(html).toContain("flex-wrap");
  37. expect(html).toContain("gap-2");
  38. expect(html).toContain("rounded-xl");
  39. expect(html).toContain("border-border");
  40. expect(html).toContain("bg-surface");
  41. expect(html).toContain("text-foreground");
  42. expect(html).not.toContain("bg-warning");
  43. expect(html).not.toContain("border-warning");
  44. expect(html).not.toContain("shadow-md");
  45. });
  46. });