Skip to content

Commit c361c51

Browse files
committed
chore(docs): alter claude command
1 parent e65bf20 commit c361c51

File tree

1 file changed

+112
-16
lines changed

1 file changed

+112
-16
lines changed

.claude/commands/create-eng-docs.md

Lines changed: 112 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ Based on component type and features:
141141
- [ ] Form integration (field patterns only)
142142
- [ ] API reference (required)
143143
- [ ] Common patterns (recommended)
144-
- [ ] Testing your implementation (required)
144+
- [ ] Testing your implementation (required - now auto-generated from .docs.spec.tsx)
145145
- [ ] Resources (required)
146146

147147
### Example Generation Strategy
@@ -222,12 +222,14 @@ Once confirmed, create the documentation file:
222222
> is good practice to add a **persistent**, **unique** id to the
223223
> component:
224224
- **Testing**:
225-
- **Mandatory**: Start with this exact disclaimer:
225+
- **NEW APPROACH**: Testing examples are now auto-generated from `.docs.spec.tsx` files
226+
- **Mandatory**: Include this text before the injection token:
226227
> These examples demonstrate how to test your implementation when using
227228
> [Component] in your application. The component's internal functionality
228229
> is already tested by Nimbus - these patterns help you verify your
229230
> integration and application-specific logic.
230-
- Provide realistic test examples (Rendering, Interaction, etc.)
231+
- Add injection token: `{{docs-tests: {component-name}.docs.spec.tsx}}`
232+
- Create companion `.docs.spec.tsx` file with test sections (see Step 6.1)
231233
- **Resources**: Link to Storybook (use "link-tbd" placeholder)
232234

233235
7. **Remove all HTML comments**: Clean up template guidance comments
@@ -241,6 +243,82 @@ Once confirmed, create the documentation file:
241243

242244
9. **Write the file** using the Write tool
243245

246+
### **Step 6.1: Create Documentation Test File**
247+
248+
**IMPORTANT**: After creating the `.dev.mdx` file, create the companion `.docs.spec.tsx` test file.
249+
250+
1. **Create test file**: `{component-name}.docs.spec.tsx` in same directory as component
251+
252+
2. **File structure**:
253+
```typescript
254+
import { describe, it, expect, vi } from 'vitest';
255+
import { render, screen } from '@testing-library/react';
256+
import userEvent from '@testing-library/user-event';
257+
import { ComponentName, NimbusProvider } from '@commercetools/nimbus';
258+
259+
/**
260+
* @docs-section basic-rendering
261+
* @docs-title Basic Rendering Tests
262+
* @docs-description Verify the component renders with expected elements
263+
* @docs-order 1
264+
*/
265+
describe('ComponentName - Basic rendering', () => {
266+
it('renders component', () => {
267+
render(
268+
<NimbusProvider>
269+
<ComponentName />
270+
</NimbusProvider>
271+
);
272+
273+
expect(screen.getByRole('...')).toBeInTheDocument();
274+
});
275+
});
276+
277+
/**
278+
* @docs-section interactions
279+
* @docs-title Interaction Tests
280+
* @docs-description Test user interactions with the component
281+
* @docs-order 2
282+
*/
283+
describe('ComponentName - Interactions', () => {
284+
it('handles user interaction', async () => {
285+
const user = userEvent.setup();
286+
render(
287+
<NimbusProvider>
288+
<ComponentName />
289+
</NimbusProvider>
290+
);
291+
292+
// Test interactions
293+
});
294+
});
295+
```
296+
297+
3. **JSDoc tags required**:
298+
- `@docs-section` - Unique ID for section
299+
- `@docs-title` - Display title
300+
- `@docs-description` - Brief description
301+
- `@docs-order` - Sort order (0 for setup, 1+ for tests)
302+
303+
4. **Test patterns to include** (based on component features):
304+
- Basic rendering (always)
305+
- Interactions (if interactive)
306+
- Controlled mode (if supports value/onChange)
307+
- States (disabled, invalid, readonly, required - if component has these props)
308+
- Component-specific features
309+
310+
5. **Critical rules**:
311+
- ✅ Every `render()` must wrap with `<NimbusProvider>`
312+
- ✅ Import NimbusProvider from `@commercetools/nimbus`
313+
- ✅ Use `vi.fn()` for mocks (not `jest.fn()`)
314+
- ✅ Use `userEvent.setup()` for interactions
315+
- ✅ Base test names on component features, not generic patterns
316+
317+
6. **Verify tests**:
318+
```bash
319+
pnpm test:unit {component-name}.docs.spec.tsx
320+
```
321+
244322
### **Step 7: Validate Documentation**
245323

