File size: 5,841 Bytes
baf85a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import pytest
from unittest.mock import patch, MagicMock

import sys
import os

# Importing from parent directory
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../")))
# Import the functions to test
from app import (
    _configure_page,
    _apply_custom_css,
    _get_proficiency_label,
    _render_skills,
    _create_skills_chart,
    _render_recommendation,
    _render_strengths,
    _render_skill_gaps,
)


# Fixture for session state
@pytest.fixture
def mock_session_state():
    """Create a mock session state for testing."""

    class MockSessionState:
        def __init__(self):
            self.insights_prompt = "Test prompt"
            self.page_filter = "@PAGERANGE(1-3)"

    return MockSessionState()


# Fixture for candidate insights
@pytest.fixture
def sample_candidate_insights():
    """Provide sample candidate insights for testing."""
    return {
        "name": "John Doe",
        "email": "john.doe@example.com",
        "skills": [
            {"name": "Python", "proficiency": 4},
            {"name": "Machine Learning", "proficiency": 3},
        ],
    }


# Fixture for job match assessment
@pytest.fixture
def sample_match_assessment():
    """Provide sample job match assessment for testing."""
    return {
        "percentage_match": 75,
        "overall_recommendation": "Strong Fit",
        "strengths": ["Strong Python skills", "ML background"],
        "potential_skill_gaps": ["Advanced cloud computing"],
    }


def test_configure_page():
    """Test page configuration function."""
    with patch("streamlit.set_page_config") as mock_set_page_config:
        _configure_page()
        mock_set_page_config.assert_called_once_with(
            page_title="Resume Intelligence",
            page_icon="📋",
            layout="wide",
            initial_sidebar_state="expanded",
        )


def test_apply_custom_css():
    """Test custom CSS application."""
    with patch("streamlit.markdown") as mock_markdown:
        _apply_custom_css()
        mock_markdown.assert_called_once()
        # Check that the markdown contains expected CSS
        assert "skill-badge" in mock_markdown.call_args[0][0]


def test_get_proficiency_label():
    """Test proficiency label generation."""
    assert _get_proficiency_label(1) == "Beginner"
    assert _get_proficiency_label(3) == "Intermediate"
    assert _get_proficiency_label(5) == "Advanced"


def test_render_skills():
    """Test skills rendering."""
    skills = [
        {"name": "Python", "proficiency": 4},
        {"name": "JavaScript", "proficiency": 2},
    ]

    with patch("streamlit.markdown") as mock_markdown:
        _render_skills(skills)
        mock_markdown.assert_called_once()
        # Verify skills are rendered
        assert "Python" in mock_markdown.call_args[0][0]
        assert "JavaScript" in mock_markdown.call_args[0][0]


def test_render_skills_empty():
    """Test skills rendering with empty skills list."""
    with patch("streamlit.markdown") as mock_markdown:
        _render_skills([])
        mock_markdown.assert_called_once_with("*No skills listed*")


def test_create_skills_chart(sample_candidate_insights):
    """Test skills proficiency chart creation."""
    with patch("streamlit.subheader"), patch(
        "streamlit.tabs", return_value=(MagicMock(), MagicMock())
    ) as mock_tabs, patch("streamlit.altair_chart"), patch("streamlit.dataframe"):
        _create_skills_chart(sample_candidate_insights["skills"])

        # Verify chart creation steps
        assert mock_tabs.call_count == 1
        # Ensure two tabs are created
        assert len(mock_tabs.call_args[0]) == 1


def test_render_recommendation():
    """Test job match recommendation rendering."""
    sample_assessments = [
        {"overall_recommendation": "Strong Fit"},
        {"overall_recommendation": "Moderate Fit"},
        {"overall_recommendation": "Poor Fit"},
    ]

    for assessment in sample_assessments:
        with patch("streamlit.markdown") as mock_markdown:
            _render_recommendation(assessment)
            mock_markdown.assert_called_once()
            # Verify recommendation is rendered
            assert assessment["overall_recommendation"] in mock_markdown.call_args[0][0]


def test_render_strengths(sample_match_assessment):
    """Test strengths rendering."""
    with patch("streamlit.subheader"), patch(
        "streamlit.columns", return_value=[MagicMock(), MagicMock()]
    ), patch("streamlit.markdown") as mock_markdown:
        _render_strengths(sample_match_assessment)
        mock_markdown.assert_called()
        # Verify strengths are rendered
        assert "ML background" in mock_markdown.call_args[0][0]


def test_render_strengths_empty():
    """Test strengths rendering with empty strengths."""
    with patch("streamlit.subheader"), patch("streamlit.info") as mock_info:
        _render_strengths({"strengths": []})
        mock_info.assert_called_once_with("No specific strengths identified")


def test_render_skill_gaps(sample_match_assessment):
    """Test skill gaps rendering."""
    with patch("streamlit.subheader"), patch(
        "streamlit.columns", return_value=[MagicMock()]
    ), patch("streamlit.markdown") as mock_markdown:
        _render_skill_gaps(sample_match_assessment)
        mock_markdown.assert_called_once()
        # Verify skill gaps are rendered
        assert "Advanced cloud computing" in mock_markdown.call_args[0][0]


def test_render_skill_gaps_empty():
    """Test skill gaps rendering with empty gaps."""
    with patch("streamlit.subheader"), patch("streamlit.info") as mock_info:
        _render_skill_gaps({"potential_skill_gaps": []})
        mock_info.assert_called_once_with("No significant skill gaps identified")


# Additional error handling and edge case tests could be added here