1212import unittest
1313import lvgl as lv
1414import mpos .ui
15- import time
1615import sys
1716from mpos import (
18- wait_for_render ,
19- find_label_with_text ,
17+ wait_for_text ,
2018 verify_text_present ,
2119 print_screen_labels ,
22- simulate_click ,
23- get_widget_coords ,
2420 find_button_with_text ,
25- find_text_on_screen ,
2621 AppManager
2722)
2823
@@ -36,17 +31,10 @@ def _start_activity_from_settings_assets(self, filename, classname):
3631 cwd = f"builtin/apps/{ app_fullname } /assets/"
3732 result = AppManager .execute_script (entrypoint , classname , cwd , app_fullname = app_fullname )
3833 self .assertTrue (result , f"Failed to start { classname } from { entrypoint } " )
39- wait_for_render (iterations = 60 )
4034
4135 def tearDown (self ):
4236 """Clean up after test."""
43- # Navigate back to launcher
44- try :
45- for _ in range (3 ): # May need multiple backs
46- mpos .ui .back_screen ()
47- wait_for_render (10 )
48- except :
49- pass
37+ mpos .ui .back_screen ()
5038
5139 def test_check_calibration_activity_loads (self ):
5240 """Test that CheckIMUCalibrationActivity loads and displays."""
@@ -55,10 +43,13 @@ def test_check_calibration_activity_loads(self):
5543 # Navigate directly to activity to avoid flaky settings clicks
5644 self ._start_activity_from_settings_assets ("check_imu_calibration.py" , "CheckIMUCalibrationActivity" )
5745
46+ # Wait for activity UI to render (polling, not fixed — handles slow CI)
47+ self .assertTrue (wait_for_text ("Quality" , timeout = 10 ),
48+ "CheckIMUCalibrationActivity: 'Quality' label not found within timeout" )
49+
5850 # Verify key elements are present
5951 screen = lv .screen_active ()
6052 print_screen_labels (screen )
61- self .assertTrue (verify_text_present (screen , "Quality" ), "Quality label not found" )
6253 self .assertTrue (verify_text_present (screen , "Accel." ), "Accel. label not found" )
6354 self .assertTrue (verify_text_present (screen , "Gyro" ), "Gyro label not found" )
6455
@@ -71,31 +62,29 @@ def test_calibrate_activity_flow(self):
7162 # Navigate directly to activity to avoid flaky settings clicks
7263 self ._start_activity_from_settings_assets ("calibrate_imu.py" , "CalibrateIMUActivity" )
7364
74- # Verify activity loaded and shows instructions
65+ # Wait for activity UI to render (polling, not fixed)
66+ self .assertTrue (wait_for_text ("IMU Calibration" , timeout = 10 ),
67+ "CalibrateIMUActivity title not found within timeout" )
7568 screen = lv .screen_active ()
7669 print_screen_labels (screen )
77- self .assertTrue (verify_text_present (screen , "IMU Calibration" ),
78- "CalibrateIMUActivity title not found" )
7970 self .assertTrue (verify_text_present (screen , "Place device on flat" ),
8071 "Instructions not shown" )
8172
8273 # Click "Calibrate Now" button to start calibration
8374 calibrate_btn = find_button_with_text (screen , "Calibrate Now" )
8475 self .assertIsNotNone (calibrate_btn , "Could not find 'Calibrate Now' button" )
8576 calibrate_btn .send_event (lv .EVENT .CLICKED , None )
86- wait_for_render (25 )
8777
88- # Wait for calibration to complete (mock takes ~3 seconds)
89- time .sleep (4 )
90- wait_for_render (50 )
78+ # Wait for calibration to complete — poll for the success message
79+ # instead of fixed sleep (handles slow/fast CI equally well)
80+ self .assertTrue (
81+ wait_for_text ("Calibration successful!" , timeout = 15 ),
82+ "Calibration completion message not found within timeout"
83+ )
9184
92- # Verify calibration completed
85+ # Verify offsets are shown
9386 screen = lv .screen_active ()
9487 print_screen_labels (screen )
95- self .assertTrue (verify_text_present (screen , "Calibration successful!" ),
96- "Calibration completion message not found" )
97-
98- # Verify offsets are shown
9988 self .assertTrue (verify_text_present (screen , "Accel offsets" ) or
10089 verify_text_present (screen , "offsets" ),
10190 "Calibration offsets not shown" )
@@ -109,6 +98,10 @@ def test_navigation_from_check_to_calibrate(self):
10998 # Navigate directly to Check activity
11099 self ._start_activity_from_settings_assets ("check_imu_calibration.py" , "CheckIMUCalibrationActivity" )
111100
101+ # Wait for Check activity to render
102+ self .assertTrue (wait_for_text ("Quality" , timeout = 10 ),
103+ "CheckIMUCalibrationActivity: 'Quality' label not found" )
104+
112105 # Click "Calibrate" button to navigate to Calibrate activity
113106 screen = lv .screen_active ()
114107 calibrate_btn = find_button_with_text (screen , "Calibrate" )
@@ -121,19 +114,20 @@ def test_navigation_from_check_to_calibrate(self):
121114 added_path = True
122115 try :
123116 calibrate_btn .send_event (lv .EVENT .CLICKED , None )
124- wait_for_render (60 )
125117 finally :
126118 if added_path :
127119 try :
128120 sys .path .remove (assets_path )
129121 except ValueError :
130122 pass
131123
132- # Verify CalibrateIMUActivity loaded
124+ # Wait for CalibrateIMUActivity to load (polling, not fixed)
125+ self .assertTrue (
126+ wait_for_text ("Calibrate Now" , timeout = 10 ),
127+ "Did not navigate to CalibrateIMUActivity within timeout"
128+ )
133129 screen = lv .screen_active ()
134130 print_screen_labels (screen )
135- self .assertTrue (verify_text_present (screen , "Calibrate Now" ),
136- "Did not navigate to CalibrateIMUActivity" )
137131 self .assertTrue (verify_text_present (screen , "Place device on flat" ),
138132 "CalibrateIMUActivity instructions not shown" )
139133
0 commit comments