Add unit tests for frontend utilities and hooks
82 tests covering download.ts and all React Query hooks. API modules are mocked with vi.mock; mutation tests spy on queryClient.invalidateQueries to verify cache invalidation. Conditional queries (null id) are verified to stay idle. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,31 +1,27 @@
|
||||
---
|
||||
# nuzlocke-tracker-ee9s
|
||||
title: Unit tests for frontend utilities and hooks
|
||||
status: draft
|
||||
status: completed
|
||||
type: task
|
||||
priority: normal
|
||||
created_at: 2026-02-10T09:33:38Z
|
||||
updated_at: 2026-02-10T09:33:38Z
|
||||
updated_at: 2026-02-21T12:47:19Z
|
||||
parent: nuzlocke-tracker-yzpb
|
||||
---
|
||||
|
||||
Write unit tests for the frontend utility functions and custom React hooks.
|
||||
|
||||
All API modules are mocked with `vi.mock`. Hooks are tested with `renderHook` from @testing-library/react, wrapped in `QueryClientProvider`. Mutation tests spy on `queryClient.invalidateQueries` to verify cache invalidation.
|
||||
|
||||
## Checklist
|
||||
|
||||
- [ ] Test `utils/formatEvolution.ts` — evolution chain formatting logic
|
||||
- [ ] Test `utils/download.ts` — file download utility
|
||||
- [ ] Test `hooks/useRuns.ts` — run CRUD hook with mocked API
|
||||
- [ ] Test `hooks/useGames.ts` — game fetching hook
|
||||
- [ ] Test `hooks/useEncounters.ts` — encounter operations hook
|
||||
- [ ] Test `hooks/usePokemon.ts` — pokemon data hook
|
||||
- [ ] Test `hooks/useGenlockes.ts` — genlocke operations hook
|
||||
- [ ] Test `hooks/useBosses.ts` — boss operations hook
|
||||
- [ ] Test `hooks/useStats.ts` — stats fetching hook
|
||||
- [ ] Test `hooks/useAdmin.ts` — admin operations hook
|
||||
|
||||
## Notes
|
||||
|
||||
- Utility functions are pure functions — straightforward to test
|
||||
- Hooks wrap React Query — test that they call the right API endpoints, handle loading/error states, and invalidate queries correctly
|
||||
- Use `@testing-library/react`'s `renderHook` for hook testing
|
||||
- Mock the API client (from `src/api/`) rather than individual fetch calls
|
||||
- [x] Test `utils/formatEvolution.ts` — done in smoke test
|
||||
- [x] Test `utils/download.ts` — blob URL creation, filename, cleanup
|
||||
- [x] Test `hooks/useGames.ts` — query hooks and disabled state
|
||||
- [x] Test `hooks/useRuns.ts` — query hooks + mutations with cache invalidation
|
||||
- [x] Test `hooks/useEncounters.ts` — mutations and conditional queries
|
||||
- [x] Test `hooks/usePokemon.ts` — conditional queries
|
||||
- [x] Test `hooks/useGenlockes.ts` — queries and mutations
|
||||
- [x] Test `hooks/useBosses.ts` — queries and mutations
|
||||
- [x] Test `hooks/useStats.ts` — single query hook
|
||||
- [x] Test `hooks/useAdmin.ts` — representative subset (usePokemonList, useCreateGame, useDeleteGame)
|
||||
|
||||
@@ -24,5 +24,5 @@ Add comprehensive unit and integration test coverage to both the backend (FastAP
|
||||
- [ ] Backend schemas and services have unit test coverage
|
||||
- [x] Backend API endpoints have integration test coverage
|
||||
- [x] Frontend test infrastructure is set up (Vitest, RTL)
|
||||
- [ ] Frontend utilities and hooks have unit test coverage
|
||||
- [x] Frontend utilities and hooks have unit test coverage
|
||||
- [ ] Frontend components have basic render/interaction tests
|
||||
Reference in New Issue
Block a user