# Phase 5: Testing Checklist

## Quick Manual Tests (30 min)

### ✅ Test 1: State Machine Flow
1. Open moderation queue → Click submission
2. **Check DevTools React Components:** Find `SubmissionReviewManager`
3. **Verify state transitions:** `idle` → `claiming` → `locked` → `loading_data` → `reviewing`
4. **Expected:** Items load, no console errors

### ✅ Test 2: Lock Expiry Warning
1. Claim submission and wait ~13 minutes (or modify DB lock duration to 2 min for testing)
2. **Expected:** Toast warning appears: "Lock Expiring Soon"
3. Click to extend lock
4. **Expected:** Lock renewed, toast confirms

### ✅ Test 3: Approval Flow
1. Select items → Click "Approve Selected"
2. **Check state transitions:** `reviewing` → `approving` → `complete`
3. **Expected:** Success toast with requestId, items approved

### ✅ Test 4: Rejection Flow
1. Select items → Click "Reject Selected"
2. Enter reason → Confirm
3. **Check state:** `reviewing` → `rejecting` → `complete`
4. **Expected:** Success toast, items rejected

### ✅ Test 5: Illegal Transition Prevention
1. While in `approving` state, try clicking "Reject"
2. **Expected:** Button disabled, no console errors

### ✅ Test 6: Error Recovery
1. Disconnect network → Attempt approval
2. **Expected:** State shows `error`, "Try Again" button appears
3. Reconnect → Click "Try Again"
4. **Expected:** Recovery successful

---

## Database Validation Queries (15 min)

### Query 1: Active Locks
```sql
SELECT id, status, locked_until, assigned_to
FROM content_submissions
WHERE locked_until > NOW()
ORDER BY locked_until DESC;
```
**Expected:** All locks valid, no expired with status='locked'

### Query 2: Stuck Locks Check
```sql
SELECT id, status, locked_until
FROM content_submissions
WHERE status = 'locked' 
  AND locked_until < NOW();
```
**Expected:** 0 rows (no stuck locks)

### Query 3: Request Tracking Coverage
```sql
SELECT 
  endpoint,
  COUNT(*) as request_count,
  AVG(duration_ms) as avg_duration_ms,
  COUNT(CASE WHEN error_message IS NOT NULL THEN 1 END) as error_count
FROM request_metadata
WHERE created_at > NOW() - INTERVAL '1 hour'
GROUP BY endpoint
ORDER BY request_count DESC;
```
**Expected:** `process-selective-approval` present with requests

### Query 4: Status Type Safety
```sql
SELECT status, COUNT(*) as count
FROM content_submissions
WHERE status NOT IN ('draft', 'pending', 'locked', 'reviewing', 'partially_approved', 'approved', 'rejected', 'escalated')
GROUP BY status;
```
**Expected:** 0 rows (all statuses valid)

---

## Performance Check (15 min)

### Test 1: State Machine Overhead
1. Chrome DevTools → Performance tab → Record
2. Submit approval flow
3. Stop recording → Search for "moderationReducer"
4. **Target:** < 5ms total time

### Test 2: UI Responsiveness
1. Measure button click → state change
2. **Target:** < 100ms response time

### Test 3: Memory Leak Check
1. DevTools Memory tab → Take baseline heap snapshot
2. Perform 20 form submissions
3. Force GC (🗑️) → Take second snapshot
4. Compare snapshots
5. **Expected:** No significant memory retention

---

## Success Criteria

**Functional:**
- ✅ State machine controls all submission states
- ✅ Lock expiry warnings work
- ✅ Illegal transitions prevented
- ✅ Error recovery functional
- ✅ All buttons respect state machine guards

**Quality:**
- ✅ Zero TypeScript errors
- ✅ No console errors during normal flow
- ✅ All manual tests pass
- ✅ Database shows no orphaned/invalid data

**Performance:**
- ✅ State machine overhead < 5ms
- ✅ UI response < 100ms
- ✅ No memory leaks

---

## Quick Test Commands

```bash
# Test lock expiry (reduce to 2 min for testing)
UPDATE content_submissions 
SET locked_until = NOW() + INTERVAL '2 minutes'
WHERE id = 'YOUR_SUBMISSION_ID';

# Reset stuck submission
UPDATE content_submissions 
SET status = 'pending', locked_until = NULL, assigned_to = NULL
WHERE id = 'YOUR_SUBMISSION_ID';

# View recent request tracking
SELECT * FROM request_metadata 
ORDER BY created_at DESC 
LIMIT 20;
```

---

## Issue Checklist

- [ ] All 6 manual tests pass
- [ ] All 4 database queries return expected results
- [ ] Performance benchmarks meet targets
- [ ] No memory leaks detected
- [ ] Lock monitoring functions correctly
- [ ] Error recovery works
- [ ] UI reflects state accurately

**Estimated Time:** 1 hour total
