5.8 KiB
5.8 KiB
Agent 2: Search Debounce Test Plan
Manual Testing Steps
Test 1: Basic Debounce
- Open any document in NaviDocs
- Type "engine" in search box
- Expected: See loading spinner appear after typing stops
- Expected: Search executes 300ms after last keystroke
- Expected: Results appear highlighted in document
Test 2: Cancellation on New Input
- Type "eng"
- Wait 200ms (before search triggers)
- Continue typing "ine"
- Expected: Previous pending search is cancelled
- Expected: New 300ms timer starts
- Expected: Only one search executes (for "engine")
Test 3: Minimum Query Length
- Type "e" (1 character)
- Expected: No search executes
- Expected: No loading spinner
- Type "n" (now "en", 2 characters)
- Expected: Search triggers after 300ms
- Expected: Results appear
Test 4: Clear Search
- Type "engine" and wait for results
- Click the X (clear) button
- Expected: Input clears immediately
- Expected: Results clear immediately
- Expected: No highlights remain
Test 5: Backspace to < 2 Characters
- Type "engine" and wait for results
- Backspace to "en"
- Expected: New search executes after 300ms
- Backspace to "e"
- Expected: Results clear immediately
- Expected: No search executes
Test 6: Loading Indicator
- Type "engine"
- Expected: Search button shows spinning icon
- Expected: Button is disabled during search
- Expected: Tooltip shows "Searching..."
- Wait for search to complete
- Expected: Search icon returns
- Expected: Tooltip shows "Search"
Test 7: Rapid Typing
- Type "abcdefghijklmnop" quickly without pausing
- Expected: Loading state appears
- Expected: Only ONE search executes (after typing stops)
- Expected: No multiple searches for intermediate strings
Test 8: Enter Key Override
- Type "eng" (3 characters)
- Press Enter immediately (don't wait for debounce)
- Expected: Search executes immediately
- Expected: Debounce timer is bypassed
Test 9: Multiple Cancel Operations
- Type "test"
- Before search executes, type "search"
- Before that executes, clear input
- Expected: No errors in console
- Expected: All abort controllers cleaned up properly
Test 10: Cross-Page Search Integration
- Type "engine" and wait for results
- Expected: Current page highlights appear
- Expected: Background cross-page search starts
- Expected: Total match count includes all pages
- Navigate to next/previous match
- Expected: Navigation works correctly
Automated Test Scenarios (for future implementation)
describe('Search Debounce', () => {
it('should debounce search by 300ms', async () => {
// Type characters
await typeText('engine')
// Verify search hasn't executed yet
expect(performSearch).not.toHaveBeenCalled()
// Wait 300ms
await delay(300)
// Verify search executed
expect(performSearch).toHaveBeenCalledTimes(1)
})
it('should cancel previous search on new input', async () => {
await typeText('eng')
await delay(200)
await typeText('ine')
// Only one search should execute
await delay(300)
expect(performSearch).toHaveBeenCalledTimes(1)
expect(performSearch).toHaveBeenCalledWith('engine')
})
it('should not search for queries < 2 chars', async () => {
await typeText('e')
await delay(300)
expect(performSearch).not.toHaveBeenCalled()
})
it('should show loading indicator', async () => {
await typeText('engine')
expect(isSearching.value).toBe(true)
expect(searchButton.querySelector('.animate-spin')).toBeInTheDocument()
await delay(300)
await waitFor(() => expect(isSearching.value).toBe(false))
})
})
Performance Verification
Metrics to Check
- Debounce delay: Should be exactly 300ms
- Search cancellation: Previous searches should abort properly
- Memory leaks: No timers or controllers left hanging
- UI responsiveness: No lag during typing
- Search execution: Only one search per debounce period
Console Checks
// Should see ONE log after typing "engine":
console.log("Found X matches across Y pages")
// Should NOT see:
console.error("Search error:")
console.warn("Failed to abort search")
Edge Cases
Concurrent Operations
- ✅ Typing while previous search is running
- ✅ Clearing input while search is running
- ✅ Navigating away while search is running
- ✅ Closing document while search is running
Boundary Conditions
- ✅ Empty string → No search
- ✅ 1 character → No search
- ✅ 2 characters → Search executes
- ✅ Very long query → Search executes normally
State Cleanup
- ✅ Timer cleared on new input
- ✅ Abort controller cleared on completion
- ✅ Loading state reset on error
- ✅ All state reset on clear
Success Criteria
✅ Search executes 300ms after user stops typing ✅ Loading indicator shows during search ✅ Previous searches cancel when new input arrives ✅ Results update in real-time ✅ Clearing input clears results immediately ✅ Queries < 2 characters don't trigger search ✅ No console errors ✅ No memory leaks ✅ Smooth user experience
Known Limitations
- Debounce timing: 300ms is hardcoded (could be configurable)
- Minimum query length: 2 characters is hardcoded (could be configurable)
- No search history: Previous searches not saved
- No smart cancellation: Cancels even if query prefix matches
Future Enhancements
- Make debounce delay configurable via settings
- Add search history dropdown
- Implement smart cancellation (don't cancel if new query starts with old)
- Add search suggestions/autocomplete
- Persist search state across page navigation
- Add keyboard shortcuts (Cmd+G for next match)
- Add search within results filtering