A comprehensive test suite for the DraftReview React component using TDD (Test-Driven Development).
File: components/DraftReview.test.tsx
- 444 lines of code
- 41 test cases organized in 8 suites
- 100% failing (component doesn't exist yet)
This is the RED phase of TDD. Tests are written first, before the component implementation. The component (DraftReview.tsx) does not exist yet, so all tests correctly fail.
| Document | Purpose | Read When |
|---|---|---|
| QUICK_START.md | 1-minute overview | You want to get started fast |
| DRAFT_REVIEW_TEST_SUMMARY.txt | Test reference card | Looking up test details |
| DRAFT_REVIEW_IMPLEMENTATION_GUIDE.md | Step-by-step guide | Ready to implement the component |
| RED_PHASE_COMPLETE.md | Detailed summary | Need full context and background |
| DELIVERABLES.md | Project completion report | Comprehensive overview |
| README_DRAFTREVIEW.md | This file | Navigation and context |
See all the tests
cat components/DraftReview.test.tsxRun the tests
npm test -- components/DraftReview.test.tsxUnderstand what to build
→ Read: DRAFT_REVIEW_TEST_SUMMARY.txt
Implement the component
→ Read: DRAFT_REVIEW_IMPLEMENTATION_GUIDE.md
Get the big picture
→ Read: RED_PHASE_COMPLETE.md
Start right now
→ Read: QUICK_START.md
A React component that displays an email draft reply for user review before sending. Users can:
- View the original email
- Review the AI-generated draft reply
- Approve, reject, or edit the draft
- See confidence score and priority level
- Display original email (subject, sender, body)
- Display AI-generated draft content
- Show priority badge and confidence percentage
- Approve/Reject buttons
- Edit mode with save/cancel
- Loading and error states
- Accessibility compliant
<DraftReview
draft={{
id: 'draft-1',
originalEmail: { ... },
draftContent: 'Thank you for reaching out...',
priority: 'high',
confidence: 0.87,
status: 'pending'
}}
onApprove={(draftId) => { /* approve */ }}
onReject={(draftId) => { /* reject */ }}
onSave={(draftId, content) => { /* save */ }}
/>DraftReview Component
├── Rendering (10 tests)
│ └── Display email, draft, badges, buttons
├── Interactions (10 tests)
│ ├── Button Actions (3): approve, reject, edit
│ └── Edit Mode (7): textarea, save, cancel
├── Loading State (4 tests)
│ └── Show indicator, disable buttons
├── Error State (4 tests)
│ └── Show message, disable buttons
├── Edge Cases (8 tests)
│ └── Long content, extremes, empty data
├── Component Structure (3 tests)
│ └── Required data-testids
└── Accessibility (4 tests)
└── Semantic HTML, ARIA, roles
Total: 56 test cases (41 individual + combined)
touch components/DraftReview.tsxFollow DRAFT_REVIEW_IMPLEMENTATION_GUIDE.md:
- Basic rendering (tests 1-10)
- Buttons & handlers (tests 11-13)
- Edit mode (tests 14-20)
- Loading state (tests 21-24)
- Error state (tests 25-28)
- Edge cases (tests 29-36)
- Structure (tests 37-39)
- Accessibility (tests 40-56)
npm test -- --watch components/DraftReview.test.tsxGoal: 56/56 tests passing
it('should display original email subject', () => {
render(<DraftReview draft={mockDraftData} {...handlers} />);
expect(screen.getByText('Project Proposal Discussion')).toBeInTheDocument();
});it('should call onApprove when approve button clicked', async () => {
const onApprove = vi.fn();
render(<DraftReview draft={mockDraftData} onApprove={onApprove} {...} />);
const approveButton = screen.getByRole('button', { name: /approve/i });
fireEvent.click(approveButton);
expect(onApprove).toHaveBeenCalledWith(mockDraftData.id);
});it('should call onSave with edited content', async () => {
const user = userEvent.setup();
const onSave = vi.fn();
render(<DraftReview {...} onSave={onSave} />);
await user.click(screen.getByRole('button', { name: /edit/i }));
const textarea = screen.getByRole('textbox');
await user.clear(textarea);
await user.type(textarea, 'Updated content');
await user.click(screen.getByRole('button', { name: /save/i }));
expect(onSave).toHaveBeenCalledWith(mockDraftData.id, 'Updated content');
});Project: sovereign-agent
Location: C:\Users\Travi\Desktop\convex-ai-bot\sovereign-agent
Framework: Next.js 16 + React 19
Testing: Vitest + @testing-library/react
State: Convex
Styling: Tailwind CSS
sovereign-agent/
├── components/
│ └── DraftReview.test.tsx (Main test file)
├── QUICK_START.md (Get started)
├── DRAFT_REVIEW_IMPLEMENTATION_GUIDE.md (How to build)
├── DRAFT_REVIEW_TEST_SUMMARY.txt (Test reference)
├── RED_PHASE_COMPLETE.md (Full summary)
├── DELIVERABLES.md (Completion report)
└── README_DRAFTREVIEW.md (This file)
| Metric | Value |
|---|---|
| Test File Size | 17 KB |
| Lines of Code | 444 |
| Test Cases | 41 |
| Test Suites | 8 |
| Current Pass Rate | 0% (0/56) |
| Expected Pass Rate (after impl) | 100% (56/56) |
| Estimated Build Time | 2.5 hours |
- Write tests first
- All tests fail (expected)
- Status: Component doesn't exist
- Implement component
- Watch tests turn green
- Goal: 56/56 passing
- Clean up code
- Improve design
- Keep tests passing
- Quick answers: See
QUICK_START.md - Test details: See
DRAFT_REVIEW_TEST_SUMMARY.txt - How to implement: See
DRAFT_REVIEW_IMPLEMENTATION_GUIDE.md - Full context: See
RED_PHASE_COMPLETE.md - All details: See
DELIVERABLES.md
- Tests written and organized
- All tests failing (expected)
- Tests are comprehensive
- Documentation complete
- Ready for implementation
- Component implemented
- All tests passing
- No console errors
- Code coverage > 80%
- Code optimized
- Comments added
- Tests still passing
- Code review passed
npm test -- components/DraftReview.test.tsxFAIL components/DraftReview.test.tsx
Error: Cannot find module './DraftReview'
Test Files 1 failed (1)
Tests no tests ran
npm test -- --watch components/DraftReview.test.tsxnpm test -- components/DraftReview.test.tsx -t "Rendering"
npm test -- components/DraftReview.test.tsx -t "Edit Mode"
npm test -- components/DraftReview.test.tsx -t "Loading"- Vitest - Fast unit test runner
- @testing-library/react - Component testing utilities
- @testing-library/user-event - User interaction simulation
- Convex hooks mocked (useQuery, useMutation, useConvex)
- External dependencies controlled
- No API calls during tests
- AAA (Arrange-Act-Assert)
- User-centric testing
- Accessibility testing
- Error case coverage
Test-Driven Development: Write tests before code
- RED: Write failing tests
- GREEN: Write minimal code to pass tests
- REFACTOR: Improve code while keeping tests passing
- Tests define behavior precisely
- Code is written to pass tests (high quality)
- Refactoring is safe (tests catch regressions)
- Documentation is executable
We're in the RED phase. The component doesn't exist yet. This is normal and correct.
| Phase | Time | Status |
|---|---|---|
| RED (testing) | 2-3 hours | ✅ Complete |
| GREEN (impl) | 2.5 hours | In Progress |
| REFACTOR | 1 hour | Not Started |
| Total | 5.5 hours |
When implementing in GREEN phase, ensure:
- All 56 tests passing
- No console errors
- Proper TypeScript types
- Tailwind styling applied
- Component exported correctly
- Mock data structure matches
- All data-testids present
- ARIA attributes correct
- Responsive design works
- Accessibility compliant
Q: Why do all tests fail? A: This is RED phase of TDD. Tests are written first, component is built in GREEN phase.
Q: How do I know what to implement? A: Read the test file. Each test describes exactly what the component should do.
Q: How long will implementation take? A: Approximately 2.5 hours following the implementation guide.
Q: Can tests run in any order? A: Yes, all tests are independent. Order doesn't matter.
Q: Do I need to follow the implementation guide exactly? A: No, but following it phase-by-phase makes development easier and tests pass incrementally.
- Vitest: https://vitest.dev/
- React Testing Library: https://testing-library.com/react
- TDD: https://en.wikipedia.org/wiki/Test-driven_development
- Component-Based Testing: https://testing-library.com/docs/queries/about/
Version: 1.0 Created: 2026-01-09 Status: RED Phase Complete Next: GREEN Phase Implementation
For detailed information on any topic, refer to the relevant documentation file listed at the top of this README.