# Manual Testing Checklist
## Task 13.2: Manual Testing of Complete Workflows

**Purpose:** Verify end-to-end functionality of all features in the comprehensive-reports-and-fixes spec.

## Prerequisites

- [ ] All automated tests passing (or known failures documented)
- [ ] Test database populated with sample data
- [ ] Test user accounts created (admin, loan officer, borrower)
- [ ] Development server running

## Test Environment Setup

```bash
# Create test users
python manage.py shell
from users.models import CustomUser
from users.models import Branch

# Create test branch
branch = Branch.objects.create(name="Test Branch", code="TB001")

# Create admin user
admin = CustomUser.objects.create_user(
    username='admin@test.com',
    email='admin@test.com',
    password='testpass123',
    role='admin',
    branch=branch,
    is_staff=True,
    is_superuser=True
)

# Create loan officer
officer = CustomUser.objects.create_user(
    username='officer@test.com',
    email='officer@test.com',
    password='testpass123',
    role='loan_officer',
    branch=branch
)

# Create borrower
borrower = CustomUser.objects.create_user(
    username='borrower@test.com',
    email='borrower@test.com',
    password='testpass123',
    role='borrower',
    branch=branch,
    first_name='Test',
    last_name='Borrower',
    phone_number='+254700000000'
)
```

## 1. Disbursed Loans Report Testing

### 1.1 Basic Report Access
- [ ] Navigate to `/reports/disbursed-loans/`
- [ ] Verify page loads without errors
- [ ] Verify report displays loan list

### 1.2 Period Filtering
- [ ] Select "Today" filter
  - [ ] Verify only today's disbursements shown
  - [ ] Verify count matches expected
- [ ] Select "This Week" filter
  - [ ] Verify only current week's disbursements shown
  - [ ] Verify date range is Monday-Sunday
- [ ] Select "Total" filter
  - [ ] Verify all disbursed loans shown
  - [ ] Verify no date restriction

### 1.3 Status Filtering
- [ ] Filter by "Active" status
  - [ ] Verify only active loans shown
- [ ] Filter by "Paid" status
  - [ ] Verify only paid loans shown
- [ ] Filter by "Defaulted" status
  - [ ] Verify only defaulted loans shown
- [ ] Filter by "Rolled Over" status
  - [ ] Verify only rolled over loans shown
- [ ] Filter by "Written Off" status
  - [ ] Verify only written off loans shown

### 1.4 Additional Filters
- [ ] Filter by branch
  - [ ] Verify only loans from selected branch shown
- [ ] Filter by loan product
  - [ ] Verify only loans of selected product shown
- [ ] Filter by amount range
  - [ ] Enter min amount: 5000, max amount: 20000
  - [ ] Verify only loans in range shown

### 1.5 Sorting
- [ ] Sort by loan number (ascending/descending)
- [ ] Sort by borrower name (ascending/descending)
- [ ] Sort by disbursement date (ascending/descending)
- [ ] Sort by principal amount (ascending/descending)
- [ ] Sort by outstanding amount (ascending/descending)

### 1.6 Data Display
- [ ] Verify all columns displayed:
  - [ ] Loan number
  - [ ] Borrower name
  - [ ] Phone number
  - [ ] Disbursement date
  - [ ] Principal amount
  - [ ] Interest amount
  - [ ] Processing fee
  - [ ] Total amount
  - [ ] Amount paid
  - [ ] Outstanding amount
  - [ ] Status

### 1.7 Export Functionality
- [ ] Click "Export to PDF"
  - [ ] Verify PDF downloads
  - [ ] Open PDF and verify:
    - [ ] All filtered data included
    - [ ] Proper formatting (headers, footers, page numbers)
    - [ ] Currency formatted with thousand separators
    - [ ] Dates formatted consistently
    - [ ] Report title and generation date included
- [ ] Click "Export to Excel"
  - [ ] Verify Excel file downloads
  - [ ] Open Excel and verify:
    - [ ] All columns included
    - [ ] All filtered data included
    - [ ] Proper formatting
    - [ ] Currency and date formatting

## 2. Age & Gender Analytics Report Testing

