# Testing Guide - Supervisory Comment Revision System

## Prerequisites
- Migration has been run: `php artisan migrate`
- You have test accounts for:
  - Student user
  - Supervisor user
- A logbook entry exists that can be reviewed

## Test Scenarios

### Scenario 1: First Review (Rejection)
**As Supervisor:**

1. Navigate to a submitted logbook entry
2. Fill in the review form:
   - Status: "Rejected"
   - Supervisor Feedback: "Please add more detail about the activities performed and include specific learning outcomes."
3. Submit the review

**Expected Results:**
- Entry status changes to "Rejected"
- A revision record is created with revision_number = 1
- Student sees the feedback
- "Revision History" section appears showing 1 revision
- Student can now edit the entry

---

### Scenario 2: Student Amendment
**As Student:**

1. View the rejected logbook entry
2. Notice:
   - "Revision History" section shows the rejection
   - Alert indicates amendment is required
3. Click "Edit" button
4. Notice the warning alert showing supervisor feedback
5. Make improvements to the entry
6. Change status to "Submit for review"
7. Save changes

**Expected Results:**
- Entry status changes back to "Submitted"
- Entry can now be reviewed again by supervisor
- Previous revision history is preserved

---

### Scenario 3: Second Review (Approval)
**As Supervisor:**

1. Navigate to the resubmitted logbook entry
2. Review the revised content
3. Fill in the review form:
   - Status: "Approved"
   - Supervisor Feedback: "Great improvement! The additional details clearly demonstrate your learning."
4. Submit the review

**Expected Results:**
- Entry status changes to "Approved"
- A second revision record is created with revision_number = 2
- "Revision History" shows 2 revisions in timeline
- Entry becomes locked (cannot be edited anymore)

---

### Scenario 4: Multiple Rejections & Amendments
**Repeat Scenarios 1-2 multiple times:**

1. Supervisor rejects → revision_number increments
2. Student amends and resubmits
3. Supervisor reviews again → new revision created

**Expected Results:**
- Each review creates a new revision record
- Revision numbers increment: 1, 2, 3, 4...
- Complete timeline visible in "Revision History"
- All feedback preserved and visible

---

## What to Check

### Database Verification
Check the `logbook_entry_revisions` table:

```sql
SELECT * FROM logbook_entry_revisions 
WHERE logbook_entry_id = [YOUR_ENTRY_ID]
ORDER BY revision_number;
```

**Should show:**
- Each review as a separate row
- Incrementing revision_number
- All feedback preserved
- Correct reviewed_by foreign keys
- Accurate timestamps

### View Components
**On show.blade.php:**

✅ Current Review Status card displays latest review
✅ Revision History section appears when revisions exist
✅ Timeline shows all revisions in reverse chronological order
✅ Color coding: green for approved, red for rejected
✅ Badge shows total revision count
✅ If rejected, alert prompts for amendment

**On edit.blade.php (when editing rejected entry):**

✅ Warning alert appears at top
✅ Supervisor feedback displayed prominently
✅ Reviewer name and date shown
✅ Form is editable and can be submitted

### Permission Checks

**Students can:**
- Edit entries with status "draft" or "rejected"
- View revision history for their own entries
- Cannot edit "approved" entries

**Supervisors can:**
- Review submitted entries
- View revision history
- Cannot edit student entries

---

## Sample Test Data

### Test Review 1 (Rejection)
```
Status: Rejected
Feedback: "Your description lacks specific details. Please include:
1. Exact tasks performed
2. Tools/technologies used
3. Challenges encountered
4. Skills developed"
```

### Test Review 2 (Approval)
```
Status: Approved
Feedback: "Excellent work! Your revised entry clearly demonstrates:
- Detailed daily activities
- Clear learning outcomes
- Professional reflection
Well done!"
```

### Test Review 3 (Rejection with specific guidance)
```
Status: Rejected
Feedback: "Please revise the following sections:
- Weather conditions: Add more environmental context
- Time tracking: Start and end times are missing
- Word count: Current 150 words, need 250+ words"
```

---

## Edge Cases to Test

### 1. No Revisions Yet
- Entry just created
- No reviews performed
- "Revision History" section should NOT appear

### 2. Approved Entry Edit Attempt
- Entry status = "Approved"
- Student tries to click edit
- Should redirect with error message

### 3. Multiple Supervisors
- Different supervisors review the same entry
- Each revision should record the correct reviewer

### 4. Concurrent Reviews
- Ensure revision_number stays accurate
- Test with multiple supervisors reviewing different entries

---

## Troubleshooting

### Revision not created
**Check:**
- Migration ran successfully
- LogbookEntryRevision model imported in controller
- Route `logbook.review` exists and is accessible

### Revision history not showing
**Check:**
- Revisions relationship loaded: `$logbook->load('revisions.reviewer')`
- View file updated correctly
- At least one revision exists in database

### Student cannot edit rejected entry
**Check:**
- Entry status is exactly "Rejected" (case matters)
- `canEdit` logic in show() method
- Edit permission check in edit() method

### Wrong revision number
**Check:**
- Count query: `$logbook->revisions()->count()`
- No duplicate revisions created
- Database revision records are correct

---

## Clean Up After Testing

To reset test data:

```sql
-- Delete test revisions
DELETE FROM logbook_entry_revisions 
WHERE logbook_entry_id = [YOUR_TEST_ENTRY_ID];

-- Reset logbook entry status
UPDATE logbook_entries 
SET status = 'draft', 
    supervisor_feedback = NULL, 
    reviewed_by = NULL, 
    reviewed_at = NULL
WHERE id = [YOUR_TEST_ENTRY_ID];
```

---

## Success Criteria

✅ All revisions are saved to database
✅ Revision numbers increment correctly
✅ Timeline displays all revisions
✅ Rejected entries can be edited
✅ Approved entries cannot be edited
✅ All feedback is preserved and visible
✅ Permissions work correctly
✅ No errors in logs or console
