onboardingSessionLimitOptions.test.ts 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { createElement } from "react";
  2. import { renderToStaticMarkup } from "react-dom/server";
  3. import { describe, expect, it, vi } from "vitest";
  4. import {
  5. resolveClaudeMigrationScanLimit,
  6. UNLIMITED_SCAN_LIMIT_INPUT,
  7. } from "@/hooks/useClaudeSessionMigration.js";
  8. vi.mock("@/i18n/IntlProvider.js", () => ({
  9. useZCodeIntl: () => ({
  10. intl: {
  11. formatMessage: ({ id }: { id: string }, values?: Record<string, string>) => {
  12. if (id === "onboarding.sessions.count") {
  13. return `${values?.count ?? ""} 个会话`;
  14. }
  15. if (id === "onboarding.sessions.unlimited") {
  16. return "不限制";
  17. }
  18. return id;
  19. },
  20. },
  21. }),
  22. }));
  23. vi.mock("@/components/ui/select.js", () => ({
  24. Select: ({ children }: { children: unknown }) => createElement("div", null, children),
  25. SelectContent: ({ children }: { children: unknown }) => createElement("div", null, children),
  26. SelectItem: ({ children, value }: { children: unknown; value: string }) =>
  27. createElement("div", { "data-value": value }, children),
  28. SelectTrigger: ({ children }: { children: unknown }) => createElement("button", null, children),
  29. SelectValue: () => null,
  30. }));
  31. vi.mock("@/components/ui/button.js", () => ({
  32. Button: ({ children, ...props }: { children: unknown; [key: string]: unknown }) =>
  33. createElement("button", props, children),
  34. }));
  35. vi.mock("@/components/ui/badge.js", () => ({
  36. Badge: ({ children }: { children: unknown }) => createElement("span", null, children),
  37. }));
  38. describe("OnboardingSessionsStep", () => {
  39. it("把不限制选项解析为无扫描 limit", () => {
  40. expect(resolveClaudeMigrationScanLimit(UNLIMITED_SCAN_LIMIT_INPUT)).toBeUndefined();
  41. });
  42. it("提供 30、50、100 和不限制四个会话扫描数量选项", async () => {
  43. const { OnboardingSessionsStep } = await import("@/onboarding/OnboardingFlowParts.js");
  44. const html = renderToStaticMarkup(
  45. createElement(OnboardingSessionsStep, {
  46. migration: {
  47. range: "30d",
  48. setRange: vi.fn(),
  49. limitInput: "100",
  50. setLimitInput: vi.fn(),
  51. supportState: { supported: true },
  52. isScanning: false,
  53. scan: vi.fn(),
  54. scanError: null,
  55. },
  56. workspaceCandidates: [],
  57. selectedWorkspacePaths: [],
  58. onToggleWorkspace: vi.fn(),
  59. onSelectAll: vi.fn(),
  60. onClearSelection: vi.fn(),
  61. }),
  62. );
  63. expect(html).toContain("30 个会话");
  64. expect(html).toContain("50 个会话");
  65. expect(html).toContain("100 个会话");
  66. expect(html).toContain("不限制");
  67. expect(html).toContain('data-value="unlimited"');
  68. });
  69. });