Search Functionality Tests
This directory contains Playwright end-to-end tests for the search functionality in TinaDocs.
Overview
The search tests verify that the Pagefind-based search functionality works correctly across different scenarios:
- Basic search functionality
- Search result display
- Navigation to search results
- Mobile responsiveness
- Performance testing
- Error handling
Test Files
search.spec.ts- Comprehensive search tests with detailed scenariossearch-simplified.spec.ts- Simplified tests using helper utilitiesutils/search-helpers.ts- Helper functions for search testing
Running Tests
Local Development
-
Start the development server:
pnpm dev -
Run tests with UI (for debugging):
pnpm test:ui
Preview/Production Testing
-
Test against a specific URL:
PREVIEW_URL=https://your-preview-url.com pnpm test -
Run all tests:
pnpm test
Test Scenarios
Basic Functionality
- ✅ Search input field is visible
- ✅ Search returns results for existing content
- ✅ Search shows "No Llamas Found" for non-existent content
- ✅ Search clears when clicking outside
- ✅ Empty search input is handled gracefully
- ✅ Multiple rapid searches work correctly
Technical Verification
- ✅ Pagefind files are accessible (
/_next/static/pagefind/) - ✅ Search completes within reasonable time (< 3 seconds)
- ✅ Mobile viewport works correctly
Performance
- ✅ Search performance is measured and reported
GitHub Actions Integration
The tests are automatically run in GitHub Actions on:
- Pull Requests - Tests run against Vercel preview deployments
- Manual Workflow - Can test against any preview URL
Configuration
Environment Variables
BASE_URL- Base URL for testing (defaults tohttp://localhost:3000)PREVIEW_URL- Preview URL for testing
Playwright Configuration
See playwright.config.ts for:
- Browser configurations (Chrome)
- Test timeouts and retries
- Screenshot and video capture settings
- Report generation
Debugging
View Test Reports
After running tests, view the HTML report:
npx playwright show-report
Debug Individual Tests
- Add
test.only()to run a single test - Use
--debugflag for step-by-step debugging - Use
--headedto see the browser in action
Common Issues
-
Search not working locally:
- Ensure Pagefind index is generated:
pnpm build-local-pagefind - Check if
/_next/static/pagefind/files exist
- Ensure Pagefind index is generated:
-
Tests timing out:
- Increase timeout in
playwright.config.ts - Check if the server is running and accessible
- Increase timeout in
-
Search results not appearing:
- Verify search input selector matches the actual component
- Check if Pagefind files are being served correctly
Test Data
The tests use predefined search terms that should exist in your documentation:
const KNOWN_CONTENT = {
searchTerms: [
'TinaDocs',
'documentation',
'search',
'API',
'TinaCMS',
'deployment',
'theming',
'components'
]
};
Important: Update these terms based on your actual content to ensure tests pass reliably.
Contributing
When adding new search features:
- Add corresponding tests to
search.spec.ts - Update helper functions in
search-helpers.tsif needed - Update test data with relevant search terms
- Ensure tests pass locally before committing
Troubleshooting
Search Index Issues
If search isn't working, check:
-
Build process:
pnpm build-local-pagefind -
Pagefind files:
/_next/static/pagefind/pagefind.js/_next/static/pagefind/pagefind-index.json
-
Content indexing:
- Ensure content has
data-pagefind-bodyattributes - Check if content is being built correctly
- Ensure content has
Test Failures
Common test failure reasons:
- Selector changes - Update selectors in tests
- Content changes - Update test data with new content
- Timing issues - Increase wait times or add better wait conditions
- Environment issues - Check if server is running and accessible