test: add tests for 1D party position chart
This commit is contained in:
@@ -278,3 +278,63 @@ def test_partial_party_traces():
|
||||
# hovertemplate should include raw marker fields like 'x (raw)'
|
||||
if hasattr(tr, "hovertemplate") and tr.hovertemplate:
|
||||
assert "x (raw)" in tr.hovertemplate
|
||||
|
||||
|
||||
def test_render_party_axis_chart_1d_renders():
|
||||
"""Test that _render_party_axis_chart_1d creates a figure with proper structure."""
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from explorer import _render_party_axis_chart_1d
|
||||
|
||||
party_coords = {
|
||||
"VVD": (0.5,),
|
||||
"SP": (-0.6,),
|
||||
"PVV": (0.8,),
|
||||
"DENK": (-0.4,),
|
||||
}
|
||||
|
||||
theme = {
|
||||
"label": "Test Component",
|
||||
"positive_pole": "Positive",
|
||||
"negative_pole": "Negative",
|
||||
"flip": False,
|
||||
}
|
||||
|
||||
# Mock st.plotly_chart to capture the figure being rendered
|
||||
with patch("explorer.st.plotly_chart") as mock_plotly_chart:
|
||||
_render_party_axis_chart_1d(party_coords, 3, theme)
|
||||
|
||||
# Verify that plotly_chart was called
|
||||
assert mock_plotly_chart.called, "plotly_chart should be called"
|
||||
|
||||
# Get the figure passed to plotly_chart
|
||||
fig = mock_plotly_chart.call_args[0][0]
|
||||
assert fig is not None, "Figure should not be None"
|
||||
# Check that figure has traces (the bar chart)
|
||||
assert len(fig.data) > 0, "Figure should have traces"
|
||||
|
||||
|
||||
def test_render_party_axis_chart_1d_empty_coords():
|
||||
"""Test that _render_party_axis_chart_1d handles empty coords gracefully."""
|
||||
from unittest.mock import patch
|
||||
|
||||
from explorer import _render_party_axis_chart_1d
|
||||
|
||||
theme = {
|
||||
"label": "Test Component",
|
||||
"positive_pole": "Positive",
|
||||
"negative_pole": "Negative",
|
||||
"flip": False,
|
||||
}
|
||||
|
||||
# Empty coords should show caption, not plotly_chart
|
||||
with patch("explorer.st.caption") as mock_caption:
|
||||
with patch("explorer.st.plotly_chart") as mock_plotly_chart:
|
||||
result = _render_party_axis_chart_1d({}, 3, theme)
|
||||
|
||||
# Should show caption for empty data
|
||||
assert mock_caption.called, "Should show caption for empty data"
|
||||
# Should NOT call plotly_chart
|
||||
assert not mock_plotly_chart.called, (
|
||||
"Should not call plotly_chart for empty data"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user