#!/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()