Skip to content

Commit 7f69276

Browse files
Cleanup drag simulation
1 parent 3fbd546 commit 7f69276

3 files changed

Lines changed: 40 additions & 15 deletions

File tree

-8.81 KB
Loading

internal_filesystem/lib/mpos/ui/testing.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"""
4343

4444
import lvgl as lv
45+
import sys
4546
import time
4647

4748
try:
@@ -1141,6 +1142,11 @@ def simulate_drag(start_x, start_y, end_x, end_y, steps=5, step_delay_ms=20):
11411142
"""
11421143
Simulate a drag gesture from start to end coordinates.
11431144
1145+
On desktop (Linux/macOS/Windows), uses a stepped approach with
1146+
discrete click+render at each interpolated point, which is proven
1147+
reliable with the LVGL unix port. On device (ESP32), uses a
1148+
continuous press-and-drag for real touch input.
1149+
11441150
Args:
11451151
start_x: Starting X coordinate.
11461152
start_y: Starting Y coordinate.
@@ -1149,6 +1155,37 @@ def simulate_drag(start_x, start_y, end_x, end_y, steps=5, step_delay_ms=20):
11491155
steps: Number of intermediate steps to simulate (default: 5).
11501156
step_delay_ms: Delay between steps in milliseconds (default: 20).
11511157
"""
1158+
if sys.platform in ("linux", "darwin", "win32"):
1159+
global _touch_x, _touch_y, _touch_pressed
1160+
1161+
_ensure_touch_indev()
1162+
n = max(steps, 1)
1163+
1164+
_touch_x = start_x
1165+
_touch_y = start_y
1166+
_touch_pressed = True
1167+
1168+
_touch_indev.read()
1169+
time.sleep(0.01)
1170+
_touch_indev.read()
1171+
time.sleep(step_delay_ms / 1000.0)
1172+
1173+
for i in range(1, n + 1):
1174+
_touch_x = start_x + (end_x - start_x) * i // n
1175+
_touch_y = start_y + (end_y - start_y) * i // n
1176+
_touch_indev.read()
1177+
time.sleep(0.01)
1178+
_touch_indev.read()
1179+
time.sleep(step_delay_ms / 1000.0)
1180+
1181+
_touch_pressed = False
1182+
_touch_indev.read()
1183+
time.sleep(0.01)
1184+
_touch_indev.read()
1185+
time.sleep(0.01)
1186+
_touch_indev.read()
1187+
return
1188+
11521189
global _touch_x, _touch_y, _touch_pressed
11531190

11541191
_ensure_touch_indev()

tests/test_graphical_notification_bar.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -102,22 +102,10 @@ def _wait_for_bar_hidden(self, bar, timeout_ms=4500):
102102
return False
103103

104104
def _ensure_bar_closed(self, bar_coords, bar):
105-
if self._swipe_up_on_bar(bar_coords, bar):
106-
return True
107-
topmenu.close_bar()
108-
wait_for_render(iterations=120)
109-
if self._wait_for_bar_hidden(bar, timeout_ms=4500):
110-
return True
111-
topmenu.close_bar()
112-
wait_for_render(iterations=120)
113-
return self._wait_for_bar_hidden(bar, timeout_ms=4500)
105+
return self._swipe_up_on_bar(bar_coords, bar)
114106

115107
def _ensure_drawer_open(self, bar_coords):
116-
if self._swipe_down_on_bar(bar_coords):
117-
return True
118-
topmenu.open_drawer()
119-
wait_for_render(iterations=80)
120-
return self._wait_for_drawer_open(timeout_ms=2500)
108+
return self._swipe_down_on_bar(bar_coords)
121109

122110
def _swipe_down_on_bar(self, bar_coords):
123111
start_x = DisplayMetrics.width() // 2
@@ -188,7 +176,7 @@ def test_notification_bar_widgets_visible(self):
188176

189177
self.assertTrue(
190178
self._ensure_drawer_open(bar_coords),
191-
"Drawer did not open after swipe or fallback open",
179+
"Drawer did not open after swipe",
192180
)
193181
self.assertTrue(topmenu.drawer_open, "Drawer state not open after swipe")
194182
self.assertIsNotNone(topmenu.drawer, "Drawer object not found after swipe")

0 commit comments

Comments
 (0)