-
-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Open
Labels
Description
Feature description
RFC: Add comprehensive tests for Command component
🎯 Motivation
The Command component is one of the most widely used components in shadcn/ui, powering command palettes and search interfaces across thousands of projects. However, it currently lacks comprehensive test coverage.
This proposal aims to add a complete test suite to:
- Ensure component reliability across different use cases
- Prevent regressions during future updates
- Serve as documentation for component behavior
- Establish testing patterns for other components
📋 Proposed Test Coverage
Rendering & Structure (8 tests)
- Render Command component
- Render with custom className
- Render children correctly
- Render CommandInput with search icon
- Render CommandList with multiple items
- Render CommandEmpty state
- Render CommandGroup with heading
- Render CommandSeparator
User Interactions (12 tests)
- Accept text input in CommandInput
- Apply custom placeholder
- Handle click events on CommandItem
- Call onSelect callback
- Handle disabled items
- CommandDialog opens when open=true
- CommandDialog closes when open=false
- Call onOpenChange on dialog state change
- Filter items based on search input (cmdk behavior)
- Navigate with keyboard (handled by cmdk)
- Display shortcut hints
- Support multiple command groups
Edge Cases (8 tests)
- Empty command list
- Special characters in items
- Very long item text
- Large number of items (100+)
- Command without input
- Command with only empty state
- Multiple items with same text
- Nested groups
Complex Scenarios (4 tests)
- Complete command palette structure
- Multiple groups with separators
- Items with shortcuts
- Search filtering integration
Component Sub-testing (16 tests)
- CommandInput (4 tests)
- CommandList (2 tests)
- CommandItem (4 tests)
- CommandEmpty (2 tests)
- CommandGroup (3 tests)
- CommandSeparator (2 tests)
- CommandShortcut (2 tests)
- CommandDialog (3 tests)
Total: 48 test cases
🛠️ Implementation Details
Testing Stack
- Framework: Vitest (already used in the project)
- Testing Library: @testing-library/react + @testing-library/user-event
- Utilities: @testing-library/jest-dom for enhanced matchers
Test File Location
apps/www/registry/default/ui/command.test.tsx
Dependencies Required
{
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.5.0",
"@testing-library/jest-dom": "^6.1.0"
}🧠 Generation & Review Process
- Initial generation: Used TestMind (AI-powered testing tool) to analyze component structure and generate comprehensive test scaffolding
- Manual review: Reviewed every test case for:
- Accuracy and completeness
- Alignment with shadcn/ui code style
- Real-world usage patterns
- Optimization:
- Adjusted test data to match realistic scenarios
- Ensured proper async handling
- Added edge cases not covered by initial generation
- Validation: Structured tests for maintainability and clarity
✅ Benefits
For Users
- Confidence: Tests ensure component works as expected
- Documentation: Tests serve as usage examples
- Regression Prevention: Catch breaking changes early
For Maintainers
- Safety: Refactor with confidence
- Quality: Catch bugs before release
- Patterns: Establish testing standards for other components
For Contributors
- Guidance: Clear examples of how to test components
- Standards: Template for adding tests to other components
📊 Expected Outcomes
- ✅ 48 comprehensive test cases
- ✅ Coverage of all component variants
- ✅ Edge case handling validated
- ✅ CI/CD integration ready
- ✅ Zero breaking changes to existing code
🤝 Seeking Feedback
Before submitting a PR, I'd love to get feedback on:
- Scope: Is this level of testing appropriate? Should I add/remove any scenarios?
- Approach: Are there specific testing patterns shadcn/ui prefers?
- Dependencies: Are the chosen testing libraries acceptable?
- Structure: Any preferences for test organization?
🚀 Next Steps
If this proposal is accepted:
- Submit PR with test suite
- Address review feedback
- Potentially create tests for other complex components (Combobox, Calendar, etc.)
- Document testing best practices for contributors
Note: This contribution is created with AI assistance (TestMind) but includes thorough human review and optimization to ensure quality and alignment with project standards.
cc @shadcn
Affected component/components
Command
Additional Context
Additional details here...
Before submitting
- I've made research efforts and searched the documentation
- I've searched for existing issues and PRs