### 2.1 Basic Report Access
- [ ] Navigate to `/reports/age-gender-analytics/`
- [ ] Verify page loads without errors
- [ ] Verify report displays demographic analysis

### 2.2 Age Group Analysis
- [ ] Verify age group breakdown table displayed
- [ ] Verify age groups: 18-25, 26-35, 36-45, 46-55, 56-65, 66+, Not Specified
- [ ] For each age group, verify displayed:
  - [ ] Total applications
  - [ ] Approved applications
  - [ ] Approval rate (%)
  - [ ] Average loan amount
  - [ ] Average repayment rate (%)

### 2.3 Gender Analysis
- [ ] Verify gender breakdown table displayed
- [ ] Verify gender categories: Male, Female, Other, Not Specified
- [ ] For each gender, verify displayed:
  - [ ] Total applications
  - [ ] Approved applications
  - [ ] Approval rate (%)
  - [ ] Average loan amount
  - [ ] Average repayment rate (%)

### 2.4 Payment Pattern Analysis
- [ ] Verify payment pattern tables displayed
- [ ] Verify on-time vs late payment breakdown by age group
- [ ] Verify on-time vs late payment breakdown by gender
- [ ] Verify percentages add up to 100%

### 2.5 Visual Charts
- [ ] Verify age distribution chart displayed
- [ ] Verify gender distribution chart displayed
- [ ] Verify payment performance charts displayed
- [ ] Verify charts are interactive (if applicable)

### 2.6 Export Functionality
- [ ] Click "Export to PDF"
  - [ ] Verify PDF downloads
  - [ ] Verify all tables included
  - [ ] Verify charts included (if supported)
  - [ ] Verify proper formatting
- [ ] Click "Export to Excel"
  - [ ] Verify Excel file downloads
  - [ ] Verify separate sheets for:
    - [ ] Age analysis
    - [ ] Gender analysis
    - [ ] Raw data (if included)

## 3. Loan Edit Functionality Testing

### 3.1 Access Control
- [ ] Log in as admin user
- [ ] Navigate to loan detail page
- [ ] Verify "Edit Loan" button visible
- [ ] Log out and log in as non-admin user
- [ ] Navigate to loan detail page
- [ ] Verify "Edit Loan" button NOT visible

### 3.2 Edit Form Display
- [ ] As admin, click "Edit Loan" button
- [ ] Verify edit form displays with fields:
  - [ ] Principal amount
  - [ ] Interest amount
  - [ ] Processing fee
  - [ ] Disbursement date
  - [ ] Due date
  - [ ] Status dropdown

### 3.3 Amount Editing
- [ ] Edit principal amount to 15000
- [ ] Edit interest amount to 1500
- [ ] Edit processing fee to 750
- [ ] Submit form
- [ ] Verify success message displayed
- [ ] Verify total_amount recalculated (15000 + 1500 + 750 = 17250)
- [ ] Verify changes persisted (refresh page)

### 3.4 Status Transitions - Valid
- [ ] Create loan with status "active"
- [ ] Change status to "paid" (ensure sufficient payment)
  - [ ] Verify transition allowed
  - [ ] Verify status updated
- [ ] Create loan with status "active"
- [ ] Change status to "defaulted"
  - [ ] Verify transition allowed
- [ ] Create loan with status "active"
- [ ] Change status to "rolled_over"
  - [ ] Verify transition allowed
- [ ] Create loan with status "active"
- [ ] Change status to "written_off"
  - [ ] Verify transition allowed
- [ ] Create loan with status "defaulted"
- [ ] Change status to "written_off"
  - [ ] Verify transition allowed

### 3.5 Status Transitions - Invalid
- [ ] Create loan with status "paid"
- [ ] Attempt to change status to any other status
  - [ ] Verify error message displayed
  - [ ] Verify status NOT changed
- [ ] Create loan with status "rolled_over"
- [ ] Attempt to change status
  - [ ] Verify error message displayed
- [ ] Create loan with status "written_off"
- [ ] Attempt to change status
  - [ ] Verify error message displayed

### 3.6 Paid Status Validation
- [ ] Create loan with total_amount = 10000, no payments
- [ ] Attempt to change status to "paid"
  - [ ] Verify error message: "Cannot mark as paid: insufficient payment"
