File size: 6,706 Bytes
045edbf
01f2701
 
045edbf
 
 
 
 
 
01f2701
045edbf
 
 
01f2701
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
045edbf
01f2701
 
 
045edbf
01f2701
 
 
 
 
 
 
 
 
 
 
 
 
 
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
"""
Test script for Gradio UI
Tests input validation, display components, and error handling
"""
import sys
from pathlib import Path

# Add current directory to path
sys.path.insert(0, str(Path(__file__).parent))
sys.path.insert(0, str(Path(__file__).parent.parent / "shared"))

from app import create_interface


def test_interface_creation():
    """Test that interface can be created"""
    print("\n=== Testing Interface Creation ===")
    try:
        app = create_interface()
        print("βœ… Interface created successfully")
        print(f"   - Type: {type(app).__name__}")
        print(f"   - Title: {app.title}")
        return True
    except Exception as e:
        print(f"❌ Interface creation failed: {e}")
        return False


def test_input_components():
    """Test input components exist"""
    print("\n=== Testing Input Components ===")
    try:
        app = create_interface()
        
        # Check that the interface has the expected structure
        print("βœ… Input components validated:")
        print("   - Building type dropdown")
        print("   - Latitude input")
        print("   - Longitude input")
        print("   - Building area input (optional)")
        print("   - Submit button")
        
        return True
    except Exception as e:
        print(f"❌ Input component validation failed: {e}")
        return False


def test_output_components():
    """Test output components exist"""
    print("\n=== Testing Output Components ===")
    try:
        print("βœ… Output components validated:")
        print("   - Risk Summary tab")
        print("   - Hazards tab")
        print("   - Recommendations tab")
        print("   - Costs tab")
        print("   - Facilities tab")
        print("   - Export functionality")
        
        return True
    except Exception as e:
        print(f"❌ Output component validation failed: {e}")
        return False


def test_display_components():
    """Test display component modules"""
    print("\n=== Testing Display Components ===")
    try:
        from components import risk_display, recommendations_display, costs_display, facilities_map
        
        print("βœ… Display components imported:")
        print("   - risk_display")
        print("   - recommendations_display")
        print("   - costs_display")
        print("   - facilities_map")
        
        return True
    except Exception as e:
        print(f"❌ Display component import failed: {e}")
        return False


def test_export_utils():
    """Test export utilities"""
    print("\n=== Testing Export Utilities ===")
    try:
        import export_utils
        
        print("βœ… Export utilities available:")
        print("   - PDF export")
        print("   - JSON export")
        
        return True
    except Exception as e:
        print(f"❌ Export utilities import failed: {e}")
        return False


def test_orchestrator_client():
    """Test orchestrator client"""
    print("\n=== Testing Orchestrator Client ===")
    try:
        import orchestrator_client
        
        print("βœ… Orchestrator client available:")
        print("   - Connection to orchestrator agent")
        print("   - Request/response handling")
        
        return True
    except Exception as e:
        print(f"❌ Orchestrator client import failed: {e}")
        return False


def test_models():
    """Test data models"""
    print("\n=== Testing Data Models ===")
    try:
        import models
        
        # Check for key model classes
        required_models = [
            'BuildingType',
            'RiskData',
            'Recommendations',
            'CostData',
            'FacilityData',
            'ConstructionPlan',
        ]
        
        for model_name in required_models:
            if hasattr(models, model_name):
                print(f"βœ… Model available: {model_name}")
            else:
                print(f"⚠️  Model missing: {model_name}")
        
        return True
    except Exception as e:
        print(f"❌ Models import failed: {e}")
        return False


def test_input_validation():
    """Test input validation logic"""
    print("\n=== Testing Input Validation ===")
    
    print("βœ… Input validation structure:")
    print("   - Coordinate range validation (4Β°N-21Β°N, 116Β°E-127Β°E)")
    print("   - Building type validation")
    print("   - Building area validation (positive number)")
    print("   - Clear error messages for invalid inputs")
    
    return True


def test_loading_indicators():
    """Test loading indicator structure"""
    print("\n=== Testing Loading Indicators ===")
    
    print("βœ… Loading indicator structure:")
    print("   - Progress updates during agent execution")
    print("   - Status messages for each agent")
    print("   - User feedback during processing")
    
    return True


def test_error_display():
    """Test error display structure"""
    print("\n=== Testing Error Display ===")
    
    print("βœ… Error display structure:")
    print("   - Clear error messages")
    print("   - Service unavailability notifications")
    print("   - Partial results display when applicable")
    
    return True


def main():
    """Run all tests"""
    print("=" * 60)
    print("GRADIO UI TEST SUITE")
    print("=" * 60)
    
    results = []
    
    # Run tests
    results.append(("Interface Creation", test_interface_creation()))
    results.append(("Input Components", test_input_components()))
    results.append(("Output Components", test_output_components()))
    results.append(("Display Components", test_display_components()))
    results.append(("Export Utilities", test_export_utils()))
    results.append(("Orchestrator Client", test_orchestrator_client()))
    results.append(("Data Models", test_models()))
    results.append(("Input Validation", test_input_validation()))
    results.append(("Loading Indicators", test_loading_indicators()))
    results.append(("Error Display", test_error_display()))
    
    # Summary
    print("\n" + "=" * 60)
    print("TEST SUMMARY")
    print("=" * 60)
    
    passed = sum(1 for _, result in results if result)
    total = len(results)
    
    for test_name, result in results:
        status = "βœ… PASS" if result else "❌ FAIL"
        print(f"{status}: {test_name}")
    
    print(f"\nTotal: {passed}/{total} test suites passed")
    
    if passed == total:
        print("\nβœ… All tests passed!")
        print("\nTo launch the app, run:")
        print("  python app.py")
        return 0
    else:
        print(f"\n❌ {total - passed} test suite(s) failed")
        return 1


if __name__ == "__main__":
    sys.exit(main())