219 lines
8.8 KiB
Python
219 lines
8.8 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test script to validate the Language Provider implementation
|
|
Tests the provider/inject pattern for translation management
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import subprocess
|
|
import time
|
|
from pathlib import Path
|
|
|
|
# Add project root to path
|
|
project_root = Path(__file__).parent
|
|
sys.path.append(str(project_root))
|
|
|
|
def test_file_exists(file_path, description):
|
|
"""Test if a file exists"""
|
|
full_path = project_root / file_path
|
|
exists = full_path.exists()
|
|
status = "✅ PASS" if exists else "❌ FAIL"
|
|
print(f"{status} - {description}: {file_path}")
|
|
return exists
|
|
|
|
def test_file_contains(file_path, search_terms, description):
|
|
"""Test if a file contains specific terms"""
|
|
full_path = project_root / file_path
|
|
if not full_path.exists():
|
|
print(f"❌ FAIL - {description}: File not found - {file_path}")
|
|
return False
|
|
|
|
try:
|
|
content = full_path.read_text(encoding='utf-8')
|
|
all_found = all(term in content for term in search_terms)
|
|
status = "✅ PASS" if all_found else "❌ FAIL"
|
|
print(f"{status} - {description}")
|
|
|
|
if not all_found:
|
|
missing = [term for term in search_terms if term not in content]
|
|
print(f" Missing terms: {missing}")
|
|
|
|
return all_found
|
|
except Exception as e:
|
|
print(f"❌ FAIL - {description}: Error reading file - {e}")
|
|
return False
|
|
|
|
def test_javascript_syntax(file_path, description):
|
|
"""Test JavaScript syntax using Node.js if available"""
|
|
full_path = project_root / file_path
|
|
if not full_path.exists():
|
|
print(f"❌ FAIL - {description}: File not found")
|
|
return False
|
|
|
|
try:
|
|
# Try to check syntax with node if available
|
|
result = subprocess.run(['node', '-c', str(full_path)],
|
|
capture_output=True, text=True, timeout=10)
|
|
if result.returncode == 0:
|
|
print(f"✅ PASS - {description}: JavaScript syntax valid")
|
|
return True
|
|
else:
|
|
print(f"❌ FAIL - {description}: JavaScript syntax error")
|
|
print(f" Error: {result.stderr}")
|
|
return False
|
|
except (subprocess.TimeoutExpired, FileNotFoundError):
|
|
print(f"⚠️ SKIP - {description}: Node.js not available for syntax check")
|
|
return True # Don't fail if Node.js is not available
|
|
|
|
def run_tests():
|
|
"""Run all tests for the Language Provider implementation"""
|
|
print("🧪 Testing Language Provider Implementation")
|
|
print("=" * 50)
|
|
|
|
tests_passed = 0
|
|
total_tests = 0
|
|
|
|
# Test 1: LanguageProvider service exists
|
|
total_tests += 1
|
|
if test_file_exists("eveai_chat_client/static/assets/js/services/LanguageProvider.js",
|
|
"LanguageProvider service file exists"):
|
|
tests_passed += 1
|
|
|
|
# Test 2: LanguageProvider contains required exports
|
|
total_tests += 1
|
|
if test_file_contains("eveai_chat_client/static/assets/js/services/LanguageProvider.js",
|
|
["createLanguageProvider", "useLanguageProvider", "useComponentTranslations", "LANGUAGE_PROVIDER_KEY"],
|
|
"LanguageProvider exports required functions"):
|
|
tests_passed += 1
|
|
|
|
# Test 3: ChatApp.vue provides the language provider
|
|
total_tests += 1
|
|
if test_file_contains("eveai_chat_client/static/assets/vue-components/ChatApp.vue",
|
|
["createLanguageProvider", "provide", "LANGUAGE_PROVIDER_KEY"],
|
|
"ChatApp.vue provides language provider"):
|
|
tests_passed += 1
|
|
|
|
# Test 4: ProgressTracker uses component translations
|
|
total_tests += 1
|
|
if test_file_contains("eveai_chat_client/static/assets/vue-components/ProgressTracker.vue",
|
|
["useComponentTranslations", "progress_tracker"],
|
|
"ProgressTracker uses component translations"):
|
|
tests_passed += 1
|
|
|
|
# Test 5: SideBarExplanation uses component translations
|
|
total_tests += 1
|
|
if test_file_contains("eveai_chat_client/static/assets/vue-components/SideBarExplanation.vue",
|
|
["useComponentTranslations", "sidebar_explanation"],
|
|
"SideBarExplanation uses component translations"):
|
|
tests_passed += 1
|
|
|
|
# Test 6: ChatMessage uses component translations
|
|
total_tests += 1
|
|
if test_file_contains("eveai_chat_client/static/assets/vue-components/ChatMessage.vue",
|
|
["useComponentTranslations", "chat_message"],
|
|
"ChatMessage uses component translations"):
|
|
tests_passed += 1
|
|
|
|
# Test 7: LanguageSelector optionally uses provider
|
|
total_tests += 1
|
|
if test_file_contains("eveai_chat_client/static/assets/vue-components/LanguageSelector.vue",
|
|
["useLanguageProvider", "providerLanguage", "effectiveCurrentLanguage"],
|
|
"LanguageSelector optionally uses provider"):
|
|
tests_passed += 1
|
|
|
|
# Test 8: Check JavaScript syntax of LanguageProvider
|
|
total_tests += 1
|
|
if test_javascript_syntax("eveai_chat_client/static/assets/js/services/LanguageProvider.js",
|
|
"LanguageProvider JavaScript syntax"):
|
|
tests_passed += 1
|
|
|
|
# Test 9: Verify old event-based code is removed from ProgressTracker
|
|
total_tests += 1
|
|
progress_tracker_path = "eveai_chat_client/static/assets/vue-components/ProgressTracker.vue"
|
|
full_path = project_root / progress_tracker_path
|
|
if full_path.exists():
|
|
content = full_path.read_text(encoding='utf-8')
|
|
old_patterns = ["handleLanguageChange", "language-changed", "translateConstants"]
|
|
has_old_code = any(pattern in content for pattern in old_patterns)
|
|
if not has_old_code:
|
|
print("✅ PASS - ProgressTracker: Old event-based translation code removed")
|
|
tests_passed += 1
|
|
else:
|
|
print("❌ FAIL - ProgressTracker: Still contains old event-based translation code")
|
|
else:
|
|
print("❌ FAIL - ProgressTracker: File not found")
|
|
|
|
# Test 10: Verify old event-based code is removed from ChatMessage
|
|
total_tests += 1
|
|
chat_message_path = "eveai_chat_client/static/assets/vue-components/ChatMessage.vue"
|
|
full_path = project_root / chat_message_path
|
|
if full_path.exists():
|
|
content = full_path.read_text(encoding='utf-8')
|
|
old_patterns = ["handleLanguageChange", "language-changed"]
|
|
has_old_code = any(pattern in content for pattern in old_patterns)
|
|
if not has_old_code:
|
|
print("✅ PASS - ChatMessage: Old event-based translation code removed")
|
|
tests_passed += 1
|
|
else:
|
|
print("❌ FAIL - ChatMessage: Still contains old event-based translation code")
|
|
else:
|
|
print("❌ FAIL - ChatMessage: File not found")
|
|
|
|
print("\n" + "=" * 50)
|
|
print(f"🧪 Test Results: {tests_passed}/{total_tests} tests passed")
|
|
|
|
if tests_passed == total_tests:
|
|
print("🎉 All tests passed! Language Provider implementation looks good.")
|
|
return True
|
|
else:
|
|
print(f"⚠️ {total_tests - tests_passed} tests failed. Please review the implementation.")
|
|
return False
|
|
|
|
def check_implementation_completeness():
|
|
"""Check if the implementation is complete"""
|
|
print("\n🔍 Checking Implementation Completeness")
|
|
print("=" * 50)
|
|
|
|
# Check if all required files exist
|
|
required_files = [
|
|
"eveai_chat_client/static/assets/js/services/LanguageProvider.js",
|
|
"eveai_chat_client/static/assets/vue-components/ChatApp.vue",
|
|
"eveai_chat_client/static/assets/vue-components/ProgressTracker.vue",
|
|
"eveai_chat_client/static/assets/vue-components/SideBarExplanation.vue",
|
|
"eveai_chat_client/static/assets/vue-components/ChatMessage.vue",
|
|
"eveai_chat_client/static/assets/vue-components/LanguageSelector.vue"
|
|
]
|
|
|
|
all_exist = True
|
|
for file_path in required_files:
|
|
full_path = project_root / file_path
|
|
if full_path.exists():
|
|
print(f"✅ {file_path}")
|
|
else:
|
|
print(f"❌ {file_path} - MISSING")
|
|
all_exist = False
|
|
|
|
return all_exist
|
|
|
|
if __name__ == "__main__":
|
|
print("🚀 Language Provider Implementation Test Suite")
|
|
print("Testing provider/inject pattern for translation management")
|
|
print("=" * 60)
|
|
|
|
# Check completeness first
|
|
if not check_implementation_completeness():
|
|
print("\n❌ Implementation incomplete. Please ensure all files exist.")
|
|
sys.exit(1)
|
|
|
|
# Run tests
|
|
success = run_tests()
|
|
|
|
if success:
|
|
print("\n✅ Implementation validation successful!")
|
|
print("The provider/inject pattern should resolve timing issues.")
|
|
sys.exit(0)
|
|
else:
|
|
print("\n❌ Implementation validation failed!")
|
|
print("Please review and fix the issues before proceeding.")
|
|
sys.exit(1) |