# Run all SearchBar tests
npm test components/molecules/SearchBar/SearchBar.test.tsx
# Run with coverage report
npm test -- --coverage components/molecules/SearchBar/
# Watch mode (auto-rerun on changes)
npm test -- --watch components/molecules/SearchBar/SearchBar.test.tsxThe test suite includes 60+ test cases organized into 11 describe blocks:
-
Rendering (8 tests)
- Default and custom placeholders
- Icon rendering
- Accessibility attributes
- Custom styling
-
Input Value Management (5 tests)
- Value updates
- Initial values
- Clear button visibility
- Edge cases
-
Search Callback with Debounce (5 tests)
- Debounce timing
- Debounce cancellation
- Custom delays
- Search on clear
-
Clear Button Functionality (5 tests)
- Value clearing
- Callback invocation
- Focus management
- Button visibility
-
Keyboard Shortcuts (6 tests)
- Slash focus
- Modifier keys
- Disabling shortcuts
- Keyboard hint visibility
- Protection from other inputs
-
Focus State and Styling (4 tests)
- Focus ring styles
- Hover styles
- Border colors
-
Ref Forwarding (3 tests)
- Ref creation
- Direct manipulation
- Callback refs
-
Edge Cases (7 tests)
- Rapid input changes
- Special characters
- Long input (1000+ chars)
- Unmount cleanup
- Empty values
- Undefined props
- Whitespace and numeric input
-
Accessibility (5 tests)
- ARIA labels
- Input type
- Keyboard navigation
- Button attributes
-
Integration (3 tests)
- Form submission
- All props together
- Multiple instances
-
Default Props (4 tests)
- Debounce delay
- Clear button visibility
- Search icon visibility
- Slash shortcut enablement
- Component renders without errors in browser
- Search icon appears on the left
- Clear (×) button appears only when input has value
- Focus ring is clearly visible (2px green ring)
- Placeholder text is visible and centered
- Dark mode styling works correctly
- Responsive design works on mobile (< 640px)
- Responsive design works on tablet (640px - 1024px)
- Responsive design works on desktop (> 1024px)
- Can type in the search input
- Debounce delays the search callback (default 300ms)
- Clear button appears after typing
- Clicking clear button empties the input
- Clear button disappears after input is empty
- Focus is restored to input after clearing
- onSearch callback is called with current value
- onClear callback is called when clearing
- Tab key navigates to search input
- Tab key navigates from input to clear button (when visible)
- Shift+Tab navigates backwards
- Space/Enter activates clear button
-
/key focuses the search input -
Ctrl+/does NOT focus the search input -
Cmd+/(Mac) does NOT focus the search input - Alt+/ does NOT focus the search input
- Shift+/ does NOT focus the search input
- Keyboard hint (
/) shows when empty - Keyboard hint disappears when value is present
- Screen reader announces "Search input" label correctly
- Input type is announced as "Edit text"
- Placeholder text is available to screen reader
- Clear button has label "Clear search input"
- Clear button is announced as a button
- Search icon is skipped (aria-hidden)
- Icons don't create noise in screen reader
- All functionality accessible via keyboard
- No keyboard traps
- Focus order is logical: Input → Clear button → Next element
- Focus indicator is visible at all times
- Focus ring has sufficient contrast (WCAG AA)
- Text has sufficient contrast (WCAG AA)
- Component works at 200% zoom
- Component works with high contrast mode
- Font size adjustable (no fixed px on text)
- Appears in top navigation bar
- Styling matches the green header background
- Search functionality works in context
- Doesn't interfere with other header elements
- Responsive adjustments work in context
- Works with custom placeholder
- Works with initial value
- Works with debounce delay of 100ms
- Works with debounce delay of 500ms
- Works with slash shortcut disabled
- Works with clear button hidden
- Works with search icon hidden
- Works with different max-width options
- No memory leaks (check DevTools heap snapshots)
- Debounce prevents excessive function calls
- Cleanup on unmount is effective
- Multiple instances don't cause slowdown
Test in the following browsers:
- Chrome (latest)
- Firefox (latest)
- Safari (latest)
- Edge (latest)
npm run storybook
# Navigate to Components > SearchBar in the sidebarVerify each story:
- Default - Basic search bar
- AssetSearch - Custom placeholder
- WithInitialValue - Pre-filled value
- SmallWidth - max-w-sm constraint
- LargeWidth - max-w-lg constraint
- FullWidth - Full width
- NoClearButton - Without clear button
- NoSearchIcon - Without search icon
- Minimal - No icons
- NoSlashShortcut - Slash shortcut disabled
- FastDebounce - 100ms debounce
- SlowDebounce - 500ms debounce
- CustomStyling - Additional CSS classes
- Controlled - Controlled component pattern
- InForm - Inside form element
- Multiple - Multiple instances
- Accessibility - A11y features demo
Each story should:
- Render without errors
- Be interactive
- Show correct styling
- Include documentation
When running tests, expect output like:
✓ SearchBar Component (60 tests)
✓ Rendering (8 tests)
✓ should render the search input with default placeholder
✓ should render with custom placeholder
... (6 more)
✓ Input Value Management (5 tests)
... (5 tests)
✓ Search Callback with Debounce (5 tests)
... (5 tests)
... (remaining describe blocks)
Test Files 1 passed (1)
Tests 60 passed (60)
Expected coverage metrics:
- Statements: 95%+
- Branches: 95%+
- Functions: 95%+
- Lines: 95%+
Run with coverage:
npm test -- --coverage components/molecules/SearchBar/None currently documented. Component should work in all modern browsers.
Issue: Clear button not appearing
- Check if input has a value
- Check
showClearButtonprop is true - Clear browser cache
Issue: Slash shortcut not working
- Check if user is already in another input
- Check if
enableSlashShortcutprop is true - Check browser console for errors
Issue: Styling looks different
- Check Tailwind CSS is loaded
- Check CSS variable
--New-outlineis defined - Clear browser cache
Add this to component for debugging:
useEffect(() => {
console.log('SearchBar value:', value);
console.log('SearchBar props:', {
showClearButton,
showSearchIcon,
enableSlashShortcut
});
}, [value, showClearButton, showSearchIcon, enableSlashShortcut]);After deployment, monitor:
- Component Load Time: Should be < 50ms
- Search Callback Frequency: Should match debounce delay
- Memory Usage: No memory leaks on repeated mount/unmount
- Re-renders: Only re-render on value change or prop change
The test suite should be integrated into CI/CD:
# Example GitHub Actions
- name: Run SearchBar Tests
run: npm test components/molecules/SearchBar/SearchBar.test.tsx
- name: Generate Coverage
run: npm test -- --coverage components/molecules/SearchBar/If issues are discovered:
-
Tests are failing:
- Check test file syntax
- Ensure all dependencies are installed
- Clear npm cache:
npm cache clean --force
-
Component is broken:
- Revert to previous SearchBar implementation
- Keep both components temporarily
- Plan gradual migration
-
Styling issues:
- Check CSS variable values
- Verify Tailwind CSS is loaded
- Check for CSS conflicts
Before considering the consolidation complete:
- All 60+ tests pass
- Coverage >= 95%
- All Storybook stories render
- Manual testing complete
- Accessibility testing complete
- Browser compatibility verified
- TopNav integration works
- Documentation complete
- No TypeScript errors
- No ESLint errors
- Performance acceptable
- Ready for merge and deployment
- Run full test suite
- Review test coverage report
- Manual verification in browser
- Deploy to staging
- Final QA testing
- Merge to main branch
- Monitor in production