|
| 1 | +# Component Style Testing |
| 2 | + |
| 3 | +This directory contains automated testing scripts for verifying that ObjectUI components render with proper styles in the fumadocs documentation site. |
| 4 | + |
| 5 | +## Scripts |
| 6 | + |
| 7 | +### 1. `test-component-styles.js` (Node.js) |
| 8 | + |
| 9 | +A comprehensive automated test that: |
| 10 | +- Launches a headless browser |
| 11 | +- Navigates to all component documentation pages |
| 12 | +- Checks for proper CSS styling on components |
| 13 | +- Takes screenshots for visual verification |
| 14 | +- Reports errors and warnings |
| 15 | + |
| 16 | +**Usage:** |
| 17 | +```bash |
| 18 | +# Requires dev server to be running on http://localhost:3000 |
| 19 | +node scripts/test-component-styles.js |
| 20 | +``` |
| 21 | + |
| 22 | +**Features:** |
| 23 | +- ✅ Tests 15+ critical components |
| 24 | +- ✅ Validates background colors, borders, padding, etc. |
| 25 | +- ✅ Captures screenshots for manual review |
| 26 | +- ✅ Detects missing or invalid styles |
| 27 | +- ✅ Distinguishes between critical and non-critical failures |
| 28 | + |
| 29 | +### 2. `test-component-styles.sh` (Bash) |
| 30 | + |
| 31 | +A wrapper script that: |
| 32 | +- Automatically starts the dev/production server |
| 33 | +- Runs the Node.js test script |
| 34 | +- Cleans up the server after testing |
| 35 | + |
| 36 | +**Usage:** |
| 37 | +```bash |
| 38 | +# Test with dev server (default) |
| 39 | +./scripts/test-component-styles.sh dev |
| 40 | + |
| 41 | +# Test with production build |
| 42 | +./scripts/test-component-styles.sh build |
| 43 | +``` |
| 44 | + |
| 45 | +## Quick Start |
| 46 | + |
| 47 | +1. **Install dependencies:** |
| 48 | + ```bash |
| 49 | + pnpm install |
| 50 | + ``` |
| 51 | + |
| 52 | +2. **Run the tests:** |
| 53 | + ```bash |
| 54 | + # Option 1: Manual (requires server running) |
| 55 | + cd apps/site && pnpm dev & |
| 56 | + node scripts/test-component-styles.js |
| 57 | + |
| 58 | + # Option 2: Automatic |
| 59 | + ./scripts/test-component-styles.sh |
| 60 | + ``` |
| 61 | + |
| 62 | +3. **Check results:** |
| 63 | + - Console output shows pass/fail for each component |
| 64 | + - Screenshots saved to `/tmp/*.png` |
| 65 | + - Exit code 0 = all tests passed, 1 = critical failures |
| 66 | + |
| 67 | +## Adding New Components |
| 68 | + |
| 69 | +To test a new component, edit `test-component-styles.js`: |
| 70 | + |
| 71 | +```javascript |
| 72 | +const COMPONENT_PAGES = [ |
| 73 | + // Add your component |
| 74 | + { |
| 75 | + path: '/docs/components/category/your-component', |
| 76 | + name: 'Your Component', |
| 77 | + critical: true // Set to true if it's a critical component |
| 78 | + }, |
| 79 | + // ... |
| 80 | +]; |
| 81 | +``` |
| 82 | + |
| 83 | +## Common Issues |
| 84 | + |
| 85 | +### Calendar/Date Picker Styling |
| 86 | + |
| 87 | +If calendar components show styling issues: |
| 88 | + |
| 89 | +1. **Check CSS custom properties**: Ensure `global.css` includes all design tokens |
| 90 | +2. **Check Tailwind config**: Verify `tailwind.config.ts` maps CSS variables correctly |
| 91 | +3. **Check content paths**: Ensure Tailwind scans all component source files |
| 92 | +4. **Check for dynamic classes**: Some components use runtime-generated class names |
| 93 | + |
| 94 | +### Fixing Style Issues |
| 95 | + |
| 96 | +1. **Missing colors**: Add CSS custom property to `apps/site/app/global.css` |
| 97 | +2. **Missing mapping**: Add color mapping to `apps/site/tailwind.config.ts` |
| 98 | +3. **Classes not found**: Add path to `content` array in Tailwind config |
| 99 | +4. **Component-specific**: Check component UI source in `packages/components/src/ui/` |
| 100 | + |
| 101 | +## CI Integration |
| 102 | + |
| 103 | +Add to your CI pipeline: |
| 104 | + |
| 105 | +```yaml |
| 106 | +- name: Test Component Styles |
| 107 | + run: | |
| 108 | + pnpm build |
| 109 | + pnpm start & |
| 110 | + sleep 10 |
| 111 | + node scripts/test-component-styles.js |
| 112 | +``` |
| 113 | +
|
| 114 | +## Output Format |
| 115 | +
|
| 116 | +``` |
| 117 | +🚀 Starting Component Style Tests... |
| 118 | + |
| 119 | +Testing: Button (/docs/components/form/button) |
| 120 | +✅ PASSED - Button |
| 121 | + |
| 122 | +Testing: Calendar (/docs/components/data-display/calendar) |
| 123 | +❌ FAILED - Calendar (3 errors, 1 warnings) |
| 124 | + ⚠️ CRITICAL COMPONENT |
| 125 | + |
| 126 | +📊 TEST SUMMARY |
| 127 | +================================================================================ |
| 128 | + |
| 129 | +Total Tests: 15 |
| 130 | +Passed: 14 ✅ |
| 131 | +Failed: 1 ❌ |
| 132 | +Critical Failures: 1 ⚠️ |
| 133 | + |
| 134 | +Failed Components: |
| 135 | + |
| 136 | + ⚠️ Calendar: |
| 137 | + Path: /docs/components/data-display/calendar |
| 138 | + Errors: 3, Warnings: 1 |
| 139 | + Screenshot: /tmp/calendar.png |
| 140 | + - [ERROR] Missing or invalid background-color on button[class*="selected"] |
| 141 | + - [ERROR] Missing or invalid color on button[class*="selected"] |
| 142 | + - [ERROR] Missing or invalid border-color on [class*="border"] |
| 143 | +``` |
| 144 | +
|
| 145 | +## Troubleshooting |
| 146 | +
|
| 147 | +**Server not starting:** |
| 148 | +- Check if port 3000 is available |
| 149 | +- Ensure all dependencies are installed (`pnpm install`) |
| 150 | +- Try building first (`pnpm build`) |
| 151 | + |
| 152 | +**Tests timing out:** |
| 153 | +- Increase timeout in script (default: 30s) |
| 154 | +- Check for console errors in browser |
| 155 | +- Verify components are actually rendering |
| 156 | + |
| 157 | +**False positives:** |
| 158 | +- Some components may have intentionally transparent backgrounds |
| 159 | +- Adjust `STYLE_CHECKS` in the script to match expected behavior |
| 160 | +- Add component-specific validation rules |
| 161 | + |
| 162 | +## Maintenance |
| 163 | + |
| 164 | +Update the test script when: |
| 165 | +- Adding new components to the documentation |
| 166 | +- Changing component styling approach |
| 167 | +- Modifying Tailwind configuration |
| 168 | +- Updating design tokens |
| 169 | + |
| 170 | +Last updated: 2026-01-23 |
0 commit comments