|
|
|
"""
|
|
Test script to verify that the private chat dropdown shows entity names instead of IDs
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
|
|
|
|
def test_dropdown_display_names():
|
|
try:
|
|
|
|
from src.core.game_engine import get_game_engine
|
|
from src.facades.game_facade import GameFacade
|
|
from src.ui.interface_manager import InterfaceManager
|
|
from src.ui.huggingface_ui import HuggingFaceUI
|
|
|
|
print("🧪 Testing Private Chat Dropdown Display Names...")
|
|
|
|
|
|
facade = GameFacade()
|
|
ui = HuggingFaceUI(facade)
|
|
interface_manager = InterfaceManager(facade, ui)
|
|
|
|
|
|
player1_id = facade.join_game('TestPlayer1')
|
|
player2_id = facade.join_game('TestPlayer2')
|
|
|
|
print(f"✅ Created players:")
|
|
print(f" - TestPlayer1: {player1_id}")
|
|
print(f" - TestPlayer2: {player2_id}")
|
|
|
|
|
|
facade.move_player(player1_id, "right")
|
|
facade.move_player(player2_id, "right")
|
|
|
|
print("📍 Moved players to same position for proximity testing")
|
|
|
|
|
|
proximity_html, choices, has_entities = interface_manager._get_proximity_info(player1_id)
|
|
|
|
print(f"🔍 Proximity detection result:")
|
|
print(f" - Has nearby entities: {has_entities}")
|
|
print(f" - Number of choices: {len(choices)}")
|
|
print(f" - Choices: {choices}")
|
|
|
|
|
|
if has_entities and choices:
|
|
print("\n✅ Testing dropdown choices:")
|
|
for choice in choices:
|
|
print(f" - Choice: '{choice}'")
|
|
|
|
if choice == "TestPlayer2":
|
|
print(f" ✅ Correctly shows human-readable name!")
|
|
elif len(choice) == 36 and '-' in choice:
|
|
print(f" ❌ Still showing entity ID instead of name!")
|
|
return False
|
|
else:
|
|
print(f" ✅ Shows name: {choice}")
|
|
|
|
|
|
print(f"\n🗺️ Entity name-to-ID mapping:")
|
|
for name, entity_id in interface_manager.entity_name_to_id.items():
|
|
print(f" - '{name}' -> {entity_id}")
|
|
|
|
|
|
if choices:
|
|
selected_name = choices[0]
|
|
print(f"\n💬 Testing chat tab creation with: '{selected_name}'")
|
|
|
|
|
|
chat_tabs_state = {}
|
|
current_state = {"joined": True, "player_id": player1_id}
|
|
|
|
result = interface_manager._handle_start_chat(
|
|
selected_name,
|
|
chat_tabs_state,
|
|
current_state
|
|
)
|
|
|
|
print(f"📋 Chat tab creation result:")
|
|
print(f" - Tab state: {chat_tabs_state}")
|
|
|
|
|
|
if chat_tabs_state:
|
|
for entity_id, tab_info in chat_tabs_state.items():
|
|
print(f" - Entity ID: {entity_id}")
|
|
print(f" - Display name: {tab_info['name']}")
|
|
if tab_info['name'] == selected_name:
|
|
print(" ✅ Tab created successfully with correct name!")
|
|
else:
|
|
print(" ❌ Tab name mismatch!")
|
|
return False
|
|
|
|
print("\n✅ All dropdown display name tests passed!")
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f"❌ Test failed: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
success = test_dropdown_display_names()
|
|
sys.exit(0 if success else 1)
|
|
|