Files
fusion/packages/dashboard/app/hooks/__tests__/useSessionFiles.test.ts
gsxdsm f2c00ad147 feat(KB-175): move file browser to header with workspace support
- Add workspace file APIs and hooks for session-scoped file browsing
- Create WorkspaceSelector component for switching between workspaces
- Update FileBrowserModal with workspace mode and improved UX
- Add files button to header with workspace-aware file browsing
- Add session files indicator to task cards for quick file access
- Include comprehensive tests for all new components and hooks
2026-03-31 01:26:57 -07:00

54 lines
1.9 KiB
TypeScript

import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import { renderHook, waitFor } from "@testing-library/react";
import { useSessionFiles } from "../useSessionFiles";
import * as api from "../../api";
vi.mock("../../api", () => ({
fetchSessionFiles: vi.fn(),
}));
const mockFetchSessionFiles = vi.mocked(api.fetchSessionFiles);
describe("useSessionFiles", () => {
beforeEach(() => {
mockFetchSessionFiles.mockReset();
});
afterEach(() => {
vi.clearAllMocks();
});
it("fetches session files for active tasks with a worktree", async () => {
mockFetchSessionFiles.mockResolvedValueOnce(["src/a.ts", "src/b.ts"]);
const { result } = renderHook(() => useSessionFiles("KB-123", "/repo/.worktrees/kb-123", "in-progress"));
await waitFor(() => expect(result.current.loading).toBe(false));
expect(result.current.files).toEqual(["src/a.ts", "src/b.ts"]);
expect(mockFetchSessionFiles).toHaveBeenCalledWith("KB-123");
});
it("does not fetch for tasks without worktrees or inactive columns", async () => {
const { result: noWorktree } = renderHook(() => useSessionFiles("KB-123", undefined, "in-progress"));
const { result: inactive } = renderHook(() => useSessionFiles("KB-123", "/repo/.worktrees/kb-123", "todo"));
await waitFor(() => expect(noWorktree.current.loading).toBe(false));
await waitFor(() => expect(inactive.current.loading).toBe(false));
expect(noWorktree.current.files).toEqual([]);
expect(inactive.current.files).toEqual([]);
expect(mockFetchSessionFiles).not.toHaveBeenCalled();
});
it("returns empty files on fetch failure", async () => {
mockFetchSessionFiles.mockRejectedValueOnce(new Error("boom"));
const { result } = renderHook(() => useSessionFiles("KB-123", "/repo/.worktrees/kb-123", "in-review"));
await waitFor(() => expect(result.current.loading).toBe(false));
expect(result.current.files).toEqual([]);
});
});