- [ ] Add payment of 10000
- [ ] Attempt to change status to "paid"
  - [ ] Verify transition allowed

### 3.7 Audit Logging
- [ ] Edit a loan (change any field)
- [ ] Navigate to audit log (if accessible)
- [ ] Verify audit log entry created with:
  - [ ] Timestamp
  - [ ] User (admin who made edit)
  - [ ] Fields changed
  - [ ] Old and new values (if logged)

## 4. Penalty Addition Testing

### 4.1 Access Control
- [ ] Log in as admin user
- [ ] Navigate to loan detail page
- [ ] Verify "Add Penalty" button visible
- [ ] Log out and log in as non-admin user
- [ ] Navigate to loan detail page
- [ ] Verify "Add Penalty" button NOT visible

### 4.2 Penalty Form Display
- [ ] As admin, click "Add Penalty" button
- [ ] Verify penalty form/modal displays with fields:
  - [ ] Amount input
  - [ ] Penalty date picker
  - [ ] Reason textarea (optional)

### 4.3 Valid Penalty Addition
- [ ] Enter amount: 500
- [ ] Select penalty date: today
- [ ] Enter reason: "Late payment fee"
- [ ] Submit form
- [ ] Verify success message displayed
- [ ] Verify penalty appears in loan detail:
  - [ ] Amount: 500
  - [ ] Penalty date: today
  - [ ] Date added: today
  - [ ] Reason: "Late payment fee"
- [ ] Verify outstanding amount increased by 500

### 4.4 Penalty Validation - Zero Amount
- [ ] Enter amount: 0
- [ ] Select penalty date: today
- [ ] Submit form
- [ ] Verify error message: "Penalty amount must be greater than zero"
- [ ] Verify penalty NOT created

### 4.5 Penalty Validation - Negative Amount
- [ ] Enter amount: -100
- [ ] Select penalty date: today
- [ ] Submit form
- [ ] Verify error message: "Penalty amount must be greater than zero"
- [ ] Verify penalty NOT created

### 4.6 Penalty Validation - Future Date
- [ ] Enter amount: 500
- [ ] Select penalty date: tomorrow
- [ ] Submit form
- [ ] Verify error message: "Penalty date cannot be in the future"
- [ ] Verify penalty NOT created

### 4.7 Penalty Validation - Past Date
- [ ] Enter amount: 500
- [ ] Select penalty date: yesterday
- [ ] Submit form
- [ ] Verify penalty created successfully
- [ ] Verify penalty date is yesterday

### 4.8 Multiple Penalties
- [ ] Add first penalty: 500
- [ ] Add second penalty: 300
- [ ] Add third penalty: 200
- [ ] Verify all three penalties displayed
- [ ] Verify outstanding amount increased by 1000 (500+300+200)
- [ ] Verify total_penalties = 1000

## 5. Overdue Filter Testing

### 5.1 Overdue Filter Option
- [ ] Navigate to loan list page
- [ ] Verify "Overdue" option in status dropdown
- [ ] Verify option appears alongside other statuses

### 5.2 Overdue Filter Logic
- [ ] Create loan with:
  - [ ] due_date = yesterday
  - [ ] outstanding_amount > 0
  - [ ] status = 'active'
- [ ] Select "Overdue" filter
- [ ] Verify loan appears in results
- [ ] Verify days overdue displayed correctly

### 5.3 Overdue Exclusions
- [ ] Create loan with due_date = yesterday, outstanding_amount = 0
  - [ ] Verify NOT in overdue filter (fully paid)
- [ ] Create loan with due_date = yesterday, status = 'paid'
  - [ ] Verify NOT in overdue filter
- [ ] Create loan with due_date = tomorrow, outstanding_amount > 0
  - [ ] Verify NOT in overdue filter (not yet due)

### 5.4 Overdue Visual Indicators
- [ ] Navigate to loan list
- [ ] Verify overdue loans have visual indicator:
  - [ ] Badge or color highlighting
  - [ ] Days overdue displayed
  - [ ] Clear distinction from non-overdue loans

### 5.5 Overdue in Reports
- [ ] Navigate to collection reports
- [ ] Verify overdue loans included
- [ ] Navigate to dashboard
- [ ] Verify overdue loans count displayed

