File size: 5,668 Bytes
b13d35c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
"""

Test UI functionality to ensure all components work properly

"""
import pytest
import sys
import os

# Add parent directory to path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from app import ArbitrageDashboard


def test_dashboard_initialization():
    """Test that ArbitrageDashboard can be initialized"""
    dashboard = ArbitrageDashboard()
    assert dashboard is not None
    assert dashboard.arbitrage_system is not None
    assert dashboard.execution_history == []
    assert dashboard.performance_data == []
    print("βœ“ Dashboard initialization works")


def test_system_status_display():
    """Test system status display generation"""
    dashboard = ArbitrageDashboard()
    status = dashboard.get_system_status_display()
    
    assert status is not None
    assert isinstance(status, str)
    assert len(status) > 0
    assert "System Status" in status or "AI Model" in status
    print("βœ“ System status display works")


def test_strategies_info_display():
    """Test strategies information display"""
    dashboard = ArbitrageDashboard()
    info = dashboard.get_strategies_info_display()
    
    assert info is not None
    assert isinstance(info, str)
    assert len(info) > 0
    print("βœ“ Strategies info display works")


def test_core_diagnostics():
    """Test core diagnostics generation"""
    dashboard = ArbitrageDashboard()
    diag = dashboard.get_core_diagnostics()
    
    assert diag is not None
    assert isinstance(diag, str)
    assert len(diag) > 0
    assert "CORE COMPONENTS" in diag or "AI Model" in diag
    print("βœ“ Core diagnostics works")


def test_data_diagnostics():
    """Test data diagnostics generation"""
    dashboard = ArbitrageDashboard()
    diag = dashboard.get_data_diagnostics()
    
    assert diag is not None
    assert isinstance(diag, str)
    assert len(diag) > 0
    assert "DATA ENGINE" in diag or "CEX" in diag or "DEX" in diag
    print("βœ“ Data diagnostics works")


def test_refresh_diagnostics():
    """Test diagnostics refresh"""
    dashboard = ArbitrageDashboard()
    result = dashboard.refresh_diagnostics()
    
    assert result is not None
    assert isinstance(result, tuple)
    assert len(result) == 3
    assert all(isinstance(r, str) for r in result)
    print("βœ“ Refresh diagnostics works")


def test_strategy_performance_chart():
    """Test strategy performance chart generation"""
    dashboard = ArbitrageDashboard()
    chart = dashboard.create_strategy_performance_chart()
    
    assert chart is not None
    # It should return a plotly Figure object
    assert hasattr(chart, 'data')
    print("βœ“ Strategy performance chart works")


def test_market_heatmap():
    """Test market heatmap generation"""
    dashboard = ArbitrageDashboard()
    heatmap = dashboard.create_market_heatmap()
    
    assert heatmap is not None
    assert hasattr(heatmap, 'data')
    print("βœ“ Market heatmap works")


def test_risk_analysis():
    """Test risk analysis generation"""
    dashboard = ArbitrageDashboard()
    analysis = dashboard.generate_risk_analysis()
    
    assert analysis is not None
    assert isinstance(analysis, str)
    assert len(analysis) > 0
    print("βœ“ Risk analysis works")


def test_refresh_analytics():
    """Test analytics refresh"""
    dashboard = ArbitrageDashboard()
    result = dashboard.refresh_analytics()
    
    assert result is not None
    assert isinstance(result, tuple)
    assert len(result) == 3
    # First two should be charts, last should be string
    assert hasattr(result[0], 'data')  # Chart
    assert hasattr(result[1], 'data')  # Chart
    assert isinstance(result[2], str)  # Risk analysis
    print("βœ“ Refresh analytics works")


def test_opportunity_details_generation():
    """Test opportunity details generation with no data"""
    dashboard = ArbitrageDashboard()
    details = dashboard.generate_opportunity_details(-1)
    
    assert details is not None
    assert isinstance(details, str)
    assert "Select an opportunity" in details or "No opportunity data" in details
    print("βœ“ Opportunity details generation works")


def test_show_opportunity_details_from_dropdown():
    """Test showing opportunity details from dropdown with no selection"""
    dashboard = ArbitrageDashboard()
    details = dashboard.show_opportunity_details_from_dropdown(None)
    
    assert details is not None
    assert isinstance(details, str)
    assert "No opportunity" in details
    print("βœ“ Show opportunity details from dropdown works")


def test_performance_chart_creation():
    """Test performance chart creation"""
    dashboard = ArbitrageDashboard()
    chart = dashboard.create_performance_chart()
    
    assert chart is not None
    assert hasattr(chart, 'data')
    print("βœ“ Performance chart creation works")


if __name__ == "__main__":
    print("\n" + "="*70)
    print("TESTING UI FUNCTIONALITY")
    print("="*70 + "\n")
    
    test_dashboard_initialization()
    test_system_status_display()
    test_strategies_info_display()
    test_core_diagnostics()
    test_data_diagnostics()
    test_refresh_diagnostics()
    test_strategy_performance_chart()
    test_market_heatmap()
    test_risk_analysis()
    test_refresh_analytics()
    test_opportunity_details_generation()
    test_show_opportunity_details_from_dropdown()
    test_performance_chart_creation()
    
    print("\n" + "="*70)
    print("ALL UI TESTS PASSED! βœ“")
    print("="*70)