# 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