File size: 4,479 Bytes
4c75d73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env python3
"""

Test script to verify that the private chat dropdown shows entity names instead of IDs

"""

import sys
import os

# Add the src directory to Python path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))

def test_dropdown_display_names():
    try:
        # Import required modules
        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...")
        
        # Get game instances
        facade = GameFacade()
        ui = HuggingFaceUI(facade)
        interface_manager = InterfaceManager(facade, ui)
        
        # Add test players
        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}")
        
        # Move players close to each other (same position)
        facade.move_player(player1_id, "right")  # Move to position (1, 0)
        facade.move_player(player2_id, "right")  # Move to position (1, 0)
        
        print("📍 Moved players to same position for proximity testing")
        
        # Test proximity info and dropdown choices
        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}")
        
        # Verify that choices contain human-readable names, not IDs
        if has_entities and choices:
            print("\n✅ Testing dropdown choices:")
            for choice in choices:
                print(f"   - Choice: '{choice}'")
                # Check if it's a human-readable name (not a UUID-like ID)
                if choice == "TestPlayer2":
                    print(f"     ✅ Correctly shows human-readable name!")
                elif len(choice) == 36 and '-' in choice:  # UUID format
                    print(f"     ❌ Still showing entity ID instead of name!")
                    return False
                else:
                    print(f"     ✅ Shows name: {choice}")
        
        # Test the name-to-ID mapping
        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}")
        
        # Test chat tab creation with display name
        if choices:
            selected_name = choices[0]  # Select first choice (should be a name)
            print(f"\n💬 Testing chat tab creation with: '{selected_name}'")
            
            # Simulate starting a chat (this should work with display names now)
            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}")
            
            # Verify that the tab was created with the correct entity ID
            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)