## 6. Date Filtering Testing

### 6.1 Loans Due Report - Today Filter
- [ ] Navigate to `/reports/loans-due/enhanced/?today_only=true`
- [ ] Verify only loans due today displayed
- [ ] Create loan with due_date = today
  - [ ] Verify appears in results
- [ ] Create loan with due_date = yesterday
  - [ ] Verify does NOT appear in results
- [ ] Create loan with due_date = tomorrow
  - [ ] Verify does NOT appear in results

### 6.2 Loans Due Report - Date Range
- [ ] Navigate to loans due report
- [ ] Select date range: March 1 - March 15
- [ ] Verify only loans due within range displayed
- [ ] Verify loans due on March 1 included
- [ ] Verify loans due on March 15 included
- [ ] Verify loans due on Feb 28 NOT included
- [ ] Verify loans due on March 16 NOT included

### 6.3 Date Comparison Consistency
- [ ] Create loan with due_date = "2026-03-14 15:30:00" (datetime with time)
- [ ] Filter by date = "2026-03-14"
- [ ] Verify loan appears in results (time component ignored)

### 6.4 Empty Results Message
- [ ] Filter by date range with no loans
- [ ] Verify message displayed: "No loans are due in the selected period"

### 6.5 Date Filtering in Other Reports
- [ ] Test date filtering in disbursed loans report
  - [ ] Verify same logic applied
- [ ] Test date filtering in any other date-based reports
  - [ ] Verify consistency across all reports

## 7. Export Formats Testing

### 7.1 PDF Export Quality
- [ ] Export any report to PDF
- [ ] Open PDF and verify:
  - [ ] Headers on each page
  - [ ] Footers on each page
  - [ ] Page numbers (e.g., "Page 1 of 3")
  - [ ] Report title at top
  - [ ] Generation date displayed
  - [ ] Filter criteria displayed
  - [ ] Consistent font and styling
  - [ ] Currency formatted: 10,000.00
  - [ ] Dates formatted: YYYY-MM-DD or DD/MM/YYYY (consistent)
  - [ ] Tables have borders
  - [ ] No text cutoff or overflow
  - [ ] Proper pagination for large datasets

### 7.2 Excel Export Quality
- [ ] Export any report to Excel
- [ ] Open Excel and verify:
  - [ ] All columns from web view included
  - [ ] All rows from filtered data included
  - [ ] Header row with column names
  - [ ] Currency formatted as numbers (not text)
  - [ ] Dates formatted as dates (not text)
  - [ ] Report title in first row or separate sheet
  - [ ] Generation date included
  - [ ] Filter criteria included
  - [ ] No truncated data
  - [ ] Proper column widths

### 7.3 Large Dataset Export
- [ ] Create 100+ loan records
- [ ] Export to PDF
  - [ ] Verify all records included
  - [ ] Verify proper pagination
  - [ ] Verify export completes within 30 seconds
- [ ] Export to Excel
  - [ ] Verify all records included
  - [ ] Verify export completes within 20 seconds

## Test Results Summary

### Disbursed Loans Report
- [ ] All tests passed
- [ ] Issues found: _______________
- [ ] Notes: _______________

### Age & Gender Analytics
- [ ] All tests passed
- [ ] Issues found: _______________
- [ ] Notes: _______________

### Loan Edit Functionality
- [ ] All tests passed
- [ ] Issues found: _______________
- [ ] Notes: _______________

### Penalty Addition
- [ ] All tests passed
- [ ] Issues found: _______________
- [ ] Notes: _______________

### Overdue Filter
- [ ] All tests passed
- [ ] Issues found: _______________
- [ ] Notes: _______________

### Date Filtering
- [ ] All tests passed
- [ ] Issues found: _______________
- [ ] Notes: _______________

### Export Formats
- [ ] All tests passed
- [ ] Issues found: _______________
- [ ] Notes: _______________

## Overall Assessment

**Manual Testing Status:** [ ] Complete / [ ] Incomplete  
**Critical Issues Found:** _______________  
**Blocker Issues:** _______________  
**Ready for Deployment:** [ ] Yes / [ ] No  

**Tester Name:** _______________  
**Date:** _______________  
**Signature:** _______________
