Complete unit test coverage for all hooks and lib modules#29
Conversation
New test files: - __tests__/hooks/useFileUpload.test.ts (13 tests) - __tests__/hooks/useFeatureFlag.test.ts (9 tests) - __tests__/hooks/useRemoteConfig.test.ts (6 tests) - __tests__/hooks/useAnalyticsTracking.test.ts (7 tests) - __tests__/hooks/useNetworkStatus.test.ts (5 tests) - __tests__/hooks/useQueryBuilder.test.ts (12 tests) - __tests__/hooks/useOfflineSync.test.ts (9 tests) - __tests__/hooks/usePackages.test.ts (1 test) - __tests__/hooks/useBatchMutation.test.ts (1 test) - __tests__/hooks/useSavedViews.test.ts (1 test) - __tests__/hooks/useObjectStack.test.ts (4 tests) - __tests__/lib/server-url.test.ts (7 tests) - __tests__/lib/auth-client.test.ts (4 tests) Total: 493 tests, 58 suites (up from 413/45) Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR closes remaining unit test coverage gaps by adding Jest/RNTL test suites for previously-untested hooks and lib modules, and updates project documentation to reflect the new test totals (493 tests across 58 suites).
Changes:
- Added new unit tests for multiple hooks (e.g., file upload, feature flags, remote config, analytics tracking, network status, query builder, offline sync, barrel/alias exports).
- Added new unit tests for
lib/server-urlandlib/auth-client. - Updated roadmap/status docs with new suite/test counts and revised success criteria.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| docs/ROADMAP.md | Updates “关键路径” test totals to 493 tests / 58 suites. |
| docs/PROJECT-STATUS.md | Updates executive summary, coverage section, and test status totals. |
| docs/NEXT-PHASE.md | Updates status wording, test totals, and GA success criteria. |
| tests/lib/server-url.test.ts | Adds persistence + validation tests for server URL management. |
| tests/lib/auth-client.test.ts | Adds tests for auth client creation and reinitialization behavior. |
| tests/hooks/useSavedViews.test.ts | Verifies useSavedViews alias identity. |
| tests/hooks/useRemoteConfig.test.ts | Tests reactive remote config hooks with subscription updates. |
| tests/hooks/useQueryBuilder.test.ts | Tests filter tree CRUD/toggling/serialization behavior for query builder hook. |
| tests/hooks/usePackages.test.ts | Verifies usePackages alias identity. |
| tests/hooks/useOfflineSync.test.ts | Tests queue draining, conflict detection, and retry limit behavior. |
| tests/hooks/useObjectStack.test.ts | Verifies barrel exports are present/defined. |
| tests/hooks/useNetworkStatus.test.ts | Tests connectivity polling behavior and offline propagation. |
| tests/hooks/useFileUpload.test.ts | Tests upload/pick/capture/document/share flows and error handling. |
| tests/hooks/useFeatureFlag.test.ts | Tests reactive feature-flag evaluation/payload updates/unmount cleanup. |
| tests/hooks/useBatchMutation.test.ts | Verifies useBatchMutation alias identity. |
| tests/hooks/useAnalyticsTracking.test.ts | Tests page view tracking and action tracking helpers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| it("falls back to HEAD request when /api/health fails", async () => { | ||
| global.fetch = jest | ||
| .fn() | ||
| .mockRejectedValueOnce(new Error("health failed")) | ||
| .mockResolvedValueOnce({ status: 200 }) as any; |
There was a problem hiding this comment.
These tests intentionally trigger validateServerUrl()'s error path (mocked fetch rejection). In lib/server-url.ts, the setTimeout(..., 8000) created for the AbortController is only cleared after a successful await fetch(...), so when fetch rejects the timeout is never cleared. That can leave pending timers/open handles and slow the Jest run. Suggest fixing validateServerUrl to always clearTimeout(timeout) in a finally block for both the health and HEAD attempts (preferred), or switch this test suite to fake timers and flush pending timers after each test.
11 hooks and 2 lib modules had zero test coverage. This closes the gap, bringing the suite from 413/45 to 493/58 (tests/suites).
New hook tests
useFileUpload(13) — upload, image/camera/document pick, download, share, permission denial, cancellationuseFeatureFlag(9) — flag evaluation, payload access, subscription lifecycle, cleanup on unmountuseRemoteConfig(6) — typed config values, fallback defaults, reactive updatesuseAnalyticsTracking(7) — page view on mount, re-track on screen change, action trackinguseNetworkStatus(5) — connectivity polling, offline state propagation, error resilienceuseQueryBuilder(12) — filter tree CRUD, nested groups, toggle logic, serializationuseOfflineSync(9) — queue drain for create/update/delete, 409 conflict detection, max-retry failureusePackages,useBatchMutation,useSavedViews(1 each) — barrel re-export identity checksuseObjectStack(4) — validates all 17 re-exported hooks are definedNew lib tests
server-url(7) — SecureStore persistence,validateServerUrlwith health/HEAD fallback chainauth-client(4) — initial creation,reinitializeAuthClientURL swap, expo plugin wiringDocs
Updated test counts in
NEXT-PHASE.md,PROJECT-STATUS.md,ROADMAP.md.💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.