Skip to content

Commit 11867dd

Browse files
Rework tests
1 parent aa449a5 commit 11867dd

File tree

3 files changed

+54
-259
lines changed

3 files changed

+54
-259
lines changed

internal_filesystem/lib/mpos/ui/testing.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"""
4242

4343
import lvgl as lv
44+
import time
4445

4546
# Simulation globals for touch input
4647
_touch_x = 0
@@ -579,3 +580,42 @@ def release_timer_cb(timer):
579580
# Schedule the release
580581
timer = lv.timer_create(release_timer_cb, press_duration_ms, None)
581582
timer.set_repeat_count(1)
583+
584+
def click_button(button_text, timeout=5):
585+
"""Find and click a button with given text."""
586+
start = time.time()
587+
while time.time() - start < timeout:
588+
button = find_button_with_text(lv.screen_active(), button_text)
589+
if button:
590+
coords = get_widget_coords(button)
591+
if coords:
592+
print(f"Clicking button '{button_text}' at ({coords['center_x']}, {coords['center_y']})")
593+
simulate_click(coords['center_x'], coords['center_y'])
594+
wait_for_render(iterations=20)
595+
return True
596+
wait_for_render(iterations=5)
597+
print(f"ERROR: Button '{button_text}' not found after {timeout}s")
598+
return False
599+
600+
def click_label(label_text, timeout=5):
601+
"""Find a label with given text and click on it (or its clickable parent)."""
602+
start = time.time()
603+
while time.time() - start < timeout:
604+
label = find_label_with_text(lv.screen_active(), label_text)
605+
if label:
606+
print("Scrolling label to view...")
607+
label.scroll_to_view_recursive(True)
608+
wait_for_render(iterations=50) # needs quite a bit of time
609+
coords = get_widget_coords(label)
610+
if coords:
611+
print(f"Clicking label '{label_text}' at ({coords['center_x']}, {coords['center_y']})")
612+
simulate_click(coords['center_x'], coords['center_y'])
613+
wait_for_render(iterations=20)
614+
return True
615+
wait_for_render(iterations=5)
616+
print(f"ERROR: Label '{label_text}' not found after {timeout}s")
617+
return False
618+
619+
def find_text_on_screen(text):
620+
"""Check if text is present on screen."""
621+
return find_label_with_text(lv.screen_active(), text) is not None

tests/test_graphical_imu_calibration.py

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
print_screen_labels,
2525
simulate_click,
2626
get_widget_coords,
27-
find_button_with_text
27+
find_button_with_text,
28+
click_label,
29+
click_button,
30+
find_text_on_screen
2831
)
2932

3033

@@ -68,16 +71,9 @@ def test_check_calibration_activity_loads(self):
6871
simulate_click(10, 10)
6972
wait_for_render(10)
7073

71-
# Find and click "Check IMU Calibration" setting
72-
screen = lv.screen_active()
73-
check_cal_label = find_label_with_text(screen, "Check IMU Calibration")
74-
self.assertIsNotNone(check_cal_label, "Could not find 'Check IMU Calibration' setting")
75-
76-
# Click on the setting container
77-
coords = get_widget_coords(check_cal_label.get_parent())
78-
self.assertIsNotNone(coords, "Could not get coordinates of setting")
79-
simulate_click(coords['center_x'], coords['center_y'])
80-
wait_for_render(30)
74+
print("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)
8177

8278
# Verify key elements are present
8379
screen = lv.screen_active()
@@ -110,15 +106,9 @@ def test_calibrate_activity_flow(self):
110106
simulate_click(10, 10)
111107
wait_for_render(10)
112108

113-
# Find and click "Calibrate IMU" setting
114-
screen = lv.screen_active()
115-
calibrate_label = find_label_with_text(screen, "Calibrate IMU")
116-
self.assertIsNotNone(calibrate_label, "Could not find 'Calibrate IMU' setting")
117-
118-
coords = get_widget_coords(calibrate_label.get_parent())
119-
self.assertIsNotNone(coords)
120-
simulate_click(coords['center_x'], coords['center_y'])
121-
wait_for_render(30)
109+
print("Clicking 'Calibrate IMU' menu item...")
110+
self.assertTrue(click_label("Calibrate IMU"), "Could not find Calibrate IMU item")
111+
wait_for_render(iterations=20)
122112

123113
# Verify activity loaded and shows instructions
124114
screen = lv.screen_active()
@@ -173,17 +163,12 @@ def test_navigation_from_check_to_calibrate(self):
173163
simulate_click(10, 10)
174164
wait_for_render(10)
175165

176-
screen = lv.screen_active()
177-
check_cal_label = find_label_with_text(screen, "Check IMU Calibration")
178-
coords = get_widget_coords(check_cal_label.get_parent())
179-
simulate_click(coords['center_x'], coords['center_y'])
180-
wait_for_render(30) # Wait for real-time updates
181-
182-
# Verify Check activity loaded
183-
screen = lv.screen_active()
184-
self.assertTrue(verify_text_present(screen, "on flat surface"), "Check activity did not load")
166+
print("Clicking 'Check IMU Calibration' menu item...")
167+
self.assertTrue(click_label("Check IMU Calibration"), "Could not find Check IMU Calibration menu item")
168+
wait_for_render(iterations=20)
185169

186170
# Click "Calibrate" button to navigate to Calibrate activity
171+
screen = lv.screen_active()
187172
calibrate_btn = find_button_with_text(screen, "Calibrate")
188173
self.assertIsNotNone(calibrate_btn, "Could not find 'Calibrate' button")
189174

tests/test_imu_calibration_ui_bug.py

Lines changed: 0 additions & 230 deletions
This file was deleted.

0 commit comments

Comments
 (0)