File size: 6,705 Bytes
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
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
178
179
180
181
# test_properties_progress_display.py
"""
Property-based tests for progress display accuracy.

Tests that progress display correctly reflects the current position in the queue
and total messages in the dataset.
"""

import pytest
from hypothesis import given, strategies as st, settings, HealthCheck
from datetime import datetime
from src.core.verification_models import (
    VerificationRecord,
    VerificationSession,
    TestMessage,
    TestDataset,
)
from src.interface.verification_ui import VerificationUIComponents


def test_message_strategy():
    """Generate random test messages."""
    return st.builds(
        TestMessage,
        message_id=st.text(
            alphabet="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_",
            min_size=1,
            max_size=20,
        ),
        text=st.text(min_size=1, max_size=500),
        pre_classified_label=st.sampled_from(["green", "yellow", "red"]),
    )


class TestProgressDisplayAccuracy:
    """
    **Feature: verification-mode, Property 7: Progress Display is Accurate**
    
    Tests that progress display correctly reflects current position and total messages.
    """

    @given(
        current_index=st.integers(min_value=0, max_value=99),
        total_messages=st.integers(min_value=1, max_value=100),
    )
    @settings(suppress_health_check=[HealthCheck.function_scoped_fixture])
    def test_progress_display_format(self, current_index, total_messages):
        """
        **Feature: verification-mode, Property 7: Progress Display is Accurate**
        **Validates: Requirements 1.3, 5.1**
        
        For any current index and total messages, the progress display should show
        "Message X of Y" where X = current_index + 1 and Y = total_messages.
        """
        # Ensure current_index is within bounds
        if current_index >= total_messages:
            current_index = total_messages - 1
        
        # Get progress display
        progress = VerificationUIComponents.update_progress_display(
            current_index, total_messages
        )
        
        # Verify format contains "Progress"
        assert "Progress" in progress
        
        # Extract the numbers from the progress string
        # Format: "📊 **Progress:** X of Y messages (Z%)"
        import re
        match = re.search(r'(\d+) of (\d+)', progress)
        assert match is not None, f"Could not find 'X of Y' pattern in: {progress}"
        message_number = int(match.group(1))
        total_from_display = int(match.group(2))
        
        # Verify message number is correct (1-based)
        assert message_number == current_index + 1
        
        # Verify total is correct
        assert total_from_display == total_messages

    def test_progress_display_first_message(self):
        """
        **Feature: verification-mode, Property 7: Progress Display is Accurate**
        **Validates: Requirements 1.3, 5.1**
        
        When at the first message (index 0), progress should show "1 of Y".
        """
        progress = VerificationUIComponents.update_progress_display(0, 10)
        
        assert "1 of 10" in progress
        assert "Progress:" in progress

    def test_progress_display_last_message(self):
        """
        **Feature: verification-mode, Property 7: Progress Display is Accurate**
        **Validates: Requirements 1.3, 5.1**
        
        When at the last message, progress should show "Y of Y".
        """
        progress = VerificationUIComponents.update_progress_display(9, 10)
        
        assert "10 of 10" in progress
        assert "Progress:" in progress

    def test_progress_display_middle_message(self):
        """
        **Feature: verification-mode, Property 7: Progress Display is Accurate**
        **Validates: Requirements 1.3, 5.1**
        
        When at a middle message, progress should show correct position.
        """
        progress = VerificationUIComponents.update_progress_display(4, 10)
        
        assert "5 of 10" in progress
        assert "Progress:" in progress

    def test_progress_display_single_message(self):
        """
        **Feature: verification-mode, Property 7: Progress Display is Accurate**
        **Validates: Requirements 1.3, 5.1**
        
        When there is only one message, progress should show "1 of 1".
        """
        progress = VerificationUIComponents.update_progress_display(0, 1)
        
        assert "1 of 1" in progress
        assert "Progress:" in progress

    @given(st.integers(min_value=1, max_value=1000))
    def test_progress_display_large_dataset(self, total_messages):
        """
        **Feature: verification-mode, Property 7: Progress Display is Accurate**
        **Validates: Requirements 1.3, 5.1**
        
        For any large dataset size, progress display should correctly show position.
        """
        import re
        # Test at various positions
        for position_ratio in [0.0, 0.25, 0.5, 0.75, 0.99]:
            current_index = int(total_messages * position_ratio)
            if current_index >= total_messages:
                current_index = total_messages - 1
            
            progress = VerificationUIComponents.update_progress_display(
                current_index, total_messages
            )
            
            # Extract numbers using regex
            # Format: "📊 **Progress:** X of Y messages (Z%)"
            match = re.search(r'(\d+) of (\d+)', progress)
            assert match is not None, f"Could not find 'X of Y' pattern in: {progress}"
            message_number = int(match.group(1))
            total_from_display = int(match.group(2))
            
            # Verify correctness
            assert message_number == current_index + 1
            assert total_from_display == total_messages

    def test_progress_display_contains_emoji(self):
        """
        **Feature: verification-mode, Property 7: Progress Display is Accurate**
        **Validates: Requirements 1.3, 5.1**
        
        Progress display should contain the progress emoji for visual clarity.
        """
        progress = VerificationUIComponents.update_progress_display(0, 10)
        
        assert "📊" in progress

    def test_progress_display_contains_messages_text(self):
        """
        **Feature: verification-mode, Property 7: Progress Display is Accurate**
        **Validates: Requirements 1.3, 5.1**
        
        Progress display should contain "messages" text.
        """
        progress = VerificationUIComponents.update_progress_display(0, 10)
        
        # The implementation uses "messages" in the format
        assert "messages" in progress