|
10 | 10 | """ |
11 | 11 |
|
12 | 12 | import unittest |
| 13 | +import time |
13 | 14 | import lvgl as lv |
14 | 15 | import mpos.ui |
15 | | -from mpos import AppManager, WifiService, wait_for_render, click_button, print_screen_labels |
| 16 | +from mpos import ( |
| 17 | + AppManager, |
| 18 | + WifiService, |
| 19 | + wait_for_render, |
| 20 | + click_button, |
| 21 | + print_screen_labels, |
| 22 | + get_widget_coords, |
| 23 | + simulate_click, |
| 24 | +) |
16 | 25 |
|
17 | 26 |
|
18 | 27 | class TestGraphicalHotspotThenStation(unittest.TestCase): |
19 | 28 | """Test hotspot start flow via the hotspot settings app.""" |
20 | 29 |
|
| 30 | + def _find_first_list_item(self, screen): |
| 31 | + def find_list(node): |
| 32 | + try: |
| 33 | + if node.__class__.__name__ == "list": |
| 34 | + return node |
| 35 | + except Exception: |
| 36 | + pass |
| 37 | + try: |
| 38 | + if hasattr(node, "add_button") and hasattr(node, "get_child_count"): |
| 39 | + return node |
| 40 | + except Exception: |
| 41 | + pass |
| 42 | + try: |
| 43 | + child_count = node.get_child_count() |
| 44 | + except Exception: |
| 45 | + child_count = 0 |
| 46 | + for i in range(child_count): |
| 47 | + child = node.get_child(i) |
| 48 | + found = find_list(child) |
| 49 | + if found: |
| 50 | + return found |
| 51 | + return None |
| 52 | + |
| 53 | + wifi_list = find_list(screen) |
| 54 | + if wifi_list is None: |
| 55 | + return None |
| 56 | + try: |
| 57 | + if wifi_list.get_child_count() < 1: |
| 58 | + return None |
| 59 | + return wifi_list.get_child(0) |
| 60 | + except Exception: |
| 61 | + return None |
| 62 | + |
21 | 63 | def tearDown(self): |
22 | 64 | """Clean up after each test method.""" |
23 | 65 | try: |
@@ -64,6 +106,44 @@ def test_hotspot_start_button_enables_hotspot(self): |
64 | 106 | "Hotspot should be enabled after pressing Start", |
65 | 107 | ) |
66 | 108 |
|
| 109 | + result = AppManager.start_app("com.micropythonos.settings.wifi") |
| 110 | + self.assertTrue(result, "Failed to start WiFi settings app") |
| 111 | + wait_for_render(iterations=20) |
| 112 | + |
| 113 | + screen = lv.screen_active() |
| 114 | + print("\nWiFi screen labels (before scan wait):") |
| 115 | + print_screen_labels(screen) |
| 116 | + |
| 117 | + print("\nWaiting 10 seconds for WiFi scan to finish...") |
| 118 | + time.sleep(10) |
| 119 | + wait_for_render(iterations=20) |
| 120 | + |
| 121 | + screen = lv.screen_active() |
| 122 | + print("\nWiFi screen labels (after scan wait):") |
| 123 | + print_screen_labels(screen) |
| 124 | + |
| 125 | + first_item = self._find_first_list_item(screen) |
| 126 | + self.assertIsNotNone(first_item, "Could not find first WiFi access point") |
| 127 | + |
| 128 | + coords = get_widget_coords(first_item) |
| 129 | + if coords: |
| 130 | + print(f"Clicking first WiFi access point at ({coords['center_x']}, {coords['center_y']})") |
| 131 | + first_item.send_event(lv.EVENT.CLICKED, None) |
| 132 | + else: |
| 133 | + first_item.send_event(lv.EVENT.CLICKED, None) |
| 134 | + wait_for_render(iterations=40) |
| 135 | + |
| 136 | + self.assertTrue( |
| 137 | + click_button("Connect"), |
| 138 | + "Could not find Connect button in WiFi edit screen", |
| 139 | + ) |
| 140 | + wait_for_render(iterations=40) |
| 141 | + |
| 142 | + self.assertFalse( |
| 143 | + WifiService.is_hotspot_enabled(), |
| 144 | + "Hotspot should be disabled after connecting to a WiFi access point", |
| 145 | + ) |
| 146 | + |
67 | 147 | print("\n=== Hotspot start-flow test completed ===") |
68 | 148 |
|
69 | 149 |
|
|
0 commit comments