This document outlines the comprehensive test suite for the Mux Protocol frontend network badge components and related wallet UI components. The tests ensure robust behavior, proper styling, accessibility compliance, and graceful handling of edge cases.
Rendering Tests
- Verifies correct label display for testnet and mainnet networks
- Ensures component renders as a semantic span element
- Validates proper DOM structure
Styling Tests
- Validates network-specific color schemes (testnet: amber, mainnet: blue)
- Verifies dark mode styles are applied correctly
- Confirms outline variant styles are present
- Tests hover state styles
Custom className Tests
- Ensures custom classes merge with default styles
- Validates style override capability
- Tests multiple custom class handling
Props Validation Tests
- Confirms all valid network types are accepted
- Validates optional className prop handling
Accessibility Tests
- Verifies semantic HTML structure with
data-slot="badge"attribute - Ensures text content is visible and readable
- Validates text contrast with color combinations
Edge Cases
- Rapid re-renders with network switching
- Dynamic className changes
- Component lifecycle stability
Integration Tests
- Validates Badge component integration
- Confirms outline variant application
- Tests inherited base styles from Badge component
Rendering Tests
- Verifies correct status labels (Active, Pending, Inactive)
- Validates dot indicator rendering
- Ensures proper component structure
Styling Tests
- Status-specific color schemes:
- Active: Green (bg-green-50, text-green-700)
- Pending: Yellow (bg-yellow-50, text-yellow-700)
- Inactive: Zinc (bg-zinc-100, text-zinc-600)
- Dark mode styles for each status
- Pulse animation for pending status
Dot Indicator Tests
- Validates correct dot colors per status
- Confirms pulse animation on pending status
- Tests dot dimensions (h-2 w-2)
Custom className Tests
- Style merging and override capabilities
- Multiple class handling
Props Validation Tests
- All valid status types acceptance
- Optional className prop handling
Accessibility Tests
- Semantic structure validation
- Text readability and visibility
- Text contrast verification
Edge Cases
- Rapid status changes
- Status switching with style updates
- Dynamic className changes
Integration Tests
- Badge component integration
- Dot and text display together
- Inherited Badge base styles
Rendering Tests
- Table structure validation
- Header rendering
- Wallet row rendering
NetworkBadge Integration Tests
- Network badge display for each wallet
- Correct styling application (mainnet/testnet)
- Multiple network handling
StatusIndicator Integration Tests
- Status indicator display
- Correct styling per status
- Multiple status handling
Empty State Tests
- Proper rendering with no wallets
- Header-only table structure
Data Display Tests
- Balance display and formatting
- Missing balance handling (dash display)
- Address truncation
Responsive Design Tests
- Column visibility at different breakpoints
- Responsive class application (sm:, md:, lg:)
Edge Cases
- Single wallet rendering
- Multiple wallets with same network
- Multiple wallets with same status
- Missing optional fields
- Minimal wallet data
Accessibility Tests
- Table semantic structure
- Proper row and cell structure
- Header and body organization
Styling Tests
- Container styles (rounded-xl, border, bg-white)
- Dark mode container styles
- Header row styles
pnpm installpnpm testpnpm test:watchpnpm test:coverage- Test Environment: jsdom (for DOM testing)
- Setup File: jest.setup.ts (imports @testing-library/jest-dom)
- Module Mapper: Path alias support (@/* → src/*)
- Coverage Collection: Excludes app directory, .d.ts files, and story files
- Imports @testing-library/jest-dom for extended matchers
- Enables DOM testing utilities
Added Features:
- Graceful handling of invalid network values (defaults to mainnet)
- Comprehensive JSDoc documentation
- Input validation with fallback behavior
Code:
// Validate network value and default to mainnet if invalid
const validNetwork: WalletNetwork = (
Object.keys(networkStyles) as WalletNetwork[]
).includes(network)
? network
: "mainnet";Added Features:
- Graceful handling of invalid status values (defaults to inactive)
- Comprehensive JSDoc documentation
- Input validation with fallback behavior
Code:
// Validate status value and default to inactive if invalid
const validStatus: WalletStatus = (
Object.keys(statusStyles) as WalletStatus[]
).includes(status)
? status
: "inactive";- Total Test Suites: 3
- Total Test Cases: 80+
- Coverage Areas:
- Component rendering
- Styling and theming
- Props validation
- Accessibility
- Edge cases
- Integration scenarios
✅ Behavior is covered by tests
- 80+ test cases covering all component behaviors
- Unit tests for individual components
- Integration tests for component interactions
- Edge case handling tests
✅ No regressions in related flows
- WalletTable integration tests ensure NetworkBadge and StatusIndicator work correctly together
- Mock data tests validate component behavior with realistic data
- Responsive design tests ensure layout stability
✅ Graceful handling of stale, disconnected, or invalid states
- NetworkBadge validates network values and defaults to mainnet
- StatusIndicator validates status values and defaults to inactive
- WalletTable handles missing optional fields (balance, lastActivity)
- Empty state handling for zero wallets
✅ Follows existing patterns
- Uses Testing Library for React component testing
- Follows Jest conventions
- Matches project's TypeScript strict mode
- Integrates with existing Biome linting configuration
✅ Documented where APIs change
- JSDoc comments added to NetworkBadge and StatusIndicator
- TEST_DOCUMENTATION.md provides comprehensive test documentation
- Component enhancements documented with code examples
Add to your CI pipeline:
pnpm install
pnpm lint:fix
pnpm test --coverageTests can be integrated with Husky pre-commit hooks:
{
"husky": {
"hooks": {
"pre-commit": "lint-staged && pnpm test"
}
}
}- Run tests before committing:
pnpm test - Check coverage:
pnpm test:coverage - Watch mode for development:
pnpm test:watch - Keep tests focused: Each test validates one behavior
- Use descriptive test names: Clearly state what is being tested
- Mock external dependencies: useCopyToClipboard is mocked in WalletTable tests
- Add visual regression tests with Percy or similar
- Add E2E tests with Playwright or Cypress
- Add performance benchmarks
- Add snapshot tests for component output
- Expand mock data scenarios
- Ensure dependencies are installed:
pnpm install - Clear Jest cache:
pnpm test --clearCache - Check Node version compatibility (Node 18+)
- Verify path aliases in tsconfig.json
- Check jest.config.ts moduleNameMapper configuration
- Ensure all imports use @/* alias format
- Verify Tailwind CSS classes are correct
- Check that class-variance-authority is properly installed
- Ensure dark mode classes are properly formatted