# Profile Feature Testing Guide

## Quick Start

### 1. Run Migration
```bash
php artisan migrate
```

### 2. Start Server
```bash
php artisan serve
```

### 3. Access Application
```
http://localhost:8000
```

## Test Scenarios

### Scenario 1: Doctor Profile Access
**Goal**: Access and view doctor profile

1. Login with `doctor@rxnetworx.com` (any password)
2. Look at the sidebar - you should see the user profile section at the top
3. Click on "Dr. James Wilson" - a dropdown should appear
4. Click "My Profile" in the dropdown
5. **Expected**: You should see the profile page with two tabs:
   - Personal Information (active by default)
   - Due Diligence

### Scenario 2: Upload Profile Photo (Doctor)
**Goal**: Change profile picture

1. On the Personal Information tab, find the "Profile Photo" card on the left
2. Click "Choose File" and select an image (JPEG, PNG, JPG, or GIF, max 2MB)
3. Click "Upload Photo"
4. **Expected**: 
   - Green success message appears
   - New photo displays in the profile page
   - Photo updates in the sidebar

### Scenario 3: Change Password
**Goal**: Update account password

1. On the Personal Information tab, scroll to the "Change Password" section
2. Fill in:
   - Current Password: `anypassword`
   - New Password: `newpassword123` (min 8 chars)
   - Confirm New Password: `newpassword123`
3. Click "Update Password"
4. **Expected**: Green success message appears

### Scenario 4: Upload Medical License (Doctor)
**Goal**: Upload credential document

1. Click the "Due Diligence" tab
2. In the "Medical License" card, click "Choose File"
3. Select a PDF, JPEG, or PNG file (max 5MB)
4. Click "Upload License"
5. **Expected**:
   - Green success message appears
   - "License uploaded" badge appears
   - "View Current License" button appears

### Scenario 5: Upload Digital Signature (Doctor)
**Goal**: Upload signature image

1. On the Due Diligence tab, find the "Digital Signature" card
2. Click "Choose File" and select an image (PNG, JPEG, or JPG, max 2MB)
3. Click "Upload Signature"
4. **Expected**:
   - Green success message appears
   - "Signature uploaded" badge appears
   - Signature preview displays

### Scenario 6: Patient Profile Access
**Goal**: Access patient profile (simpler version)

1. Logout and login with `patient@rxnetworx.com`
2. Click on bottom navigation "Profile" icon (mobile) or sidebar user dropdown
3. Click "My Profile"
4. **Expected**: 
   - Only Personal Information tab visible (no Due Diligence)
   - Can upload profile photo
   - Can change password
   - Personal details are read-only

### Scenario 7: Mobile Navigation
**Goal**: Test mobile responsive design

1. Resize browser to mobile width (< 768px) or use device emulator
2. Look at bottom navigation bar
3. Click the "Profile" icon
4. **Expected**: Navigate to profile page
5. Test photo upload and password change on mobile view

### Scenario 8: Dropdown Menu
**Goal**: Verify dropdown functionality

1. Login as doctor
2. Click on user profile section in sidebar
3. **Expected**: Dropdown appears with:
   - "My Profile" option
   - Divider line
   - "Sign Out" option (in red)
4. Click anywhere outside - dropdown should close
5. Click "Sign Out" - should logout and redirect to login page

## Validation Testing

### Test File Size Limits
**Profile Photo**:
- ✅ Try uploading > 2MB image → Should show error
- ✅ Try valid image < 2MB → Should succeed

**Medical License**:
- ✅ Try uploading > 5MB file → Should show error
- ✅ Try valid PDF < 5MB → Should succeed

**Digital Signature**:
- ✅ Try uploading > 2MB image → Should show error
- ✅ Try valid image < 2MB → Should succeed

### Test File Type Validation
**Profile Photo**:
- ✅ Try .txt file → Should show error
- ✅ Try .exe file → Should show error
- ✅ Try .jpg file → Should succeed

**Medical License**:
- ✅ Try .docx file → Should show error
- ✅ Try .pdf file → Should succeed

**Digital Signature**:
- ✅ Try .gif file → Should show error (only PNG/JPG/JPEG allowed)
- ✅ Try .png file → Should succeed

### Test Password Validation
- ✅ Try password < 8 chars → Should show error
- ✅ Try mismatched confirmation → Should show error
- ✅ Try empty current password → Should show error
- ✅ Try valid 8+ char password with match → Should succeed

## Visual Verification

### Desktop (> 768px)
- [ ] Sidebar shows user profile with dropdown arrow
- [ ] Clicking profile opens dropdown menu
- [ ] Profile page shows two columns on Personal Info tab
- [ ] Tabs are clearly visible and clickable
- [ ] Upload buttons are properly styled
- [ ] Success/error messages display correctly

### Mobile (< 768px)
- [ ] Bottom navigation shows Profile icon
- [ ] Profile icon highlights when active
- [ ] Profile page stacks vertically
- [ ] Tabs are touch-friendly
- [ ] Forms are easy to use on mobile
- [ ] File inputs work on mobile devices

## File System Verification

After uploading files, verify they exist:
```bash
# Profile photos
ls public/uploads/profiles/

# Medical licenses
ls public/uploads/licenses/

# Digital signatures
ls public/uploads/signatures/
```

Files should be named: `{type}_{timestamp}.{extension}`
Example: `profile_1737408000.jpg`

## Browser Console Check

1. Open browser developer tools (F12)
2. Check Console tab for any JavaScript errors
3. Check Network tab when uploading files
4. Verify POST requests return 200 status

## Common Issues and Solutions

### Issue: Dropdown doesn't open
**Solution**: 
- Verify Bootstrap JS is loaded
- Check console for JavaScript errors
- Clear browser cache

