test: add comprehensive unit tests for InlineEditHistory and LocationPicker
Summary
This MR improves frontend reliability by adding comprehensive unit test coverage for the following components:
- InlineEditHistory.tsx
- LocationPicker.tsx
A total of 10 meaningful tests were added covering async history loading, expand/collapse behavior, fallback rendering, geolocation flows, map interactions, modal actions, and error paths. This improves confidence in future changes and reduces regression risk in these user-facing components.
What does this MR do and why?
Previously, these components had limited or no dedicated test coverage, leaving important workflows such as edit history rendering, location selection, geolocation handling, and interaction states untested.
This MR addresses those gaps by:
- Adding comprehensive test coverage for two critical UI components
- Testing success, failure, loading, empty, and interaction states
- Covering edge cases and defensive paths
- Improving confidence in future refactors
- Verifying component behavior through user-focused tests
Motivation:
- Improve code reliability and maintainability
- Prevent regressions in edit history and location selection workflows
- Increase confidence in future UI refactors
- Strengthen component-level test coverage
- Improve test quality standards
Approach
- Used Vitest and React Testing Library
- Followed behavior-driven testing practices
- Focused on user-visible behavior instead of implementation details
- Mocked external dependencies and browser APIs
- Tested edge cases and defensive branches
- Kept production changes minimal and behavior-preserving
Trade-offs:
- LocationPicker relies on mocked react-leaflet and browser geolocation APIs in tests
- Test execution time increases slightly due to added coverage
- One unreachable branch in LocationPicker required a minimal cleanup to achieve true coverage
Changes Made
New Test Files Added:
tests/src/components/InlineEditHistory.test.tsx (5 tests)
tests/src/components/LocationPicker.test.tsx (5 tests)
Component Improvements:
src/components/LocationPicker.tsx
Changes:
- Removed unreachable position === null branch
- Removed unused imports tied to dead path
Purpose:
- Enable true branch coverage
- Preserve runtime behavior
Technical Details
Root Cause:
- Missing test coverage for InlineEditHistory and LocationPicker
- No validation of async history loading and error states
- No test coverage for geolocation flows
- No test coverage for map interaction and modal behavior
Solution:
- Implemented focused component test suites
- Mocked fetch, react-i18next, react-leaflet, leaflet, and navigator.geolocation
- Verified UI state transitions and callback behavior
- Covered fallback rendering and defensive paths
Component Behavior Covered:
InlineEditHistory:
- Component rendering
- Loading state
- Successful fetch rendering
- Empty state
- API failure handling
- Error handling
- Expand/collapse behavior
- Field change rendering
- Fallback N/A rendering
LocationPicker:
- Modal rendering
- Default coordinate selection
- Close action
- Confirm location action
- Map click interaction
- Marker drag interaction
- Geolocation loading state
- Geolocation success flow
- Geolocation error flow
Test Coverage Results
InlineEditHistory:
Metric Coverage Statements 100% Branches 100% Functions 100% Lines 100%
LocationPicker:
Metric Coverage Statements 100% Branches 100% Functions 100% Lines 100%
Test Summary
Component Tests Added
InlineEditHistory 5
LocationPicker 5
Total 10 tests
Type of Change
-
Bug fix -
Feature development -
Breaking change -
Documentation update -
UI/UX improvement -
Refactor -
Performance improvement -
Test update -
Configuration change -
Security fix
Testing Done
Testing performed:
- Unit tests added
- Component interaction testing completed
- Async state testing completed
- Error scenarios validated
- Defensive paths validated
Test Quality:
✓ No skipped tests
✓ No fake assertions
✓ No coverage bypasses
✓ All meaningful branches covered
✓ Error scenarios tested
✓ Edge cases tested
Code Quality Checklist
Code Standards:
✓ Code follows project conventions
✓ No unnecessary production changes
✓ Proper TypeScript typing maintained
✓ Formatting remains consistent
React Best Practices:
✓ Proper component structure maintained
✓ Hooks behavior preserved
✓ Runtime behavior unchanged
✓ Event handling verified
Testing Standards:
✓ Behavior-focused testing
✓ Proper mocking strategy
✓ Edge cases covered
✓ External dependencies isolated
✓ No test anti-patterns
Notes
- 10 total tests added
- No breaking changes introduced
- Production behavior preserved
- Minimal cleanup done for unreachable code
- Improves maintainability
- Provides stronger regression protection
- Compatible with existing test infrastructure
Closes #250 (closed)
