11"""
2- Test for keyboard "q" button bug.
2+ Test for keyboard button functionality (originally created to fix "q" button bug) .
33
4- This test reproduces the issue where typing "q" on the keyboard results in
5- the button lighting up but no character being added to the textarea, while
6- the "a" button beneath it works correctly .
4+ This test verifies that all keyboard buttons work correctly, including the
5+ 'q' button which was previously broken due to button index 0 being treated
6+ as False in Python's truthiness check .
77
8- The test uses helper functions to locate buttons by their text, get their
9- coordinates, and simulate clicks using simulate_click() .
8+ The bug was: `if not button:` would return True when button index was 0,
9+ causing the 'q' key to be ignored. Fixed by changing to `if button is None:` .
1010
1111Usage:
1212 Desktop: ./tests/unittest.sh tests/test_graphical_keyboard_q_button_bug.py
2525)
2626
2727
28- class TestKeyboardQButtonBug (unittest .TestCase ):
29- """Test keyboard 'q' button behavior vs 'a' button ."""
28+ class TestKeyboardQButton (unittest .TestCase ):
29+ """Test keyboard button functionality (especially 'q' which was at index 0) ."""
3030
3131 def setUp (self ):
3232 """Set up test fixtures."""
@@ -40,22 +40,22 @@ def tearDown(self):
4040 lv .screen_load (lv .obj ())
4141 wait_for_render (5 )
4242
43- def test_q_button_bug (self ):
43+ def test_q_button_works (self ):
4444 """
4545 Test that clicking the 'q' button adds 'q' to textarea.
4646
47- This test demonstrates the bug where:
48- 1. Clicking 'q' button lights it up but doesn't add to textarea
49- 2. Clicking 'a' button works correctly
47+ This test verifies the fix for the bug where:
48+ - Bug: Button index 0 ( 'q') was treated as False in `if not button:`
49+ - Fix: Changed to `if button is None:` to properly handle index 0
5050
5151 Steps:
5252 1. Create textarea and keyboard
5353 2. Find 'q' button index in keyboard map
5454 3. Get button coordinates from keyboard widget
5555 4. Click it using simulate_click()
56- 5. Verify 'q' appears in textarea (EXPECTED TO FAIL due to bug )
56+ 5. Verify 'q' appears in textarea (should PASS after fix )
5757 6. Repeat with 'a' button
58- 7. Verify 'a' appears correctly (EXPECTED TO PASS)
58+ 7. Verify 'a' appears correctly (should PASS)
5959 """
6060 print ("\n === Testing keyboard 'q' and 'a' button behavior ===" )
6161
@@ -122,14 +122,9 @@ def test_q_button_bug(self):
122122 text_after_q = textarea .get_text ()
123123 print (f"Textarea after clicking 'q': '{ text_after_q } '" )
124124
125- # THIS IS THE BUG: 'q' should be added but isn't
126- if text_after_q != "q" :
127- print ("BUG REPRODUCED: 'q' button was clicked but 'q' was NOT added to textarea!" )
128- print ("Expected: 'q'" )
129- print (f"Got: '{ text_after_q } '" )
130-
125+ # Verify 'q' was added (should work after fix)
131126 self .assertEqual (text_after_q , "q" ,
132- "Clicking 'q' button should add 'q' to textarea (BUG: This test will fail) " )
127+ "Clicking 'q' button should add 'q' to textarea" )
133128
134129 # --- Test 'a' button for comparison ---
135130 print ("\n --- Testing 'a' button (for comparison) ---" )
@@ -170,13 +165,12 @@ def test_q_button_bug(self):
170165
171166 # The 'a' button should work correctly
172167 self .assertEqual (text_after_a , "a" ,
173- "Clicking 'a' button should add 'a' to textarea (should PASS) " )
168+ "Clicking 'a' button should add 'a' to textarea" )
174169
175170 print ("\n Summary:" )
176- print (f" 'q' button result: '{ text_after_q } ' (expected 'q')" )
177- print (f" 'a' button result: '{ text_after_a } ' (expected 'a')" )
178- if text_after_q != "q" and text_after_a == "a" :
179- print (" BUG CONFIRMED: 'q' doesn't work but 'a' does!" )
171+ print (f" 'q' button result: '{ text_after_q } ' (expected 'q') ✓" )
172+ print (f" 'a' button result: '{ text_after_a } ' (expected 'a') ✓" )
173+ print (" Both buttons work correctly!" )
180174
181175 def test_keyboard_button_discovery (self ):
182176 """
0 commit comments