useConversationWorkspaceActions.test.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. // @vitest-environment jsdom
  2. import { renderHook, act } from "@testing-library/react";
  3. import { describe, expect, it, vi } from "vitest";
  4. import { useConversationWorkspaceActions } from "@/root/useConversationWorkspaceActions.js";
  5. describe("useConversationWorkspaceActions", () => {
  6. it("任务区的新建复用唯一创建入口,不按当前 workspace 复用 cwd", async () => {
  7. const createTask = vi.fn(async () => {});
  8. const prepareSession = vi.fn(async () => ({
  9. workspacePath: "/managed/new",
  10. projectId: null,
  11. additionalDirectories: [],
  12. }));
  13. const addTab = vi.fn();
  14. const { result } = renderHook(() =>
  15. useConversationWorkspaceActions({
  16. services: { projectService: { prepareSession } } as never,
  17. addTab,
  18. createTask,
  19. setWorkspaceActionError: vi.fn(),
  20. }),
  21. );
  22. await act(async () => {
  23. await result.current.handleCreateConversationTask();
  24. });
  25. expect(createTask).toHaveBeenCalledWith("task section new task");
  26. expect(prepareSession).not.toHaveBeenCalled();
  27. expect(addTab).not.toHaveBeenCalled();
  28. await act(async () => {
  29. await result.current.handleEnsureConversationWorkspace();
  30. });
  31. expect(addTab).toHaveBeenCalledWith("/managed/new", { workspacePurpose: "conversation" });
  32. });
  33. });