feat(KB-502): add dashboard multi-project hooks and project API routes

- Add project API routes for multi-project backend integration
- Create useProjects hook for listing and managing registered projects
- Create useCurrentProject hook for current project selection and switching
- Create useProjectHealth hook for real-time project health metrics
- Create useActivityLog hook with ActivityLogModal integration
- Add comprehensive test coverage for all hooks (useProjects, useCurrentProject, useActivityLog)
- Add test setup utilities for React Query mocking
This commit is contained in:
gsxdsm
2026-04-01 01:15:44 -07:00
parent 265bcede89
commit 0ba42c92f3
12 changed files with 1919 additions and 70 deletions

View File

@@ -0,0 +1,60 @@
import { vi } from "vitest";
// Extend localStorage mock for multi-project tests
const localStorageMock: Record<string, string> = {};
if (typeof window !== "undefined") {
Object.defineProperty(window, "localStorage", {
value: {
getItem: (key: string) => localStorageMock[key] || null,
setItem: (key: string, value: string) => {
localStorageMock[key] = value;
},
removeItem: (key: string) => {
delete localStorageMock[key];
},
clear: () => {
Object.keys(localStorageMock).forEach((key) => delete localStorageMock[key]);
},
},
writable: true,
});
}
// Mock fetch for project API tests
const originalFetch = globalThis.fetch;
globalThis.fetch = vi.fn(async (url: RequestInfo | URL) => {
const urlString = url.toString();
// Mock project API responses
if (urlString.includes("/api/projects")) {
return {
ok: true,
status: 200,
json: async () => [],
text: async () => "[]",
headers: new Headers({ "content-type": "application/json" }),
} as Response;
}
// Default: return empty successful response
return {
ok: true,
status: 200,
json: async () => ({}),
text: async () => "{}",
headers: new Headers({ "content-type": "application/json" }),
} as Response;
}) as typeof fetch;
// Cleanup
afterEach(() => {
// Clear localStorage mock
Object.keys(localStorageMock).forEach((key) => delete localStorageMock[key]);
// Reset fetch mock
vi.mocked(globalThis.fetch).mockClear();
});
export { localStorageMock };