Files
fusion/packages/dashboard/app/hooks/__tests__/useWorkspaces.test.ts
gsxdsm 5647e500cf feat(KB-332): rename task prefix from KB to FN and branches from kb/ to fusion/
- Change default task prefix from KB to FN across all packages

- Rename branch naming pattern from kb/{id} to fusion/{id}

- Update all test assertions and fixtures to use new prefixes

- Add changeset for the breaking change

- Resolve merge conflicts in TaskCard.test.tsx touch gesture tests
2026-03-31 19:29:47 -07:00

74 lines
2.2 KiB
TypeScript

import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import { renderHook, waitFor } from "@testing-library/react";
import { useWorkspaces } from "../useWorkspaces";
import * as api from "../../api";
vi.mock("../../api", () => ({
fetchWorkspaces: vi.fn(),
}));
const mockFetchWorkspaces = vi.mocked(api.fetchWorkspaces);
describe("useWorkspaces", () => {
beforeEach(() => {
mockFetchWorkspaces.mockReset();
});
afterEach(() => {
vi.clearAllMocks();
});
it("loads project and task workspaces", async () => {
mockFetchWorkspaces.mockResolvedValueOnce({
project: "/Users/test/repo",
tasks: [{ id: "FN-123", title: "Feature", worktree: "/Users/test/.worktrees/kb-123" }],
});
const { result } = renderHook(() => useWorkspaces());
await waitFor(() => expect(result.current.loading).toBe(false));
expect(result.current.projectName).toBe("repo");
expect(result.current.workspaces).toEqual([
{
id: "FN-123",
label: "FN-123",
title: "Feature",
worktree: "/Users/test/.worktrees/kb-123",
kind: "task",
},
]);
});
it("polls for workspace updates", async () => {
mockFetchWorkspaces
.mockResolvedValueOnce({ project: "/repo", tasks: [] })
.mockResolvedValueOnce({
project: "/repo",
tasks: [{ id: "FN-200", title: "Later", worktree: "/repo/.worktrees/kb-200" }],
});
const { result } = renderHook(() => useWorkspaces());
await waitFor(() => expect(result.current.loading).toBe(false));
expect(result.current.workspaces).toEqual([]);
// Wait for the polling interval (10 seconds) - use real timers
await new Promise((resolve) => setTimeout(resolve, 10000));
await waitFor(() => expect(result.current.workspaces).toHaveLength(1));
expect(mockFetchWorkspaces).toHaveBeenCalledTimes(2);
}, 15000);
it("surfaces fetch errors", async () => {
mockFetchWorkspaces.mockRejectedValueOnce(new Error("Failed to load workspaces"));
const { result } = renderHook(() => useWorkspaces());
await waitFor(() => expect(result.current.loading).toBe(false));
expect(result.current.error).toBe("Failed to load workspaces");
expect(result.current.workspaces).toEqual([]);
});
});