### Issue: Files not uploading
**Solution**:
- Check directory permissions
- Verify `public/uploads/` directories exist
- Check PHP `upload_max_filesize` in php.ini

### Issue: Profile photo not showing
**Solution**:
- Check file was actually saved to public/uploads/profiles/
- Verify asset URL is correct
- Check browser console for 404 errors

### Issue: "Method not allowed" error
**Solution**:
- Verify form method is POST
- Check @csrf token is present in forms
- Clear route cache: `php artisan route:clear`

### Issue: Validation errors don't display
**Solution**:
- Check @errors directive in blade template
- Verify validation rules in controller
- Check Bootstrap alert classes are correct

## Database Verification

After running migration, verify table structure:
```bash
php artisan tinker
```

Then in tinker:
```php
Schema::getColumnListing('users');
// Should show: user_type, phone, profile_photo, license_file, signature_file, npi_number, dea_number, specialty
```

## Session Verification (Prototype)

Since we're using session storage for the prototype, verify data is stored:

```php
// In tinker or dd() in controller:
session()->all();
```

Should show profile-related keys after uploads:
- `profile_photo`
- `license_file`
- `signature_file`

## Accessibility Testing

### Keyboard Navigation
- [ ] Tab through dropdown menu
- [ ] Tab through form fields
- [ ] Enter key activates buttons
- [ ] Escape key closes dropdown

### Screen Reader
- [ ] Dropdown has proper ARIA labels
- [ ] Form fields have labels
- [ ] Error messages are announced
- [ ] Success messages are announced

## Performance Testing

### File Upload Speed
- Test with various file sizes
- Check for timeout issues
- Verify progress indication (browser default)

### Page Load Speed
- Profile page should load < 1 second
- Images should load asynchronously
- No blocking resources

## Security Testing

### CSRF Protection
- [ ] Try submitting form without CSRF token → Should fail
- [ ] Verify @csrf is in all forms
- [ ] Check CSRF token in request headers

### File Type Spoofing
- [ ] Try renaming .txt to .jpg → Should be caught by validation
- [ ] Try uploading executable → Should be rejected

### SQL Injection (Future)
- Currently using session, but test input sanitization
- Verify no raw queries are used

## Browser Compatibility

Test on:
- [ ] Chrome (latest)
- [ ] Firefox (latest)
- [ ] Safari (latest)
- [ ] Edge (latest)
- [ ] Mobile Safari (iOS)
- [ ] Chrome Mobile (Android)

## Final Checklist

### Functionality
- [x] Profile route is registered
- [x] Controller methods exist
- [x] View renders correctly
- [x] Sidebar dropdown works
- [x] Mobile navigation works
- [x] Photo upload works
- [x] Password change works
- [x] License upload works (doctors)
- [x] Signature upload works (doctors)

### Code Quality
- [x] No linter errors
- [x] Follows Laravel conventions
- [x] Uses existing patterns from codebase
- [x] Proper error handling
- [x] CSRF protection
- [x] Input validation

### Documentation
- [x] README updated
- [x] Feature documentation created
- [x] Implementation summary created
- [x] Testing guide created
- [x] Code comments added

### UI/UX
- [x] Responsive design
- [x] Consistent styling
- [x] Clear error messages
- [x] Success feedback
- [x] Accessible

## Success Criteria

✅ All test scenarios pass
✅ No console errors
✅ Files upload successfully
✅ Validations work correctly
✅ Mobile responsive
✅ Dropdown menu functions
✅ Both tabs work for doctors
✅ Patient sees only personal info tab

## Report Template

Use this template to report issues:

```
**Issue**: [Brief description]
**Steps to Reproduce**:
1. 
2. 
3. 

**Expected Behavior**: 
**Actual Behavior**: 
**Browser**: 
**Screenshot**: [if applicable]
```

## Testing Digital Signatures on eRX

### Scenario 10: Signature on Prescription (NEW)
**Goal**: Verify uploaded signature appears on eRX prescriptions

1. **Upload Signature** (if not done already):
   - Login as doctor (`doctor@rxnetworx.com`)
   - Go to Profile → Due Diligence tab
   - Upload a signature image (PNG/JPG)
   - Verify signature displays in the preview

2. **Approve Prescription**:
   - Navigate to Patients tab
   - Click "View Details" on any patient
   - Click "Approve & Sign" button
   - Confirm the success dialog appears

3. **View eRX with Signature**:
   - Navigate to Prescriptions tab
   - Click "View" on the prescription you just approved
   - Scroll to the bottom footer section
   - **Expected**: 
     - "Electronically Signed By" section shows prescriber name and date
     - Digital signature image appears below the text
     - Signature is contained in a bordered box

4. **Test Print View**:
   - On the same prescription view, click "Print" button
   - Check print preview
   - **Expected**:
     - Signature is visible and clear in print preview
     - Signature maintains proper sizing
     - Page layout is not broken

5. **Test Without Signature**:
   - Clear browser data or use incognito mode
   - Login as doctor
   - Navigate to Prescriptions → View any prescription
   - **Expected**: Shows "Digital signature on file" text instead of image

## Next Steps After Testing

1. Fix any identified issues
2. Run migration on staging/production
3. Test with real users
4. Monitor upload errors
5. Implement production enhancements
6. Add analytics tracking
7. Set up monitoring alerts

## Related Documentation

- [Signature on eRX Feature Documentation](./docs/SIGNATURE_ON_ERX_FEATURE.md) - Complete technical details
- [Profile Implementation Summary](./docs/PROFILE_IMPLEMENTATION_SUMMARY.md)
- [Profile Feature](./docs/PROFILE_FEATURE.md)

---

**Happy Testing! 🚀**
