|
| 1 | +""" |
| 2 | +Graphical test for hotspot settings refreshing overview values. |
| 3 | +
|
| 4 | +This test verifies: |
| 5 | +1) Auth Mode changes in settings are reflected on the hotspot overview. |
| 6 | +2) SSID changes in settings are reflected on the hotspot overview. |
| 7 | +
|
| 8 | +Usage: |
| 9 | + Desktop: ./tests/unittest.sh tests/test_graphical_hotspot_settings.py |
| 10 | + Device: ./tests/unittest.sh tests/test_graphical_hotspot_settings.py --ondevice |
| 11 | +""" |
| 12 | + |
| 13 | +import unittest |
| 14 | +import lvgl as lv |
| 15 | +import mpos.ui |
| 16 | +from mpos import ( |
| 17 | + AppManager, |
| 18 | + SharedPreferences, |
| 19 | + WifiService, |
| 20 | + wait_for_render, |
| 21 | + click_button, |
| 22 | + click_label, |
| 23 | + print_screen_labels, |
| 24 | + verify_text_present, |
| 25 | + find_dropdown_widget, |
| 26 | + select_dropdown_option_by_text, |
| 27 | + get_widget_coords, |
| 28 | + simulate_click, |
| 29 | +) |
| 30 | + |
| 31 | + |
| 32 | +class TestGraphicalHotspotSettings(unittest.TestCase): |
| 33 | + """Graphical tests for hotspot settings refresh.""" |
| 34 | + |
| 35 | + def _reset_hotspot_preferences(self): |
| 36 | + prefs = SharedPreferences("com.micropythonos.settings.hotspot") |
| 37 | + editor = prefs.edit() |
| 38 | + editor.remove_all() |
| 39 | + editor.commit() |
| 40 | + |
| 41 | + def _open_hotspot_settings_screen(self): |
| 42 | + result = AppManager.start_app("com.micropythonos.settings.hotspot") |
| 43 | + self.assertTrue(result, "Failed to start hotspot settings app") |
| 44 | + wait_for_render(iterations=20) |
| 45 | + |
| 46 | + screen = lv.screen_active() |
| 47 | + print("\nHotspot overview labels:") |
| 48 | + print_screen_labels(screen) |
| 49 | + |
| 50 | + self.assertTrue( |
| 51 | + click_button("Settings"), |
| 52 | + "Could not find Settings button in hotspot app", |
| 53 | + ) |
| 54 | + wait_for_render(iterations=40) |
| 55 | + |
| 56 | + screen = lv.screen_active() |
| 57 | + print("\nHotspot settings labels:") |
| 58 | + print_screen_labels(screen) |
| 59 | + return screen |
| 60 | + |
| 61 | + def _find_textarea(self, node): |
| 62 | + try: |
| 63 | + if node.__class__.__name__ == "textarea": |
| 64 | + return node |
| 65 | + if hasattr(node, "set_one_line") and hasattr(node, "set_text") and hasattr(node, "get_text"): |
| 66 | + return node |
| 67 | + except Exception: |
| 68 | + pass |
| 69 | + |
| 70 | + try: |
| 71 | + child_count = node.get_child_count() |
| 72 | + except Exception: |
| 73 | + return None |
| 74 | + |
| 75 | + for i in range(child_count): |
| 76 | + child = node.get_child(i) |
| 77 | + result = self._find_textarea(child) |
| 78 | + if result: |
| 79 | + return result |
| 80 | + return None |
| 81 | + |
| 82 | + def tearDown(self): |
| 83 | + try: |
| 84 | + WifiService.disable_hotspot() |
| 85 | + except Exception: |
| 86 | + pass |
| 87 | + |
| 88 | + try: |
| 89 | + mpos.ui.back_screen() |
| 90 | + wait_for_render(5) |
| 91 | + except Exception: |
| 92 | + pass |
| 93 | + |
| 94 | + def test_auth_mode_change_updates_overview_security(self): |
| 95 | + """Verify Auth Mode change is reflected on the hotspot overview.""" |
| 96 | + print("\n=== Starting hotspot Auth Mode overview refresh test ===") |
| 97 | + |
| 98 | + self._reset_hotspot_preferences() |
| 99 | + self._open_hotspot_settings_screen() |
| 100 | + |
| 101 | + self.assertTrue( |
| 102 | + click_label("Auth Mode"), |
| 103 | + "Could not click Auth Mode setting", |
| 104 | + ) |
| 105 | + wait_for_render(iterations=40) |
| 106 | + |
| 107 | + screen = lv.screen_active() |
| 108 | + dropdown = find_dropdown_widget(screen) |
| 109 | + self.assertIsNotNone(dropdown, "Auth Mode dropdown not found") |
| 110 | + |
| 111 | + coords = get_widget_coords(dropdown) |
| 112 | + self.assertIsNotNone(coords, "Could not get dropdown coordinates") |
| 113 | + |
| 114 | + print(f"Clicking dropdown at ({coords['center_x']}, {coords['center_y']})") |
| 115 | + simulate_click(coords["center_x"], coords["center_y"], press_duration_ms=100) |
| 116 | + wait_for_render(iterations=20) |
| 117 | + |
| 118 | + self.assertTrue( |
| 119 | + select_dropdown_option_by_text(dropdown, "WPA2", allow_partial=True), |
| 120 | + "Could not select WPA2 option in dropdown", |
| 121 | + ) |
| 122 | + wait_for_render(iterations=20) |
| 123 | + |
| 124 | + self.assertTrue( |
| 125 | + click_button("Save"), |
| 126 | + "Could not click Save button in Auth Mode settings", |
| 127 | + ) |
| 128 | + wait_for_render(iterations=40) |
| 129 | + |
| 130 | + mpos.ui.back_screen() |
| 131 | + wait_for_render(iterations=20) |
| 132 | + |
| 133 | + screen = lv.screen_active() |
| 134 | + print("\nHotspot overview labels after Auth Mode change:") |
| 135 | + print_screen_labels(screen) |
| 136 | + self.assertTrue( |
| 137 | + verify_text_present(screen, "Security: WPA2"), |
| 138 | + "Hotspot overview did not update Security after Auth Mode change", |
| 139 | + ) |
| 140 | + |
| 141 | + print("\n=== Hotspot Auth Mode overview refresh test completed ===") |
| 142 | + |
| 143 | + def test_ssid_change_updates_overview_name(self): |
| 144 | + """Verify SSID change is reflected on the hotspot overview.""" |
| 145 | + print("\n=== Starting hotspot SSID overview refresh test ===") |
| 146 | + |
| 147 | + new_ssid = "MPOS-Test-SSID" |
| 148 | + |
| 149 | + self._reset_hotspot_preferences() |
| 150 | + self._open_hotspot_settings_screen() |
| 151 | + |
| 152 | + self.assertTrue( |
| 153 | + click_label("Network Name (SSID)"), |
| 154 | + "Could not click Network Name (SSID) setting", |
| 155 | + ) |
| 156 | + wait_for_render(iterations=40) |
| 157 | + |
| 158 | + screen = lv.screen_active() |
| 159 | + textarea = self._find_textarea(screen) |
| 160 | + self.assertIsNotNone(textarea, "SSID textarea not found") |
| 161 | + textarea.set_text(new_ssid) |
| 162 | + wait_for_render(iterations=10) |
| 163 | + |
| 164 | + self.assertTrue( |
| 165 | + click_button("Save"), |
| 166 | + "Could not click Save button in SSID settings", |
| 167 | + ) |
| 168 | + wait_for_render(iterations=40) |
| 169 | + |
| 170 | + mpos.ui.back_screen() |
| 171 | + wait_for_render(iterations=20) |
| 172 | + |
| 173 | + screen = lv.screen_active() |
| 174 | + print("\nHotspot overview labels after SSID change:") |
| 175 | + print_screen_labels(screen) |
| 176 | + self.assertTrue( |
| 177 | + verify_text_present(screen, f"Hotspot name: {new_ssid}"), |
| 178 | + "Hotspot overview did not update SSID after settings change", |
| 179 | + ) |
| 180 | + |
| 181 | + print("\n=== Hotspot SSID overview refresh test completed ===") |
| 182 | + |
| 183 | + |
| 184 | +if __name__ == "__main__": |
| 185 | + pass |
0 commit comments