Skip to content

Commit f883a19

Browse files
Improve bar test
1 parent 6c01392 commit f883a19

2 files changed

Lines changed: 49 additions & 3 deletions

File tree

internal_filesystem/lib/mpos/ui/gesture_navigation.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ def _top_swipe_cb(event):
8282
y = point.y
8383
dx = abs(x - down_start_x)
8484
dy = abs(y - down_start_y)
85+
dy_signed = y - down_start_y
8586
# print(f"visual_back_swipe_cb event_code={event_code} and event_name={name} and pos: {x}, {y}")
8687
if event_code == lv.EVENT.PRESSED:
8788
down_start_x = x
@@ -98,7 +99,10 @@ def _top_swipe_cb(event):
9899
WidgetAnimator.smooth_hide(downbutton)
99100
dx = abs(x - down_start_x)
100101
dy = abs(y - down_start_y)
101-
if y > DisplayMetrics.height() / 5:
102+
dy_signed = y - down_start_y
103+
if dy_signed <= -(AppearanceManager.NOTIFICATION_BAR_HEIGHT // 2):
104+
topmenu.close_bar()
105+
elif y > DisplayMetrics.height() / 5:
102106
topmenu.open_drawer()
103107
elif is_short_movement(dx, dy):
104108
# print("Short movement - treating as tap")

tests/test_graphical_notification_bar.py

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,24 @@ def _wait_for_drawer_open(self, timeout_ms=2000):
8686
wait_for_render(iterations=10)
8787
return False
8888

89+
def _wait_for_bar_hidden(self, bar, timeout_ms=3500):
90+
start = time.ticks_ms()
91+
while time.ticks_diff(time.ticks_ms(), start) < timeout_ms:
92+
if not topmenu.bar_open:
93+
return True
94+
coords = get_widget_coords(bar)
95+
if coords and coords["y2"] < 0:
96+
return True
97+
wait_for_render(iterations=20)
98+
return False
99+
100+
def _ensure_bar_closed(self, bar_coords, bar):
101+
if self._swipe_up_on_bar(bar_coords, bar):
102+
return True
103+
topmenu.close_bar()
104+
wait_for_render(iterations=100)
105+
return self._wait_for_bar_hidden(bar, timeout_ms=4000)
106+
89107
def _ensure_drawer_open(self, bar_coords):
90108
if self._swipe_down_on_bar(bar_coords):
91109
return True
@@ -108,6 +126,20 @@ def _swipe_down_on_bar(self, bar_coords):
108126
wait_for_render(iterations=50)
109127
return self._wait_for_drawer_open()
110128

129+
def _swipe_up_on_bar(self, bar_coords, bar):
130+
start_x = DisplayMetrics.width() // 2
131+
start_y = max(1, (bar_coords["y1"] + bar_coords["y2"]) // 2)
132+
end_y = -AppearanceManager.NOTIFICATION_BAR_HEIGHT
133+
simulate_drag(start_x, start_y, start_x, end_y, steps=30, step_delay_ms=45)
134+
wait_for_render(iterations=80)
135+
if self._wait_for_bar_hidden(bar):
136+
return True
137+
138+
end_y = -AppearanceManager.NOTIFICATION_BAR_HEIGHT * 2
139+
simulate_drag(start_x, start_y, start_x, end_y, steps=36, step_delay_ms=45)
140+
wait_for_render(iterations=100)
141+
return self._wait_for_bar_hidden(bar)
142+
111143
def test_notification_bar_widgets_visible(self):
112144
bar = topmenu.notification_bar
113145
self.assertIsNotNone(bar, "Notification bar was not created")
@@ -117,11 +149,11 @@ def test_notification_bar_widgets_visible(self):
117149
self.assertIsNotNone(bar_coords, "Notification bar coords not available")
118150
if bar_coords["y1"] < 0:
119151
topmenu.open_bar()
120-
wait_for_render(iterations=40)
152+
wait_for_render(iterations=60)
121153
bar_coords = get_widget_coords(bar)
122154
if bar_coords and bar_coords["y1"] < 0:
123155
bar.set_y(0)
124-
wait_for_render(iterations=20)
156+
wait_for_render(iterations=30)
125157
bar_coords = get_widget_coords(bar)
126158
self.assertIsNotNone(bar_coords, "Notification bar coords not available")
127159
self.assertGreaterEqual(
@@ -181,3 +213,13 @@ def test_notification_bar_widgets_visible(self):
181213
any("Off" in text or lv.SYMBOL.POWER in text for _, text in drawer_labels),
182214
"Power-off label not found in drawer",
183215
)
216+
217+
topmenu.close_drawer()
218+
wait_for_render(iterations=40)
219+
bar_coords = get_widget_coords(bar)
220+
self.assertIsNotNone(bar_coords, "Notification bar coords not available")
221+
self.assertTrue(
222+
self._ensure_bar_closed(bar_coords, bar),
223+
"Notification bar did not close after swipe up",
224+
)
225+
self.assertFalse(topmenu.bar_open, "Notification bar is still open after swipe up")

0 commit comments

Comments
 (0)