File size: 4,073 Bytes
9bceb4c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Test house specifications display component
"""

import sys
from pathlib import Path

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

from components.house_specs_display import format_house_specs_display


def test_house_specs_display_with_dict():
    """Test house specifications display with dictionary input"""
    
    house_specs = {
        'number_of_floors': 2,
        'primary_material': 'reinforced_concrete',
        'foundation_type': 'deep_pile',
        'foundation_depth_meters': 3.5,
        'roof_type': 'hip',
        'wall_thickness_mm': 250,
        'reinforcement_details': 'Steel rebar Grade 60, 16mm diameter @ 200mm spacing',
        'structural_features': [
            {
                'feature_name': 'Shear Walls',
                'specification': '300mm thick reinforced concrete shear walls at building corners',
                'justification': 'Required for high seismic zone to resist lateral forces'
            },
            {
                'feature_name': 'Elevated Foundation',
                'specification': 'First floor elevated 1.5m above ground level',
                'justification': 'Protection against flood risk identified in the area'
            }
        ],
        'compliance_codes': [
            'National Building Code of the Philippines (NBCP)',
            'National Structural Code of the Philippines (NSCP) 2015',
            'Philippine Green Building Code'
        ],
        'decision_rationale': 'Based on high seismic risk and moderate flood risk, reinforced concrete with deep pile foundation provides optimal structural integrity. Hip roof design offers superior wind resistance.'
    }
    
    html = format_house_specs_display(house_specs)
    
    # Verify key elements are present
    assert 'πŸ—οΈ House Specifications' in html
    assert '2' in html  # number of floors
    assert 'Reinforced Concrete' in html
    assert 'Deep Pile' in html
    assert '3.50 meters' in html
    assert 'Hip' in html
    assert '250 mm' in html
    assert 'Shear Walls' in html
    assert 'Elevated Foundation' in html
    assert 'National Building Code of the Philippines' in html
    assert 'decision_rationale' in html.lower() or 'rationale' in html.lower()
    
    print("βœ… Test passed: House specifications display with dict")
    return True


def test_house_specs_display_with_none():
    """Test house specifications display with None input"""
    
    html = format_house_specs_display(None)
    
    # Should show unavailable message
    assert 'unavailable' in html.lower()
    
    print("βœ… Test passed: House specifications display with None")
    return True


def test_house_specs_display_minimal():
    """Test house specifications display with minimal data"""
    
    house_specs = {
        'number_of_floors': 1,
        'primary_material': 'wood',
        'foundation_type': 'shallow',
        'foundation_depth_meters': 1.0,
        'roof_type': 'gable',
        'wall_thickness_mm': 150,
        'reinforcement_details': '',
        'structural_features': [],
        'compliance_codes': [],
        'decision_rationale': ''
    }
    
    html = format_house_specs_display(house_specs)
    
    # Verify basic elements are present
    assert 'πŸ—οΈ House Specifications' in html
    assert '1' in html  # number of floors
    assert 'Wood' in html
    assert 'Shallow' in html
    assert 'Gable' in html
    
    print("βœ… Test passed: House specifications display with minimal data")
    return True


if __name__ == '__main__':
    print("Testing house specifications display component...\n")
    
    try:
        test_house_specs_display_with_dict()
        test_house_specs_display_with_none()
        test_house_specs_display_minimal()
        
        print("\nβœ… All tests passed!")
        
    except AssertionError as e:
        print(f"\n❌ Test failed: {e}")
        sys.exit(1)
    except Exception as e:
        print(f"\n❌ Unexpected error: {e}")
        import traceback
        traceback.print_exc()
        sys.exit(1)