151 lines
5.6 KiB
Python
151 lines
5.6 KiB
Python
#!/usr/bin/env python
|
|
"""
|
|
Test script to verify Admin Evaluation Dashboard has data
|
|
"""
|
|
import os
|
|
import django
|
|
import time
|
|
from django.contrib.auth import authenticate
|
|
from playwright.sync_api import sync_playwright
|
|
|
|
# Setup Django
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'PX360.settings')
|
|
django.setup()
|
|
|
|
from apps.accounts.models import User
|
|
|
|
def test_admin_dashboard_with_data():
|
|
print("🚀 Testing Admin Evaluation Dashboard with Data")
|
|
print("=" * 60)
|
|
|
|
# Find test user
|
|
try:
|
|
user = User.objects.get(email='rahaf@example.com')
|
|
print(f"✓ Found test user: {user.first_name}")
|
|
print(f" Email: {user.email}")
|
|
except User.DoesNotExist:
|
|
print("✗ Test user not found")
|
|
return
|
|
|
|
# Get user's assignments
|
|
complaints_count = user.assigned_complaints.count()
|
|
inquiries_count = user.assigned_inquiries.count()
|
|
print(f"\n User has {complaints_count} assigned complaints")
|
|
print(f" User has {inquiries_count} assigned inquiries")
|
|
|
|
with sync_playwright() as p:
|
|
# Launch browser
|
|
browser = p.chromium.launch(headless=True)
|
|
page = browser.new_page()
|
|
|
|
# Login page
|
|
print("\n🔐 Logging in...")
|
|
page.goto('http://localhost:8000/accounts/login/')
|
|
|
|
# Fill login form
|
|
page.fill('input[name="email"]', 'rahaf@example.com')
|
|
page.fill('input[name="password"]', 'password123')
|
|
page.click('button[type="submit"]')
|
|
|
|
# Wait for navigation
|
|
time.sleep(2)
|
|
print("✓ User logged in successfully")
|
|
|
|
# Navigate to admin evaluation dashboard
|
|
print("\n📊 Accessing admin evaluation dashboard...")
|
|
page.goto('http://localhost:8000/dashboard/admin-evaluation/')
|
|
|
|
# Wait for page load
|
|
time.sleep(3)
|
|
|
|
# Check status
|
|
print(f" URL: {page.url}")
|
|
print(f" Status: Loaded successfully")
|
|
|
|
# Check for performance data script tag
|
|
print("\n📋 Checking for performance data...")
|
|
performance_script = page.query_selector('script#performanceData')
|
|
|
|
if performance_script:
|
|
print("✓ Performance data script tag found")
|
|
|
|
# Get the content of the script tag
|
|
data_content = performance_script.inner_text()
|
|
print(f"\n Data preview (first 500 chars):")
|
|
print(f" {data_content[:500]}...")
|
|
|
|
# Check if it contains staff_metrics
|
|
if 'staff_metrics' in data_content:
|
|
print("\n✓ staff_metrics found in performance data")
|
|
else:
|
|
print("\n✗ staff_metrics NOT found in performance data")
|
|
|
|
else:
|
|
print("✗ Performance data script tag NOT found")
|
|
|
|
# Check for chart containers
|
|
print("\n📊 Checking chart containers...")
|
|
charts = [
|
|
('complaintSourceChart', 'Complaint Source'),
|
|
('complaintStatusChart', 'Complaint Status'),
|
|
('complaintActivationChart', 'Complaint Activation Time'),
|
|
('complaintResponseChart', 'Complaint Response Time'),
|
|
('inquiryStatusChart', 'Inquiry Status'),
|
|
('inquiryResponseChart', 'Inquiry Response Time'),
|
|
]
|
|
|
|
for chart_id, chart_name in charts:
|
|
chart = page.query_selector(f'div#{chart_id}')
|
|
if chart:
|
|
print(f"✓ {chart_name} chart container found")
|
|
# Check if chart has any content (SVG from ApexCharts)
|
|
svg = chart.query_selector('svg')
|
|
if svg:
|
|
print(f" - Chart rendered (SVG present)")
|
|
else:
|
|
print(f" - Chart not yet rendered (no SVG)")
|
|
else:
|
|
print(f"✗ {chart_name} chart container NOT found")
|
|
|
|
# Check staff table
|
|
print("\n👥 Checking staff table...")
|
|
table = page.query_selector('table')
|
|
if table:
|
|
print("✓ Staff table found")
|
|
rows = table.query_selector_all('tbody tr')
|
|
print(f" - Found {len(rows)} staff members in table")
|
|
if rows:
|
|
print(f"\n Sample row data:")
|
|
first_row = rows[0]
|
|
cells = first_row.query_selector_all('td')
|
|
for i, cell in enumerate(cells[:4]):
|
|
print(f" Cell {i}: {cell.text_content()[:50]}")
|
|
else:
|
|
print("✗ Staff table NOT found")
|
|
|
|
# Check summary cards
|
|
print("\n📇 Checking summary cards...")
|
|
total_staff = page.query_selector('h2#totalStaff')
|
|
total_complaints = page.query_selector('h2#totalComplaints')
|
|
total_inquiries = page.query_selector('h2#totalInquiries')
|
|
resolution_rate = page.query_selector('h2#resolutionRate')
|
|
|
|
if total_complaints:
|
|
print(f"✓ Total complaints: {total_complaints.text_content()}")
|
|
if total_inquiries:
|
|
print(f"✓ Total inquiries: {total_inquiries.text_content()}")
|
|
if resolution_rate:
|
|
print(f"✓ Resolution rate: {resolution_rate.text_content()}")
|
|
|
|
# Take screenshot
|
|
screenshot_path = '/home/ismail/projects/HH/admin_evaluation_screenshot.png'
|
|
page.screenshot(path=screenshot_path)
|
|
print(f"\n📸 Screenshot saved to: {screenshot_path}")
|
|
|
|
browser.close()
|
|
|
|
print("\n" + "=" * 60)
|
|
print("✅ Dashboard test with data completed!")
|
|
|
|
if __name__ == '__main__':
|
|
test_admin_dashboard_with_data() |