244 lines
10 KiB
Python
244 lines
10 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test script to validate the English base language implementation
|
|
Tests component-specific translations and initial language checks
|
|
"""
|
|
|
|
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_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_file_not_contains(file_path, search_terms, description):
|
|
"""Test if a file does NOT contain 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')
|
|
none_found = not any(term in content for term in search_terms)
|
|
status = "✅ PASS" if none_found else "❌ FAIL"
|
|
print(f"{status} - {description}")
|
|
|
|
if not none_found:
|
|
found = [term for term in search_terms if term in content]
|
|
print(f" Found unwanted terms: {found}")
|
|
|
|
return none_found
|
|
except Exception as e:
|
|
print(f"❌ FAIL - {description}: Error reading file - {e}")
|
|
return False
|
|
|
|
def run_tests():
|
|
"""Run all tests for the English base language implementation"""
|
|
print("🧪 Testing English Base Language Implementation")
|
|
print("=" * 60)
|
|
|
|
tests_passed = 0
|
|
total_tests = 0
|
|
|
|
# Test 1: LanguageProvider uses English as default
|
|
total_tests += 1
|
|
if test_file_contains("eveai_chat_client/static/assets/js/services/LanguageProvider.js",
|
|
["initialLanguage = 'en'", "Central language management system"],
|
|
"LanguageProvider uses English as default language"):
|
|
tests_passed += 1
|
|
|
|
# Test 2: LanguageProvider has component-specific translation function
|
|
total_tests += 1
|
|
if test_file_contains("eveai_chat_client/static/assets/js/services/LanguageProvider.js",
|
|
["translateComponentTexts", "component-specific", "targetLanguage === 'en'"],
|
|
"LanguageProvider has component-specific translation logic"):
|
|
tests_passed += 1
|
|
|
|
# Test 3: LanguageProvider forces initial translation for non-English languages
|
|
total_tests += 1
|
|
if test_file_contains("eveai_chat_client/static/assets/js/services/LanguageProvider.js",
|
|
["currentLanguage.value !== 'en'", "needs initial translation", "translateComponentTexts(componentName, currentLanguage.value)"],
|
|
"LanguageProvider forces initial translation for non-English languages"):
|
|
tests_passed += 1
|
|
|
|
# Test 4: ProgressTracker uses English original texts
|
|
total_tests += 1
|
|
if test_file_contains("eveai_chat_client/static/assets/vue-components/ProgressTracker.vue",
|
|
["Error while processing", "Processing completed", "Processing..."],
|
|
"ProgressTracker uses English original texts"):
|
|
tests_passed += 1
|
|
|
|
# Test 5: ProgressTracker does NOT use Dutch texts
|
|
total_tests += 1
|
|
if test_file_not_contains("eveai_chat_client/static/assets/vue-components/ProgressTracker.vue",
|
|
["Fout bij verwerking", "Verwerking voltooid", "Bezig met redeneren"],
|
|
"ProgressTracker does not use Dutch texts"):
|
|
tests_passed += 1
|
|
|
|
# Test 6: ChatMessage uses English original texts
|
|
total_tests += 1
|
|
if test_file_contains("eveai_chat_client/static/assets/vue-components/ChatMessage.vue",
|
|
["Try again", "Copy", "Timestamp", "An error occurred while processing"],
|
|
"ChatMessage uses English original texts"):
|
|
tests_passed += 1
|
|
|
|
# Test 7: ChatMessage does NOT use Dutch texts
|
|
total_tests += 1
|
|
if test_file_not_contains("eveai_chat_client/static/assets/vue-components/ChatMessage.vue",
|
|
["Opnieuw proberen", "Kopiëren", "Tijdstempel", "Er is een fout opgetreden"],
|
|
"ChatMessage does not use Dutch texts"):
|
|
tests_passed += 1
|
|
|
|
# Test 8: SideBarExplanation uses English as default language
|
|
total_tests += 1
|
|
if test_file_contains("eveai_chat_client/static/assets/vue-components/SideBarExplanation.vue",
|
|
["default: 'en'", "Translating..."],
|
|
"SideBarExplanation uses English as default language"):
|
|
tests_passed += 1
|
|
|
|
# Test 9: LanguageProvider handles English base language correctly
|
|
total_tests += 1
|
|
if test_file_contains("eveai_chat_client/static/assets/js/services/LanguageProvider.js",
|
|
["For English, use original texts", "no translation needed", "Start with original English texts"],
|
|
"LanguageProvider handles English base language correctly"):
|
|
tests_passed += 1
|
|
|
|
# Test 10: LanguageProvider has proper logging for debugging
|
|
total_tests += 1
|
|
if test_file_contains("eveai_chat_client/static/assets/js/services/LanguageProvider.js",
|
|
["console.log", "Registering component", "needs initial translation", "Successfully translated"],
|
|
"LanguageProvider has proper logging for debugging"):
|
|
tests_passed += 1
|
|
|
|
print("\n" + "=" * 60)
|
|
print(f"🧪 Test Results: {tests_passed}/{total_tests} tests passed")
|
|
|
|
if tests_passed == total_tests:
|
|
print("🎉 All tests passed! English base language implementation looks good.")
|
|
print("\n✅ Key improvements implemented:")
|
|
print(" - English is now the base language for all components")
|
|
print(" - Component-specific caching prevents cross-contamination")
|
|
print(" - Initial language translation works at component registration")
|
|
print(" - No fallback to Dutch - English is the source language")
|
|
print(" - Proper logging for debugging translation issues")
|
|
return True
|
|
else:
|
|
print(f"⚠️ {total_tests - tests_passed} tests failed. Please review the implementation.")
|
|
return False
|
|
|
|
def check_cache_logic():
|
|
"""Check the cache logic implementation"""
|
|
print("\n🔍 Checking Cache Logic Implementation")
|
|
print("=" * 50)
|
|
|
|
issues_found = 0
|
|
|
|
# Check if global cache is still being used incorrectly
|
|
language_provider_path = project_root / "eveai_chat_client/static/assets/js/services/LanguageProvider.js"
|
|
if language_provider_path.exists():
|
|
content = language_provider_path.read_text(encoding='utf-8')
|
|
|
|
# Check for component-specific cache
|
|
if 'componentTranslations[componentName]' in content:
|
|
print("✅ Component-specific cache implementation found")
|
|
else:
|
|
print("⚠️ Component-specific cache not properly implemented")
|
|
issues_found += 1
|
|
|
|
# Check for proper English base language handling
|
|
if "targetLanguage === 'en'" in content:
|
|
print("✅ English base language handling found")
|
|
else:
|
|
print("⚠️ English base language handling not found")
|
|
issues_found += 1
|
|
|
|
# Check for initial translation logic
|
|
if "needs initial translation" in content:
|
|
print("✅ Initial translation logic found")
|
|
else:
|
|
print("⚠️ Initial translation logic not found")
|
|
issues_found += 1
|
|
|
|
if issues_found == 0:
|
|
print("✅ Cache logic implementation looks good")
|
|
else:
|
|
print(f"⚠️ {issues_found} issue(s) found in cache logic")
|
|
|
|
return issues_found == 0
|
|
|
|
def check_startup_behavior():
|
|
"""Check startup behavior for different language scenarios"""
|
|
print("\n🔍 Checking Startup Behavior")
|
|
print("=" * 50)
|
|
|
|
print("📋 Expected startup behavior:")
|
|
print(" 1. App starts with chatConfig.language (e.g., 'nl', 'fr', 'de')")
|
|
print(" 2. Components register with English original texts")
|
|
print(" 3. If initial language ≠ 'en', automatic translation is triggered")
|
|
print(" 4. Cache is populated with correct translations for initial language")
|
|
print(" 5. No fallback to Dutch - English is always the source")
|
|
|
|
# Check chat.html for language configuration
|
|
chat_html_path = project_root / "eveai_chat_client/templates/chat.html"
|
|
if chat_html_path.exists():
|
|
content = chat_html_path.read_text(encoding='utf-8')
|
|
if "language: '{{ session.magic_link.specialist_args.language|default(" in content:
|
|
print("✅ Dynamic language configuration found in chat.html")
|
|
if '|default("nl")' in content:
|
|
print("⚠️ Default language in chat.html is still 'nl' - consider changing to 'en'")
|
|
elif '|default("en")' in content:
|
|
print("✅ Default language in chat.html is 'en'")
|
|
else:
|
|
print("⚠️ Language configuration not found in chat.html")
|
|
|
|
return True
|
|
|
|
if __name__ == "__main__":
|
|
print("🚀 English Base Language Implementation Test Suite")
|
|
print("Testing component-specific translations with English as base language")
|
|
print("=" * 70)
|
|
|
|
# Run main tests
|
|
success = run_tests()
|
|
|
|
# Check cache logic
|
|
cache_ok = check_cache_logic()
|
|
|
|
# Check startup behavior
|
|
startup_ok = check_startup_behavior()
|
|
|
|
if success and cache_ok and startup_ok:
|
|
print("\n✅ Implementation validation successful!")
|
|
print("🎯 The system now uses English as the base language with proper component-specific caching.")
|
|
print("🔧 Initial language translation should work correctly at startup.")
|
|
sys.exit(0)
|
|
else:
|
|
print("\n❌ Implementation validation failed!")
|
|
print("Please review and fix the issues before testing in browser.")
|
|
sys.exit(1) |