@@ -120,23 +120,15 @@ def test_shows_and_hides_screenreader_text
120120 def test_character_limit_updates_on_input
121121 visit_preview ( :with_character_limit )
122122
123- # Initial state - should show full limit remaining
124123 assert_selector "span.FormControl-caption[data-max-length='10']" , text : "10 characters remaining."
125-
126- # Validation should be hidden initially
127124 assert_selector "div.FormControl-inlineValidation[data-target='primer-text-field.characterLimitValidationElement']" , visible : :hidden
128125
129- # Type some text (5 characters)
130126 input = find ( "input[type=text][data-target*='primer-text-field.inputElement']" )
131127 input . fill_in ( with : "Hello" )
132128
133- # Wait for JS to update
134129 sleep 0.2
135130
136- # Character count should update to show 5 remaining
137131 assert_selector "span.FormControl-caption[data-max-length='10']" , text : "5 characters remaining."
138-
139- # Validation should still be hidden
140132 assert_selector "div.FormControl-inlineValidation[data-target='primer-text-field.characterLimitValidationElement']" , visible : :hidden
141133 end
142134
@@ -145,24 +137,16 @@ def test_character_limit_shows_validation_when_exceeded
145137
146138 input = find ( "input[type=text][data-target*='primer-text-field.inputElement']" )
147139
148- # Type text that exceeds the 10 character limit
149140 input . fill_in ( with : "Hello World!" ) # 12 characters
150141
151- # Wait for JS to update (includes debounce time)
152142 sleep 0.3
153143
154- # Character count should show "over" message
155144 assert_selector "span.FormControl-caption[data-max-length='10']" , text : "2 characters over."
156-
157- # Validation error should be visible
158145 assert_selector "div.FormControl-inlineValidation[data-target='primer-text-field.characterLimitValidationElement']" , visible : :visible do |element |
159146 assert_includes element . text , "You've exceeded the character limit"
160147 end
161-
162- # Input should be marked as invalid
163148 assert_selector "input[invalid='true'][aria-invalid='true']"
164149
165- # Check that aria-describedby includes the validation ID
166150 validation_element = find ( "div.FormControl-inlineValidation[data-target='primer-text-field.characterLimitValidationElement']" )
167151 validation_id = validation_element [ "id" ]
168152
@@ -175,25 +159,18 @@ def test_character_limit_clears_validation_when_back_under_limit
175159
176160 input = find ( "input[type=text][data-target*='primer-text-field.inputElement']" )
177161
178- # First, exceed the limit
179162 input . fill_in ( with : "Hello World!" ) # 12 characters
180163 sleep 0.3
181164
182- # Verify error is shown
183165 assert_selector "div.FormControl-inlineValidation[data-target='primer-text-field.characterLimitValidationElement']" , visible : :visible
184166 assert_selector "input[invalid='true'][aria-invalid='true']"
185167
186- # Now delete characters to get back under the limit
187168 input . fill_in ( with : "Hello" ) # 5 characters
188169 sleep 0.3
189170
190- # Character count should update
191171 assert_selector "span.FormControl-caption[data-max-length='10']" , text : "5 characters remaining."
192-
193- # Validation should be hidden again
194172 assert_selector "div.FormControl-inlineValidation[data-target='primer-text-field.characterLimitValidationElement']" , visible : :hidden
195173
196- # Input should not be marked as invalid
197174 refute_selector "input[invalid='true']"
198175 refute_selector "input[aria-invalid='true']"
199176 end
@@ -203,23 +180,18 @@ def test_character_limit_screen_reader_text_updates
203180
204181 input = find ( "input[type=text][data-target*='primer-text-field.inputElement']" )
205182
206- # Get the aria-live region
207183 sr_element = find ( "span.sr-only[aria-live='polite']" )
208184
209- # Type some text
210185 input . fill_in ( with : "Test" )
211186
212- # Wait for debounced update (150ms + buffer)
213- sleep 0.3
187+ # Wait for debounced update (500ms + buffer)
188+ sleep 0.6
214189
215- # Screen reader text should be updated
216190 assert_equal "6 characters remaining." , sr_element . text
217191
218- # Type more to exceed limit
219192 input . fill_in ( with : "Hello World!" ) # 12 characters
220- sleep 0.3
193+ sleep 0.6
221194
222- # Screen reader should announce over limit
223195 assert_equal "2 characters over." , sr_element . text
224196 end
225197
@@ -228,18 +200,14 @@ def test_character_limit_singular_vs_plural
228200
229201 input = find ( "input[type=text][data-target*='primer-text-field.inputElement']" )
230202
231- # Type to leave exactly 1 character remaining
232203 input . fill_in ( with : "123456789" ) # 9 characters, limit is 10
233204 sleep 0.3
234205
235- # Should use singular "character"
236206 assert_selector "span.FormControl-caption[data-max-length='10']" , text : "1 character remaining."
237207
238- # Type one more to exceed by exactly 1
239208 input . fill_in ( with : "12345678901" ) # 11 characters
240209 sleep 0.3
241210
242- # Should use singular "character" for over
243211 assert_selector "span.FormControl-caption[data-max-length='10']" , text : "1 character over."
244212 end
245213 end
0 commit comments