Skip to content

Commit 9f64f6e

Browse files
committed
chore(docs): alter claude command
1 parent 706e6f6 commit 9f64f6e

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
@@ -138,7 +138,7 @@ Based on component type and features:
138138
- [ ] Form integration (field patterns only)
139139
- [ ] API reference (required)
140140
- [ ] Common patterns (recommended)
141-
- [ ] Testing your implementation (required)
141+
- [ ] Testing your implementation (required - now auto-generated from .docs.spec.tsx)
142142
- [ ] Resources (required)
143143

144144
### Example Generation Strategy
@@ -215,12 +215,14 @@ Once confirmed, create the documentation file:
215215
> is good practice to add a **persistent**, **unique** id to the
216216
> component:
217217
- **Testing**:
218-
- **Mandatory**: Start with this exact disclaimer:
218+
- **NEW APPROACH**: Testing examples are now auto-generated from `.docs.spec.tsx` files
219+
- **Mandatory**: Include this text before the injection token:
219220
> These examples demonstrate how to test your implementation when using
220221
> [Component] in your application. The component's internal functionality
221222
> is already tested by Nimbus - these patterns help you verify your
222223
> integration and application-specific logic.
223-
- Provide realistic test examples (Rendering, Interaction, etc.)
224+
- Add injection token: `{{docs-tests: {component-name}.docs.spec.tsx}}`
225+
- Create companion `.docs.spec.tsx` file with test sections (see Step 6.1)
224226
- **Resources**:
225227
- Link to Storybook (use "link-tbd" placeholder)
226228
- **Internal component links must start with '/'** (e.g.,
@@ -237,6 +239,82 @@ Once confirmed, create the documentation file:
237239

238240
9. **Write the file** using the Write tool
239241

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

242320
After generating the file, run validation checks:
@@ -273,7 +351,9 @@ After generating the file, run validation checks:
273351
- [ ] Examples are realistic and functional
274352
- [ ] TypeScript types are correct
275353
- [ ] Accessibility requirements documented
276-
- [ ] Testing examples provided
354+
- [ ] Testing section has `{{docs-tests:}}` injection token
355+
- [ ] Companion `.docs.spec.tsx` file created with test sections
356+
- [ ] Tests pass when run with `pnpm test:unit`
277357

278358
### Structure Checklist
279359

@@ -286,12 +366,15 @@ After generating the file, run validation checks:
286366
### Code Example Checklist
287367

288368
- [ ] All interactive examples use `jsx-live-dev`
289-
- [ ] All type/test examples use `tsx`
369+
- [ ] All type examples use `tsx`
290370
- [ ] Examples follow `const App = () => { }` pattern
291371
- [ ] State declarations use prop type inference pattern
292372
- [ ] Controlled examples include state display with Text component
293-
- [ ] Test examples use `userEvent.setup()` pattern
294-
- [ ] Portal/popover tests use `waitFor` and document queries
373+
- [ ] Test examples in `.docs.spec.tsx` file (not in MDX)
374+
- [ ] Tests wrap every `render()` with `<NimbusProvider>`
375+
- [ ] Tests use `vi.fn()` for mocks (not `jest.fn()`)
376+
- [ ] Tests use `userEvent.setup()` for interactions
377+
- [ ] Portal/popover tests use `waitFor` with document queries
295378

296379
### Link Checklist
297380

@@ -312,33 +395,46 @@ Provide a final summary:
312395
````markdown
313396
## Documentation Created
314397

315-
**Component**: {ComponentName} **Type**: [Base Component / Field Pattern]
316-
**File**: {full-path-to-file} **Size**: {file size in lines}
398+
**Component**: {ComponentName}
399+
**Type**: [Base Component / Field Pattern]
400+
**Files Created**:
401+
- `.dev.mdx`: {full-path-to-dev-mdx}
402+
- `.docs.spec.tsx`: {full-path-to-docs-spec}
317403

318404
### Sections Included
319405

320-
- [List all sections included]
406+
- [List all sections included in .dev.mdx]
407+
408+
### Test Sections Created
409+
410+
- [List all test sections in .docs.spec.tsx with @docs-section IDs]
321411

322412
### Key Features Documented
323413

324414
- [List 3-5 main features]
325415

326416
### Code Examples
327417

328-
- Total interactive examples: X
329-
- Total test examples: Y
418+
- Total interactive examples (jsx-live-dev): X
419+
- Total test sections (in .docs.spec.tsx): Y
420+
- Total test cases: Z
330421

331422
### Next Steps
332423

333424
1. Review the generated documentation
334-
2. Test all interactive examples in the docs site
335-
3. Update the Storybook link once available
336-
4. Add any component-specific advanced patterns
337-
5. Review with the team before publishing
425+
2. Run tests: `pnpm test:unit {component-name}.docs.spec.tsx`
426+
3. Build docs: `pnpm build:docs`
427+
4. Test all interactive examples in the docs site
428+
5. Update the Storybook link once available
429+
6. Add any component-specific advanced patterns
430+
7. Review with the team before publishing
338431

339432
### Useful Commands
340433

341434
```bash
435+
# Run documentation tests
436+
pnpm test:unit {component-name}.docs.spec.tsx
437+
342438
# Start docs site to preview
343439
pnpm start:docs
344440

0 commit comments

Comments
 (0)