Spaces:
Sleeping
Sleeping
File size: 6,055 Bytes
a3934b1 7bbd836 a3934b1 7bbd836 a3934b1 7bbd836 a3934b1 7bbd836 a3934b1 7bbd836 a3934b1 7bbd836 a3934b1 7bbd836 a3934b1 7bbd836 a3934b1 7bbd836 a3934b1 7bbd836 a3934b1 7bbd836 a3934b1 7bbd836 a3934b1 7bbd836 a3934b1 7bbd836 |
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 |
# test_verification_ui.py
"""
Unit tests for verification UI components.
Tests rendering of message review components including:
- Classifier decision badge display
- Confidence percentage formatting
- Indicators display as bullet points
"""
import pytest
from src.interface.verification_ui import VerificationUIComponents
from src.core.verification_models import TestMessage
class TestMessageReviewComponentRendering:
"""Tests for message review component rendering."""
def test_classifier_decision_badge_displays_correct_color_green(self):
"""Verify classifier decision badge displays correct color for GREEN."""
badge = VerificationUIComponents.get_classifier_decision_badge("green")
assert "🟢" in badge
assert "GREEN" in badge
assert "No Distress" in badge
def test_classifier_decision_badge_displays_correct_color_yellow(self):
"""Verify classifier decision badge displays correct color for YELLOW."""
badge = VerificationUIComponents.get_classifier_decision_badge("yellow")
assert "🟡" in badge
assert "YELLOW" in badge
assert "Potential Distress" in badge
def test_classifier_decision_badge_displays_correct_color_red(self):
"""Verify classifier decision badge displays correct color for RED."""
badge = VerificationUIComponents.get_classifier_decision_badge("red")
assert "🔴" in badge
assert "RED" in badge
assert "Severe Distress" in badge
def test_confidence_is_formatted_as_percentage(self):
"""Verify confidence is formatted as percentage."""
# Test 85% confidence - high confidence uses 🎯 icon
result = VerificationUIComponents.format_confidence_percentage(0.85)
assert "85%" in result
assert "confident" in result
# Test 100% confidence - high confidence uses 🎯 icon
result = VerificationUIComponents.format_confidence_percentage(1.0)
assert "100%" in result
assert "confident" in result
# Test 0% confidence - low confidence uses ⚠️ icon
result = VerificationUIComponents.format_confidence_percentage(0.0)
assert "0%" in result
assert "confident" in result
def test_indicators_display_as_bullet_points(self):
"""Verify indicators display contains all indicators."""
indicators = ["anxiety", "health concern", "stress"]
result = VerificationUIComponents.format_indicators_as_bullets(indicators)
# Check that each indicator is present in the result
assert "anxiety" in result
assert "health concern" in result
assert "stress" in result
# Check that the result has the Detected prefix
assert "Detected" in result
def test_indicators_display_empty_list(self):
"""Verify indicators display handles empty list."""
indicators = []
result = VerificationUIComponents.format_indicators_as_bullets(indicators)
# The implementation returns "No specific indicators" for empty list
assert "No specific indicators" in result or "no indicators" in result.lower()
def test_render_message_review_complete(self):
"""Verify render_message_review returns all components correctly."""
message = TestMessage(
message_id="msg_001",
text="I'm feeling anxious about my health",
pre_classified_label="yellow",
)
message_text, decision_badge, confidence, indicators = (
VerificationUIComponents.render_message_review(
message=message,
classifier_decision="yellow",
classifier_confidence=0.85,
classifier_indicators=["anxiety", "health concern"],
)
)
# Verify message text
assert message_text == "I'm feeling anxious about my health"
# Verify decision badge
assert "🟡" in decision_badge
assert "YELLOW" in decision_badge
# Verify confidence
assert "85%" in confidence
assert "confident" in confidence
# Verify indicators contain the indicator text
assert "anxiety" in indicators
assert "health concern" in indicators
def test_progress_display_accuracy(self):
"""Verify progress display shows correct message count."""
# Test first message
result = VerificationUIComponents.update_progress_display(0, 10)
assert "1 of 10" in result
# Test middle message
result = VerificationUIComponents.update_progress_display(5, 10)
assert "6 of 10" in result
# Test last message
result = VerificationUIComponents.update_progress_display(9, 10)
assert "10 of 10" in result
def test_statistics_display_accuracy_calculation(self):
"""Verify statistics display calculates accuracy correctly."""
# Test 3 correct out of 5
correct_str, incorrect_str, accuracy_str = (
VerificationUIComponents.update_statistics_display(3, 2)
)
# The implementation uses markdown bold formatting
assert "Correct" in correct_str and "3" in correct_str
assert "Incorrect" in incorrect_str and "2" in incorrect_str
assert "60" in accuracy_str # 60.0% accuracy
def test_statistics_display_zero_messages(self):
"""Verify statistics display handles zero messages."""
correct_str, incorrect_str, accuracy_str = (
VerificationUIComponents.update_statistics_display(0, 0)
)
# The implementation uses markdown bold formatting
assert "Correct" in correct_str and "0" in correct_str
assert "Incorrect" in incorrect_str and "0" in incorrect_str
# Zero messages shows "No verifications yet" message
assert "0" in accuracy_str or "No verifications" in accuracy_str
|