todoPanel.test.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { createElement, type ReactElement } from "react";
  2. import { renderToStaticMarkup } from "react-dom/server";
  3. import { describe, expect, it, vi } from "vitest";
  4. import { TooltipProvider } from "@/components/ui/tooltip.js";
  5. import { TodoPanel } from "../src/TodoPanel.js";
  6. vi.mock("@/i18n/IntlProvider.js", () => ({
  7. useZCodeIntl: () => ({
  8. intl: {
  9. formatMessage: ({ id }: { id: string }) => id,
  10. },
  11. }),
  12. }));
  13. function renderWithTooltipProvider(element: ReactElement) {
  14. return renderToStaticMarkup(createElement(TooltipProvider, null, element));
  15. }
  16. describe("TodoPanel", () => {
  17. it("hides the todo panel after every step is completed", () => {
  18. const html = renderWithTooltipProvider(
  19. createElement(TodoPanel, {
  20. isStreaming: true,
  21. plan: [
  22. { id: "step-1", status: "completed", title: "分析问题" },
  23. { id: "step-2", status: "completed", title: "修复问题" },
  24. ],
  25. }),
  26. );
  27. expect(html).toBe("");
  28. });
  29. it("does not render completed items in the expanded todo list", () => {
  30. const html = renderWithTooltipProvider(
  31. createElement(TodoPanel, {
  32. isStreaming: false,
  33. plan: [
  34. { id: "step-1", status: "completed", title: "已经完成的事项" },
  35. { id: "step-2", status: "pending", title: "还要处理的事项" },
  36. ],
  37. }),
  38. );
  39. expect(html).not.toContain("已经完成的事项");
  40. expect(html).toContain("还要处理的事项");
  41. });
  42. it("keeps collapsed todo layout bounded on narrow remote-control viewports", () => {
  43. const html = renderWithTooltipProvider(
  44. createElement(TodoPanel, {
  45. isStreaming: true,
  46. plan: [
  47. {
  48. id: "step-1",
  49. status: "in_progress",
  50. title:
  51. "这是一个很长的待办标题,用来模拟手机远程控制窄屏里当前任务标题把右侧按钮挤出容器的问题",
  52. },
  53. {
  54. id: "step-2",
  55. status: "pending",
  56. title: "下一步",
  57. },
  58. ],
  59. }),
  60. );
  61. expect(html).toContain("min-w-0 flex-1");
  62. expect(html).toContain("truncate");
  63. expect(html).toContain("shrink-0");
  64. expect(html).toMatch(
  65. /<button[^>]*aria-expanded="false"[^>]*class="[^"]*\binline-flex\b[^"]*\bmax-w-full\b/,
  66. );
  67. expect(html).not.toContain('data-slot="plan-header" role="button"');
  68. expect(html).not.toContain("cursor-pointer items-center gap-3 px-4");
  69. });
  70. });