103 lines
3.9 KiB
Python
103 lines
3.9 KiB
Python
"""
|
|
Test script to verify ApexCharts fix in admin evaluation dashboard
|
|
"""
|
|
import os
|
|
import sys
|
|
import django
|
|
from playwright.sync_api import sync_playwright
|
|
|
|
# Setup Django
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.base')
|
|
sys.path.insert(0, '/home/ismail/projects/HH')
|
|
django.setup()
|
|
|
|
def test_admin_dashboard_charts():
|
|
"""Test that admin evaluation dashboard loads without ApexCharts errors"""
|
|
print("Testing admin evaluation dashboard with ApexCharts fix...")
|
|
|
|
with sync_playwright() as p:
|
|
browser = p.chromium.launch(headless=True)
|
|
page = browser.new_page()
|
|
|
|
try:
|
|
# Navigate to admin evaluation page
|
|
print("\n1. Navigating to admin evaluation page...")
|
|
page.goto('http://localhost:8000/admin-evaluation/')
|
|
page.wait_for_load_state('networkidle')
|
|
|
|
# Wait for page to load
|
|
page.wait_for_selector('body', timeout=10000)
|
|
print("✓ Page loaded successfully")
|
|
|
|
# Check for JavaScript errors
|
|
errors = []
|
|
page.on('console', lambda msg: errors.append(msg.text) if msg.type == 'error' else None)
|
|
|
|
# Wait a bit for charts to initialize
|
|
page.wait_for_timeout(3000)
|
|
|
|
# Check if any ApexCharts errors occurred
|
|
apex_errors = [e for e in errors if 'ApexCharts' in e or 'apexcharts' in e.lower()]
|
|
|
|
if apex_errors:
|
|
print("\n✗ ApexCharts errors found:")
|
|
for error in apex_errors:
|
|
print(f" - {error}")
|
|
return False
|
|
else:
|
|
print("\n✓ No ApexCharts errors detected")
|
|
|
|
# Check if chart containers exist
|
|
chart_ids = [
|
|
'complaintSourceChart',
|
|
'complaintStatusChart',
|
|
'complaintActivationChart',
|
|
'complaintResponseChart',
|
|
'inquiryStatusChart',
|
|
'inquiryResponseChart'
|
|
]
|
|
|
|
print("\n2. Checking chart containers...")
|
|
for chart_id in chart_ids:
|
|
chart = page.query_selector(f'#{chart_id}')
|
|
if chart:
|
|
print(f" ✓ Chart container found: {chart_id}")
|
|
else:
|
|
print(f" ✗ Chart container missing: {chart_id}")
|
|
return False
|
|
|
|
# Check if charts have SVG elements (rendered)
|
|
print("\n3. Checking if charts rendered...")
|
|
svg_elements = page.query_selector_all('svg')
|
|
if len(svg_elements) >= len(chart_ids):
|
|
print(f" ✓ {len(svg_elements)} chart elements found (expected at least {len(chart_ids)})")
|
|
else:
|
|
print(f" ⚠ Only {len(svg_elements)} SVG elements found (expected {len(chart_ids)})")
|
|
|
|
# Take screenshot
|
|
print("\n4. Taking screenshot...")
|
|
page.screenshot(path='admin_charts_test.png', full_page=True)
|
|
print(" ✓ Screenshot saved to admin_charts_test.png")
|
|
|
|
# Check for any console errors (not just ApexCharts)
|
|
if errors:
|
|
print(f"\n⚠ Found {len(errors)} console errors:")
|
|
for error in errors[:5]: # Show first 5 errors
|
|
print(f" - {error}")
|
|
else:
|
|
print("\n✓ No console errors detected")
|
|
|
|
print("\n✓ Test completed successfully!")
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f"\n✗ Test failed with error: {str(e)}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
return False
|
|
finally:
|
|
browser.close()
|
|
|
|
if __name__ == '__main__':
|
|
success = test_admin_dashboard_charts()
|
|
sys.exit(0 if success else 1) |