149 lines
5.9 KiB
Python
149 lines
5.9 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test script to validate the Sidebar LanguageProvider fix
|
|
Tests that both SideBar and ChatApp have access to LanguageProvider
|
|
"""
|
|
|
|
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 run_tests():
|
|
"""Run all tests for the Sidebar LanguageProvider fix"""
|
|
print("🧪 Testing Sidebar LanguageProvider Fix")
|
|
print("=" * 50)
|
|
|
|
tests_passed = 0
|
|
total_tests = 0
|
|
|
|
# Test 1: chat-client.js imports LanguageProvider
|
|
total_tests += 1
|
|
if test_file_contains("nginx/frontend_src/js/chat-client.js",
|
|
["import { createLanguageProvider, LANGUAGE_PROVIDER_KEY }"],
|
|
"chat-client.js imports LanguageProvider"):
|
|
tests_passed += 1
|
|
|
|
# Test 2: initializeSidebar creates and provides LanguageProvider
|
|
total_tests += 1
|
|
if test_file_contains("nginx/frontend_src/js/chat-client.js",
|
|
["createLanguageProvider(initialLanguage, apiPrefix)", "app.provide(LANGUAGE_PROVIDER_KEY, languageProvider)"],
|
|
"initializeSidebar creates and provides LanguageProvider"):
|
|
tests_passed += 1
|
|
|
|
# Test 3: SideBar app listens to language-changed events
|
|
total_tests += 1
|
|
if test_file_contains("nginx/frontend_src/js/chat-client.js",
|
|
["languageChangeHandler", "document.addEventListener('language-changed'", "languageProvider.setLanguage"],
|
|
"SideBar app listens to language-changed events"):
|
|
tests_passed += 1
|
|
|
|
# Test 4: SideBarExplanation uses useComponentTranslations
|
|
total_tests += 1
|
|
if test_file_contains("eveai_chat_client/static/assets/vue-components/SideBarExplanation.vue",
|
|
["useComponentTranslations", "sidebar_explanation"],
|
|
"SideBarExplanation uses useComponentTranslations"):
|
|
tests_passed += 1
|
|
|
|
# Test 5: ChatApp still provides LanguageProvider
|
|
total_tests += 1
|
|
if test_file_contains("eveai_chat_client/static/assets/vue-components/ChatApp.vue",
|
|
["createLanguageProvider", "provide(LANGUAGE_PROVIDER_KEY"],
|
|
"ChatApp still provides LanguageProvider"):
|
|
tests_passed += 1
|
|
|
|
print("\n" + "=" * 50)
|
|
print(f"🧪 Test Results: {tests_passed}/{total_tests} tests passed")
|
|
|
|
if tests_passed == total_tests:
|
|
print("🎉 All tests passed! Sidebar LanguageProvider fix looks good.")
|
|
print("\n✅ Expected fixes:")
|
|
print(" - SideBarExplanation should no longer throw 'useLanguageProvider must be used within a LanguageProvider' error")
|
|
print(" - Sidebar explanation text should be visible and translatable")
|
|
print(" - Both sidebar and chat translations should work correctly")
|
|
return True
|
|
else:
|
|
print(f"⚠️ {total_tests - tests_passed} tests failed. Please review the implementation.")
|
|
return False
|
|
|
|
def check_potential_issues():
|
|
"""Check for potential issues with the implementation"""
|
|
print("\n🔍 Checking for Potential Issues")
|
|
print("=" * 50)
|
|
|
|
issues_found = 0
|
|
|
|
# Check if both apps create separate LanguageProvider instances
|
|
chat_client_path = project_root / "nginx/frontend_src/js/chat-client.js"
|
|
if chat_client_path.exists():
|
|
content = chat_client_path.read_text(encoding='utf-8')
|
|
provider_creations = content.count('createLanguageProvider(')
|
|
if provider_creations >= 1:
|
|
print(f"✅ Found {provider_creations} LanguageProvider creation(s) in chat-client.js")
|
|
else:
|
|
print("⚠️ No LanguageProvider creation found in chat-client.js")
|
|
issues_found += 1
|
|
|
|
# Check if ChatApp also creates LanguageProvider
|
|
chatapp_path = project_root / "eveai_chat_client/static/assets/vue-components/ChatApp.vue"
|
|
if chatapp_path.exists():
|
|
content = chatapp_path.read_text(encoding='utf-8')
|
|
if 'createLanguageProvider(' in content:
|
|
print("✅ ChatApp creates LanguageProvider")
|
|
else:
|
|
print("⚠️ ChatApp doesn't create LanguageProvider")
|
|
issues_found += 1
|
|
|
|
if issues_found == 0:
|
|
print("✅ No potential issues detected")
|
|
else:
|
|
print(f"⚠️ {issues_found} potential issue(s) detected")
|
|
|
|
return issues_found == 0
|
|
|
|
if __name__ == "__main__":
|
|
print("🚀 Sidebar LanguageProvider Fix Test Suite")
|
|
print("Testing fix for 'useLanguageProvider must be used within a LanguageProvider' error")
|
|
print("=" * 70)
|
|
|
|
# Run tests
|
|
success = run_tests()
|
|
|
|
# Check for potential issues
|
|
no_issues = check_potential_issues()
|
|
|
|
if success and no_issues:
|
|
print("\n✅ Implementation validation successful!")
|
|
print("The sidebar should now have access to LanguageProvider and translations should work.")
|
|
sys.exit(0)
|
|
else:
|
|
print("\n❌ Implementation validation failed!")
|
|
print("Please review and fix the issues before testing in browser.")
|
|
sys.exit(1) |