246324
After generating the file, run validation checks:
@@ -277,7 +355,9 @@ After generating the file, run validation checks:
277355
- [ ] Examples are realistic and functional
278356
- [ ] TypeScript types are correct
279357
- [ ] Accessibility requirements documented
280-
- [ ] Testing examples provided
358+
- [ ] Testing section has `{{docs-tests:}}` injection token
359+
- [ ] Companion `.docs.spec.tsx` file created with test sections
360+
- [ ] Tests pass when run with `pnpm test:unit`
281361

282362
### Structure Checklist
283363

@@ -290,12 +370,15 @@ After generating the file, run validation checks:
290370
### Code Example Checklist
291371

292372
- [ ] All interactive examples use `jsx-live-dev`
293-
- [ ] All type/test examples use `tsx`
373+
- [ ] All type examples use `tsx`
294374
- [ ] Examples follow `const App = () => { }` pattern
295375
- [ ] State declarations use prop type inference pattern
296376
- [ ] Controlled examples include state display with Text component
297-
- [ ] Test examples use `userEvent.setup()` pattern
298-
- [ ] Portal/popover tests use `waitFor` and document queries
377+
- [ ] Test examples in `.docs.spec.tsx` file (not in MDX)
378+
- [ ] Tests wrap every `render()` with `<NimbusProvider>`
379+
- [ ] Tests use `vi.fn()` for mocks (not `jest.fn()`)
380+
- [ ] Tests use `userEvent.setup()` for interactions
381+
- [ ] Portal/popover tests use `waitFor` with document queries
299382

300383
### Link Checklist
301384

@@ -315,33 +398,46 @@ Provide a final summary:
315398
````markdown
316399
## Documentation Created
317400

318-
**Component**: {ComponentName} **Type**: [Base Component / Field Pattern]
319-
**File**: {full-path-to-file} **Size**: {file size in lines}
401+
**Component**: {ComponentName}
402+
**Type**: [Base Component / Field Pattern]
403+
**Files Created**:
404+
- `.dev.mdx`: {full-path-to-dev-mdx}
405+
- `.docs.spec.tsx`: {full-path-to-docs-spec}
320406

321407
### Sections Included
322408

323-
- [List all sections included]
409+
- [List all sections included in .dev.mdx]
410+
411+
### Test Sections Created
412+
413+
- [List all test sections in .docs.spec.tsx with @docs-section IDs]
324414

325415
### Key Features Documented
326416

327417
- [List 3-5 main features]
328418

329419
### Code Examples
330420

331-
- Total interactive examples: X
332-
- Total test examples: Y
421+
- Total interactive examples (jsx-live-dev): X
422+
- Total test sections (in .docs.spec.tsx): Y
423+
- Total test cases: Z
333424

334425
### Next Steps
335426

336427
1. Review the generated documentation
337-
2. Test all interactive examples in the docs site
338-
3. Update the Storybook link once available
339-
4. Add any component-specific advanced patterns
340-
5. Review with the team before publishing
428+
2. Run tests: `pnpm test:unit {component-name}.docs.spec.tsx`
429+
3. Build docs: `pnpm build:docs`
430+
4. Test all interactive examples in the docs site
431+
5. Update the Storybook link once available
432+
6. Add any component-specific advanced patterns
433+
7. Review with the team before publishing
341434

342435
### Useful Commands
343436

344437
```bash
438+
# Run documentation tests
439+
pnpm test:unit {component-name}.docs.spec.tsx
440+
345441
# Start docs site to preview
346442
pnpm start:docs
347443

0 commit comments

Comments
 (0)