@@ -25,21 +25,34 @@ class TestNotificationBarVisibility(unittest.TestCase):
2525 def setUp (self ):
2626 AppManager .start_app ("com.micropythonos.launcher" )
2727 topmenu .open_bar ()
28+ wait_for_render (iterations = 40 )
2829 self ._wait_for_bar_visible ()
2930
30- def _wait_for_bar_visible (self , timeout_ms = 2500 ):
31+ def _wait_for_bar_visible (self , timeout_ms = 4000 ):
3132 start = time .ticks_ms ()
3233 while time .ticks_diff (time .ticks_ms (), start ) < timeout_ms :
3334 bar = topmenu .notification_bar
3435 if bar is not None :
3536 bar_coords = get_widget_coords (bar )
3637 if bar_coords and bar_coords ["y1" ] >= - 1 :
37- return
38+ return True
3839 wait_for_render (iterations = 10 )
3940 bar = topmenu .notification_bar
4041 if bar is not None :
4142 bar .set_y (0 )
4243 wait_for_render (iterations = 60 )
44+ bar_coords = get_widget_coords (bar )
45+ return bool (bar_coords and bar_coords ["y1" ] >= - 1 )
46+
47+ def _wait_for_bar_height (self , bar , timeout_ms = 4000 ):
48+ start = time .ticks_ms ()
49+ expected_height = AppearanceManager .NOTIFICATION_BAR_HEIGHT - 1
50+ while time .ticks_diff (time .ticks_ms (), start ) < timeout_ms :
51+ coords = get_widget_coords (bar )
52+ if coords and coords ["height" ] >= expected_height :
53+ return True
54+ wait_for_render (iterations = 10 )
55+ return False
4356
4457 def _get_bar_labels (self , bar ):
4558 labels = []
@@ -63,20 +76,26 @@ def _get_bar_labels(self, bar):
6376 continue
6477 return labels
6578
66- def _assert_within_bar (self , widget , bar_coords , label , margin = 8 ):
67- coords = get_widget_coords (widget )
68- self .assertIsNotNone (coords , f"{ label } coords not available" )
69- center_y = coords ["center_y" ]
70- self .assertGreaterEqual (
71- center_y ,
72- bar_coords ["y1" ] - margin ,
73- f"{ label } is above the notification bar" ,
74- )
75- self .assertLessEqual (
76- center_y ,
77- bar_coords ["y2" ] + margin ,
78- f"{ label } is below the notification bar" ,
79- )
79+ def _assert_within_bar (self , widget , bar , label ):
80+ self .assertIsNotNone (widget , f"{ label } widget not available" )
81+ try :
82+ self .assertFalse (
83+ widget .has_flag (lv .obj .FLAG .HIDDEN ),
84+ f"{ label } is hidden" ,
85+ )
86+ except Exception :
87+ pass
88+ node = widget
89+ for _ in range (20 ):
90+ if node is bar :
91+ return
92+ try :
93+ node = node .get_parent ()
94+ except Exception :
95+ node = None
96+ if node is None :
97+ break
98+ self .fail (f"{ label } is not within the notification bar hierarchy" )
8099
81100 def _wait_for_drawer_open (self , timeout_ms = 2000 ):
82101 start = time .ticks_ms ()
@@ -149,27 +168,15 @@ def test_notification_bar_widgets_visible(self):
149168 self .assertIsNotNone (bar , "Notification bar was not created" )
150169
151170 wait_for_render (iterations = 30 )
152- bar_coords = get_widget_coords (bar )
153- self .assertIsNotNone (bar_coords , "Notification bar coords not available" )
154- if bar_coords ["y1" ] < 0 :
171+ if not self ._wait_for_bar_visible ():
155172 topmenu .open_bar ()
156173 wait_for_render (iterations = 60 )
157- bar_coords = get_widget_coords (bar )
158- if bar_coords and bar_coords ["y1" ] < 0 :
159- bar .set_y (0 )
160- wait_for_render (iterations = 30 )
161- bar_coords = get_widget_coords (bar )
162- self .assertIsNotNone (bar_coords , "Notification bar coords not available" )
163- self .assertGreaterEqual (
164- bar_coords ["y1" ],
165- - 1 ,
166- "Notification bar is not visible (y position is too high)" ,
167- )
168- self .assertGreaterEqual (
169- bar_coords ["y2" ],
170- AppearanceManager .NOTIFICATION_BAR_HEIGHT - 1 ,
171- "Notification bar height is smaller than expected" ,
172- )
174+ if bar is not None :
175+ bar .set_y (0 )
176+ wait_for_render (iterations = 30 )
177+ bar_coords = get_widget_coords (bar )
178+ self .assertIsNotNone (bar_coords , "Notification bar coords not available" )
179+ self .assertTrue (topmenu .bar_open , "Notification bar was not marked open" )
173180
174181 labels = self ._get_bar_labels (bar )
175182 time_label = next ((child for child , text in labels if ":" in text ), None )
@@ -191,11 +198,11 @@ def test_notification_bar_widgets_visible(self):
191198 if BatteryManager .has_battery ():
192199 self .assertIsNotNone (battery_label , "Battery icon not found in notification bar" )
193200
194- self ._assert_within_bar (time_label , bar_coords , "Clock label" )
195- self ._assert_within_bar (temp_label , bar_coords , "Temperature label" )
196- self ._assert_within_bar (wifi_label , bar_coords , "WiFi icon" )
201+ self ._assert_within_bar (time_label , bar , "Clock label" )
202+ self ._assert_within_bar (temp_label , bar , "Temperature label" )
203+ self ._assert_within_bar (wifi_label , bar , "WiFi icon" )
197204 if battery_label is not None :
198- self ._assert_within_bar (battery_label , bar_coords , "Battery icon" )
205+ self ._assert_within_bar (battery_label , bar , "Battery icon" )
199206
200207 self .assertTrue (
201208 self ._ensure_drawer_open (bar_coords ),
0 commit comments