mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-23 02:31:08 -05:00
120 lines
2.7 KiB
Markdown
120 lines
2.7 KiB
Markdown
# Park Search Tests
|
|
|
|
## Overview
|
|
|
|
Test suite for the park search functionality including:
|
|
- Autocomplete widget integration
|
|
- Search form validation
|
|
- Filter integration
|
|
- HTMX interaction
|
|
- View mode persistence
|
|
|
|
## Running Tests
|
|
|
|
```bash
|
|
# Run all park tests
|
|
uv run pytest parks/tests/
|
|
|
|
# Run specific search tests
|
|
uv run pytest parks/tests/test_search.py
|
|
|
|
# Run with coverage
|
|
uv run pytest --cov=parks parks/tests/
|
|
```
|
|
|
|
## Test Coverage
|
|
|
|
### Search Functionality Tests
|
|
- `test_autocomplete_results`: Validates real-time suggestion filtering
|
|
- `test_search_form_valid`: Ensures form validation works
|
|
- `test_autocomplete_class`: Verifies autocomplete configuration
|
|
- `test_search_with_filters`: Tests filter integration
|
|
|
|
### Integration Tests
|
|
- `test_empty_search`: Tests default behavior
|
|
- `test_partial_match_search`: Validates partial text matching
|
|
- `test_htmx_request_handling`: Ensures HTMX compatibility
|
|
- `test_view_mode_persistence`: Verifies view state preservation
|
|
|
|
### Performance Tests
|
|
- `test_suggestion_limit`: Verifies 8-item limit on suggestions
|
|
- `test_search_debounce`: Confirms proper debounce headers
|
|
|
|
### Frontend Integration
|
|
- HTMX partial updates
|
|
- Alpine.js state management
|
|
- Loading indicators
|
|
- View mode persistence
|
|
- Keyboard navigation
|
|
|
|
### Test Commands
|
|
```bash
|
|
# Run all park tests
|
|
uv run pytest parks/tests/
|
|
|
|
# Run search tests specifically
|
|
uv run pytest parks/tests/test_search.py
|
|
|
|
# Run with coverage
|
|
uv run pytest --cov=parks parks/tests/
|
|
```
|
|
|
|
### Coverage Areas
|
|
1. Search Functionality:
|
|
- Suggestion generation
|
|
- Result filtering
|
|
- Partial matching
|
|
- Empty state handling
|
|
|
|
2. UI Integration:
|
|
- HTMX requests
|
|
- View mode switching
|
|
- Loading states
|
|
- Error handling
|
|
|
|
3. Performance:
|
|
- Result limiting
|
|
- Debouncing
|
|
- Query optimization
|
|
|
|
4. Accessibility:
|
|
- ARIA attributes
|
|
- Keyboard controls
|
|
- Screen reader support
|
|
|
|
## Configuration
|
|
|
|
Tests use pytest-django and require:
|
|
- PostgreSQL database
|
|
- HTMX middleware
|
|
- Autocomplete app configuration
|
|
|
|
## Fixtures
|
|
|
|
The test suite uses standard Django test fixtures. No additional fixtures required.
|
|
|
|
## Common Issues
|
|
|
|
1. Database Errors
|
|
- Ensure PostGIS extensions are installed
|
|
- Verify database permissions
|
|
|
|
2. HTMX Tests
|
|
- Use `HTTP_HX_REQUEST` header for HTMX requests
|
|
- Check response content for HTMX attributes
|
|
|
|
## Adding New Tests
|
|
|
|
When adding tests, ensure:
|
|
1. Database isolation using `@pytest.mark.django_db`
|
|
2. Proper test naming following `test_*` convention
|
|
3. Clear test descriptions in docstrings
|
|
4. Coverage for both success and failure cases
|
|
5. HTMX interaction testing where applicable
|
|
|
|
## Future Improvements
|
|
|
|
- Add performance benchmarks
|
|
- Include accessibility tests
|
|
- Add Playwright e2e tests
|
|
- Implement geographic search tests |