Skip to content

Commit d7a7312

Browse files
Add tests/test_graphical_imu_calibration_ui_bug.py
1 parent 32de7bb commit d7a7312

File tree

1 file changed

+183
-0
lines changed

1 file changed

+183
-0
lines changed
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
#!/usr/bin/env python3
2+
"""Automated UI test for IMU calibration bug.
3+
4+
Tests the complete flow:
5+
1. Open Settings → IMU → Check Calibration
6+
2. Verify values are shown
7+
3. Click "Calibrate" → Calibrate IMU
8+
4. Click "Calibrate Now"
9+
5. Go back to Check Calibration
10+
6. BUG: Verify values are shown (not "--")
11+
"""
12+
13+
import sys
14+
import time
15+
import unittest
16+
17+
# Import graphical test infrastructure
18+
import lvgl as lv
19+
from mpos.ui.testing import (
20+
wait_for_render,
21+
simulate_click,
22+
find_button_with_text,
23+
find_label_with_text,
24+
get_widget_coords,
25+
print_screen_labels,
26+
capture_screenshot,
27+
click_label,
28+
click_button,
29+
find_text_on_screen
30+
)
31+
32+
33+
class TestIMUCalibrationUI(unittest.TestCase):
34+
35+
def test_imu_calibration_bug_test(self):
36+
print("=== IMU Calibration UI Bug Test ===\n")
37+
38+
# Initialize the OS (boot.py and main.py)
39+
print("Step 1: Initializing MicroPythonOS...")
40+
import mpos.main
41+
wait_for_render(iterations=30)
42+
print("OS initialized\n")
43+
44+
# Step 2: Open Settings app
45+
print("Step 2: Opening Settings app...")
46+
import mpos.apps
47+
48+
# Start Settings app by name
49+
mpos.apps.start_app("com.micropythonos.settings")
50+
wait_for_render(iterations=30)
51+
print("Settings app opened\n")
52+
53+
print("Current screen content:")
54+
print_screen_labels(lv.screen_active())
55+
print()
56+
57+
# Check if we're on the main Settings screen (should see multiple settings options)
58+
# The Settings app shows a list with items like "Calibrate IMU", "Check IMU Calibration", "Theme Color", etc.
59+
on_settings_main = (find_text_on_screen("Calibrate IMU") and
60+
find_text_on_screen("Check IMU Calibration") and
61+
find_text_on_screen("Theme Color"))
62+
63+
# If we're on a sub-screen (like Calibrate IMU or Check IMU Calibration screens),
64+
# we need to go back to Settings main. We can detect this by looking for screen titles.
65+
if not on_settings_main:
66+
print("Step 3: Not on Settings main screen, clicking Back or Cancel to return...")
67+
self.assertTrue(click_button("Back") or click_button("Cancel"), "Could not click 'Back' or 'Cancel' button")
68+
wait_for_render(iterations=20)
69+
print("Current screen content:")
70+
print_screen_labels(lv.screen_active())
71+
print()
72+
73+
# Step 4: Click "Check IMU Calibration" (it's a clickable label/container, not a button)
74+
print("Step 4: Clicking 'Check IMU Calibration' menu item...")
75+
self.assertTrue(click_label("Check IMU Calibration"), "Could not find Check IMU Calibration menu item")
76+
wait_for_render(iterations=20)
77+
78+
print("Step 5: Checking BEFORE calibration...")
79+
print("Current screen content:")
80+
print_screen_labels(lv.screen_active())
81+
print()
82+
83+
# Capture screenshot before
84+
capture_screenshot("../tests/screenshots/check_imu_before_calib.raw")
85+
86+
# Look for actual values (not "--")
87+
has_values_before = False
88+
widgets = []
89+
from mpos.ui.testing import get_all_widgets_with_text
90+
for widget in get_all_widgets_with_text(lv.screen_active()):
91+
text = widget.get_text()
92+
# Look for patterns like "X: 0.00" or "Quality: Good"
93+
if ":" in text and "--" not in text:
94+
if any(char.isdigit() for char in text):
95+
print(f"Found value: {text}")
96+
has_values_before = True
97+
98+
if not has_values_before:
99+
print("WARNING: No values found before calibration (all showing '--')")
100+
else:
101+
print("GOOD: Values are showing before calibration")
102+
print()
103+
104+
# Step 6: Click "Calibrate" button to go to calibration screen
105+
print("Step 6: Finding 'Calibrate' button...")
106+
calibrate_btn = find_button_with_text(lv.screen_active(), "Calibrate")
107+
self.assertIsNotNone(calibrate_btn, "Could not find 'Calibrate' button")
108+
109+
print(f"Found Calibrate button: {calibrate_btn}")
110+
print("Manually sending CLICKED event to button...")
111+
# Instead of using simulate_click, manually send the event
112+
calibrate_btn.send_event(lv.EVENT.CLICKED, None)
113+
wait_for_render(iterations=20)
114+
115+
# Wait for navigation to complete (activity transition can take some time)
116+
time.sleep(0.5)
117+
wait_for_render(iterations=50)
118+
print("Calibrate IMU screen should be open now\n")
119+
120+
print("Current screen content:")
121+
print_screen_labels(lv.screen_active())
122+
print()
123+
124+
# Step 7: Click "Calibrate Now" button
125+
print("Step 7: Clicking 'Calibrate Now' button...")
126+
self.assertTrue(click_button("Calibrate Now"), "Could not click 'Calibrate Now' button")
127+
print("Calibration started...\n")
128+
129+
# Wait for calibration to complete (~2 seconds + UI updates)
130+
time.sleep(3)
131+
wait_for_render(iterations=50)
132+
133+
print("Current screen content after calibration:")
134+
print_screen_labels(lv.screen_active())
135+
print()
136+
137+
# Step 8: Click "Done" to go back
138+
print("Step 8: Clicking 'Done' button...")
139+
self.assertTrue(click_button("Done"), "Could not click 'Done' button")
140+
print("Going back to Check Calibration\n")
141+
142+
# Wait for screen to load
143+
time.sleep(0.5)
144+
wait_for_render(iterations=30)
145+
146+
# Step 9: Check AFTER calibration (BUG: should show values, not "--")
147+
print("Step 9: Checking AFTER calibration (testing for bug)...")
148+
print("Current screen content:")
149+
print_screen_labels(lv.screen_active())
150+
print()
151+
152+
# Capture screenshot after
153+
capture_screenshot("../tests/screenshots/check_imu_after_calib.raw")
154+
155+
# Look for actual values (not "--")
156+
has_values_after = False
157+
for widget in get_all_widgets_with_text(lv.screen_active()):
158+
text = widget.get_text()
159+
# Look for patterns like "X: 0.00" or "Quality: Good"
160+
if ":" in text and "--" not in text:
161+
if any(char.isdigit() for char in text):
162+
print(f"Found value: {text}")
163+
has_values_after = True
164+
165+
print()
166+
print("="*60)
167+
print("TEST RESULTS:")
168+
print(f" Values shown BEFORE calibration: {has_values_before}")
169+
print(f" Values shown AFTER calibration: {has_values_after}")
170+
171+
if has_values_before and not has_values_after:
172+
print("\n ❌ BUG REPRODUCED: Values disappeared after calibration!")
173+
print(" Expected: Values should still be shown")
174+
print(" Actual: All showing '--'")
175+
#return False
176+
elif has_values_after:
177+
print("\n ✅ PASS: Values are showing correctly after calibration")
178+
#return True
179+
else:
180+
print("\n ⚠️ WARNING: No values shown before or after (might be desktop mock issue)")
181+
#return True
182+
183+

0 commit comments

Comments
 (0)