# S04: Search Autocomplete & Suggestions — UAT

**Milestone:** M010
**Written:** 2026-03-31T06:40:26.076Z

## UAT: Search Autocomplete & Suggestions

### Preconditions
- Chrysopedia stack running on ub01 (docker compose up -d)
- Database populated with at least 5 technique pages, 3 creators, and techniques spanning multiple topic tags
- Web UI accessible at http://ub01:8096

### Test 1: Popular Suggestions on Home Page Focus
1. Navigate to http://ub01:8096 (Home page)
2. Click the search input field (it should auto-focus on load)
3. **Expected:** A dropdown appears below the search bar with a "Popular" header, showing 8-12 suggestion items. Each item displays text and a colored type badge (topic, technique, or creator).
4. Verify at least one item of each type (topic, technique, creator) is present.

### Test 2: Typeahead Search Results
1. On the Home page, type "comp" into the search bar
2. Wait ~300ms for debounce
3. **Expected:** The popular suggestions dropdown is replaced by search results showing techniques matching "comp" (e.g., compression-related techniques). Results show title, creator, and topic info.
4. Clear the search input
5. **Expected:** Popular suggestions reappear

### Test 3: Search Submit via Enter
1. Type "reverb" into the search bar on Home
2. Press Enter
3. **Expected:** Browser navigates to /search?q=reverb with search results displayed

### Test 4: Suggestion Click Navigation
1. Return to Home page
2. Focus the search input (empty) to show popular suggestions
3. Click on a technique suggestion item
4. **Expected:** The search input fills with the suggestion text and search is submitted — navigates to /search?q={suggestion text}

### Test 5: Autocomplete on SearchResults Page
1. Navigate to http://ub01:8096/search?q=mixing
2. **Expected:** SearchResults page loads with results for "mixing". The search bar at the top shows "mixing" as the current query.
3. Clear the search bar text and focus it
4. **Expected:** Popular suggestions dropdown appears, identical behavior to Home page

### Test 6: Escape / Outside Click Dismissal
1. On Home page, focus the empty search bar to show popular suggestions
2. Press Escape
3. **Expected:** Dropdown closes
4. Focus the search bar again (dropdown reappears)
5. Click anywhere outside the search bar and dropdown
6. **Expected:** Dropdown closes

### Test 7: API Endpoint Direct Check
1. Open http://ub01:8096/api/v1/search/suggestions in a browser or curl
2. **Expected:** JSON response with `{"suggestions": [...]}` where each item has `text` (string) and `type` ("topic", "technique", or "creator")
3. Verify no duplicate text values in the response
4. Verify the response contains between 0-12 items

### Test 8: Empty Database Graceful Handling
1. (If testable) With an empty database, hit the suggestions endpoint
2. **Expected:** Returns `{"suggestions": []}` — empty array, no 500 error

### Edge Cases
- **Rapid typing:** Type and delete rapidly in the search bar. Debounce should prevent excessive API calls; no UI glitches.
- **Very long query:** Type a 200+ character string. The search bar should accept it without overflow; API should handle it gracefully.
- **Network delay:** If the suggestions API is slow, the dropdown should not flash or show stale data from a previous query.
