#!/usr/bin/env python3 """NAVIGATION lane — surface REACHABILITY + back-stack integrity for EasyNotes. Every test proves a JUMP the honest way (and_reach / and_reach_surface): the TARGET surface's discriminating element APPEARED *and* the SOURCE surface's element DISAPPEARED. Deep chains (Settings subscreens = depth 2, dialogs / the note-info modal = depth 3) are owned here and are each backed by real and_enter*/and_reach* calls — never by relaunching the app. Surfaces (validated on the running original): Home content-desc New Note / Search / Settings Settings text Colors & Styles / Behavior / Language / Backup / Privacy / Tools / About (+ subtitle "Themes • Size • Font") Colors Minimalistic Mode / Radius / Font Size / Accent Color / System Theme Behavior Markdown / Prioritize Editing Mode / Gallery Sync / Disable swipe Language Change the app language / Monospace font Backup Encrypt Database / Restore / Import Privacy Screen Protection / App lock / Vault Tools Notes (+ count) About Version / Build Type / Source Code / Supporters List Edit content-desc Back / Done ; text Name / Description Preview content-desc Back / Info More menu Delete / Pinned / Copy / Information (Preview elements vanish) Info modal Created Time / Words / Characters dialogs Select Radius ; Select Accent Color+Use System Colors ; Font Size:+Preview CAUTION (learned from the running dump): uiautomator keeps "Colors & Styles" as a literal XML entity, so it can NEVER be a target/source token — every reach here uses ampersand-free discriminators (Behavior, Language, Minimalistic Mode, Build Type, ...). Likewise, a note NAME must not contain a source token like 'Done' or the disappearance check false-positives on the card text. """ import os import sys sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from android_testgen_kit import * # noqa: F403,E402 TESTS = [] def test(fn): TESTS.append(fn) return fn # ── shared entry-point helpers (plain helpers; the and_reach_*/and_enter_* NAME # is what the depth audit greps for — implementation is ours) ───────────────── def _home_nodes(): """Restart the app and return a fresh Home dump, or None on failure.""" restart_app() if not wait_for_foreground(): return None return ui() def and_reach_settings(): """Home -> Settings. Returns True on a proven reach. Counts one surface.""" nodes = ui() gear = find_node(nodes, content_desc="Settings") if gear is None: return False # target: a Settings-only section ('Behavior' — NO ampersand, because the # dump keeps "Colors & Styles" as a literal XML entity that would never # substring-match "Colors & Styles"). source: the Home FAB that leaves. return and_reach_surface(gear, "Behavior", "New Note") def and_enter_settings(): """Navigate from a fresh Home into Settings; True once on Settings.""" nodes = _home_nodes() return bool(nodes) and and_reach_settings() def and_reach_section(nodes, subtitle, target, source): """Settings -> a section subscreen, tapping the section's SUBTITLE node (whole card is clickable) to dodge the 'Colors & Styles' XML-entity matching issue. target = a body element unique to the subscreen; source = a *sibling* section name (ampersand-free) that leaves the tree.""" row = find_node_ci(nodes, subtitle) if row is None: return False return and_reach_surface(row, target, source) def and_enter_colors(): """Home -> Settings -> Colors & Styles. True once on Colors (depth 2).""" if not and_enter_settings(): return False return and_reach_section(ui(), "Themes • Size • Font", "Minimalistic Mode", "Behavior") def and_reach_preview(): """Create a note in setup, return Home, then open it -> Preview. We navigate to a record created in setup and assert the JUMP, not the creation. Returns (ok, body) where body is the note text for source-matching. Neither the name ('Groceries') nor the body ('Milk Eggs Bread') contains a surface token (Info / New Note / Done / Back), so they are safe sources. """ body = "Milk Eggs Bread" nodes = _home_nodes() if not nodes: return False, body fab = find_node(nodes, content_desc="New Note") if fab is None or not tap_node(fab): return False, body ed = ui() fields = find_by_class(ed, "EditText") if len(fields) < 2: return False, body # document order: [0]=Name, [1]=Description (validated on the original) type_text(fields[0], "Groceries") ed2 = ui() fields2 = find_by_class(ed2, "EditText") if len(fields2) >= 2: type_text(fields2[1], body) # Save & return Home via Done. done = find_node(ui(), content_desc="Done") if done is None or not tap_node(done): return False, body settle("tap") # Open the card -> Preview. Re-find the card fresh (grid recycles children). card = find_node_ci(ui(), "Groceries") if card is None: return False, body reached = and_reach_surface(card, "Info", "New Note") return reached, body def and_reach_more(preview_body): """Preview -> More dropdown. target Information appears; the note body (a Preview-only element) disappears when the dropdown overlays it.""" info = find_node(ui(), content_desc="Info") if info is None: return False return and_reach_surface(info, "Information", preview_body) # ══════════════════════════════════════════════════════════════════════════════ # 1. Home -> Settings, and each Settings subscreen (depth 1 / depth 2) # ══════════════════════════════════════════════════════════════════════════════ @test @and_test(expects=("nav_reach_settings", "nav_reach_settings_vlm")) def test_reach_settings(): nodes = _home_nodes() ok = bool(nodes) and and_reach_settings() record("nav_reach_settings", ok, "" if ok else "feature_missing: Settings not reachable from Home " "('Behavior' section did not appear / New Note did not leave)", depth=1, jump_kind="reach", expect="Settings surface: 'Behavior' section appeared; Home 'New Note' gone") vlm_assert("nav_reach_settings", "Is there a left-pointing back/up arrow at the very top-LEFT of the " "screen, to the left of a 'Settings' title?", RESULTS_DIR, depth=1, jump_kind="reach", tag="position") @test @and_test(expects=("nav_reach_colors", "nav_reach_colors_vlm")) def test_reach_colors(): ok = and_enter_settings() if ok: ok = and_reach_section(ui(), "Themes • Size • Font", "Minimalistic Mode", "Behavior") record("nav_reach_colors", ok, "" if ok else "feature_missing: Colors & Styles subscreen not reached " "(Minimalistic Mode absent / Behavior still showing)", depth=2, jump_kind="reach", expect="Colors & Styles: 'Minimalistic Mode' appeared; Settings 'Behavior' gone") vlm_assert("nav_reach_colors", "Does this screen show a vertical list of settings rows, each with a " "round icon on the LEFT and a toggle switch or chevron on the RIGHT?", RESULTS_DIR, depth=2, jump_kind="reach", tag="layout") @test @and_test(expects=("nav_reach_behavior", "nav_reach_behavior_vlm")) def test_reach_behavior(): ok = and_enter_settings() if ok: # source 'Language' (ampersand-free sibling that leaves the Settings list) ok = and_reach_section(ui(), "Support • Images", "Markdown", "Language") record("nav_reach_behavior", ok, "" if ok else "feature_missing: Behavior subscreen not reached " "(Markdown absent / Language section still showing)", depth=2, jump_kind="reach", expect="Behavior: 'Markdown' appeared; Settings 'Language' section gone") vlm_assert("nav_reach_behavior", "Is there a screen title in a top app bar with a back arrow at its " "LEFT edge?", RESULTS_DIR, depth=2, jump_kind="reach", tag="position") @test @and_test(expects=("nav_reach_language",)) def test_reach_language(): ok = and_enter_settings() if ok: ok = and_reach_section(ui(), "Font • Language", "Change the app language", "Behavior") record("nav_reach_language", ok, "" if ok else "feature_missing: Language subscreen not reached " "(language body absent / Behavior still showing)", depth=2, jump_kind="reach", expect="Language: 'Change the app language' appeared; Settings 'Behavior' gone") @test @and_test(expects=("nav_reach_backup",)) def test_reach_backup(): ok = and_enter_settings() if ok: ok = and_reach_section(ui(), "NextCloud • Local • Encryption", "Encrypt Database", "Behavior") record("nav_reach_backup", ok, "" if ok else "feature_missing: Backup subscreen not reached " "(Encrypt Database absent / Behavior still showing)", depth=2, jump_kind="reach", expect="Backup: 'Encrypt Database' appeared; Settings 'Behavior' gone") @test @and_test(expects=("nav_reach_privacy",)) def test_reach_privacy(): ok = and_enter_settings() if ok: ok = and_reach_section(ui(), "Screen Protection", "App lock", "Behavior") record("nav_reach_privacy", ok, "" if ok else "feature_missing: Privacy subscreen not reached " "(App lock absent / Behavior still showing)", depth=2, jump_kind="reach", expect="Privacy: 'App lock' appeared; Settings 'Behavior' gone") @test @and_test(expects=("nav_reach_tools",)) def test_reach_tools(): ok = and_enter_settings() if ok: ok = and_reach_section(ui(), "Created • Delete All", "Notes", "Behavior") record("nav_reach_tools", ok, "" if ok else "feature_missing: Tools subscreen not reached " "('Notes' counter absent / Behavior still showing)", depth=2, jump_kind="reach", expect="Tools: 'Notes' appeared; Settings 'Behavior' gone") @test @and_test(expects=("nav_reach_about", "nav_reach_about_vlm")) def test_reach_about(): ok = and_enter_settings() if ok: ok = and_reach_section(ui(), "Version • Developers • License", "Build Type", "Behavior") record("nav_reach_about", ok, "" if ok else "feature_missing: About subscreen not reached " "(Build Type absent / Behavior still showing)", depth=2, jump_kind="reach", expect="About: 'Build Type' appeared; Settings 'Behavior' gone") vlm_assert("nav_reach_about", "Is a screen title showing at the TOP of the screen with a back arrow " "to its LEFT?", RESULTS_DIR, depth=2, jump_kind="reach", tag="position") # ══════════════════════════════════════════════════════════════════════════════ # 2-3. Home -> New Note editor ; Home -> Preview # ══════════════════════════════════════════════════════════════════════════════ @test @and_test(expects=("nav_reach_editor", "nav_reach_editor_vlm")) def test_reach_editor(): nodes = _home_nodes() ok = False if nodes: fab = find_node(nodes, content_desc="New Note") ok = fab is not None and and_reach_surface(fab, "Done", "New Note") record("nav_reach_editor", ok, "" if ok else "feature_missing: note editor not reached from FAB " "(Done affordance absent / New Note still showing)", depth=1, jump_kind="reach", expect="Edit surface: 'Done' appeared; Home 'New Note' gone") vlm_assert("nav_reach_editor", "Is there a checkmark / done (tick) icon at the top-RIGHT corner of " "the screen?", RESULTS_DIR, depth=1, jump_kind="reach", tag="position") @test @and_test(expects=("nav_reach_editor_toggle_vlm",)) def test_reach_editor_toggle_vlm(): # Enter the editor, then ask the VLM about the centered Edit/Preview pill. nodes = _home_nodes() reached = False if nodes: fab = find_node(nodes, content_desc="New Note") reached = fab is not None and and_reach_surface(fab, "Done", "New Note") if reached: vlm_assert("nav_reach_editor_toggle", "Is there a rounded pill-shaped toggle with two icons " "(a pencil and an eye) centered at the TOP of the screen?", RESULTS_DIR, depth=1, jump_kind="reach", tag="shape") else: record("nav_reach_editor_toggle_vlm", False, "setup_failed: could not reach the editor to photograph the toggle", depth=1, jump_kind="reach", tag="shape") @test @and_test(expects=("nav_reach_preview", "nav_reach_preview_vlm")) def test_reach_preview(): ok, _body = and_reach_preview() record("nav_reach_preview", ok, "" if ok else "feature_missing: Preview not reached from a created card " "(Info affordance absent / New Note still showing)", depth=1, jump_kind="reach", expect="Preview surface: 'Info' appeared; Home 'New Note' gone") vlm_assert("nav_reach_preview", "Is there an overflow menu button (three vertical dots) at the " "top-RIGHT corner of the screen?", RESULTS_DIR, depth=1, jump_kind="reach", tag="position") # ══════════════════════════════════════════════════════════════════════════════ # 4-5. Preview -> More dropdown ; More -> Note Info modal (deep chains) # ══════════════════════════════════════════════════════════════════════════════ @test @and_test(expects=("nav_reach_more", "nav_reach_more_vlm")) def test_reach_more(): reached_preview, body = and_reach_preview() ok = reached_preview and and_reach_more(body) record("nav_reach_more", ok, "" if ok else "feature_missing: More dropdown not reached from Preview " "(Information item absent / note body still showing)", depth=2, jump_kind="reach", expect="More dropdown: 'Information' appeared; Preview note body gone") vlm_assert("nav_reach_more", "Is a small dropdown menu panel anchored near the top-RIGHT corner, " "listing rows such as Delete, Pinned, Copy and Information?", RESULTS_DIR, depth=2, jump_kind="reach", tag="position") @test @and_test(expects=("nav_reach_note_info", "nav_reach_note_info_vlm")) def test_reach_note_info(): reached_preview, body = and_reach_preview() ok = False if reached_preview and and_reach_more(body): info_item = find_node_ci(ui(), "Information") ok = info_item is not None and and_reach_surface( info_item, "Created Time", "Copy") record("nav_reach_note_info", ok, "" if ok else "feature_missing: Note Info modal not reached " "(Created Time absent / More 'Copy' still showing)", depth=3, jump_kind="reach", expect="Note Info modal: 'Created Time' appeared; More 'Copy' gone") vlm_assert("nav_reach_note_info", "Is there a panel / sheet at the BOTTOM of the screen showing labelled " "rows like 'Created Time', 'Words' and 'Characters'?", RESULTS_DIR, depth=3, jump_kind="reach", tag="position") # ══════════════════════════════════════════════════════════════════════════════ # 6. Colors & Styles -> dialogs (depth 3) # ══════════════════════════════════════════════════════════════════════════════ @test @and_test(expects=("nav_reach_fontsize_dialog", "nav_reach_fontsize_dialog_vlm")) def test_reach_fontsize_dialog(): ok = and_enter_colors() if ok: row = find_node_ci(ui(), "Font Size") ok = row is not None and and_reach_surface(row, "Preview", "Radius") record("nav_reach_fontsize_dialog", ok, "" if ok else "feature_missing: Font Size dialog not reached " "('Preview' absent / 'Radius' row still showing)", depth=3, jump_kind="reach", expect="Font Size dialog: 'Preview' appeared; Colors 'Radius' row gone") vlm_assert("nav_reach_fontsize_dialog", "Is a dialog card centered on the screen containing a horizontal " "slider control?", RESULTS_DIR, depth=3, jump_kind="reach", tag="shape") @test @and_test(expects=("nav_reach_radius_dialog",)) def test_reach_radius_dialog(): ok = and_enter_colors() if ok: row = find_node_ci(ui(), "Radius") ok = row is not None and and_reach_surface(row, "Select Radius", "Font Size") record("nav_reach_radius_dialog", ok, "" if ok else "feature_missing: Radius dialog not reached " "('Select Radius' absent / 'Font Size' row still showing)", depth=3, jump_kind="reach", expect="Radius dialog: 'Select Radius' appeared; Colors 'Font Size' row gone") @test @and_test(expects=("nav_reach_accent_dialog",)) def test_reach_accent_dialog(): ok = and_enter_colors() if ok: row = find_node_ci(ui(), "Accent Color") ok = row is not None and and_reach_surface( row, "Use System Colors", "Minimalistic Mode") record("nav_reach_accent_dialog", ok, "" if ok else "feature_missing: Accent Color dialog not reached " "('Use System Colors' absent / 'Minimalistic Mode' still showing)", depth=3, jump_kind="reach", expect="Accent dialog: 'Use System Colors' appeared; Colors 'Minimalistic Mode' gone") # ══════════════════════════════════════════════════════════════════════════════ # 7. Back-stack integrity # ══════════════════════════════════════════════════════════════════════════════ @test @and_test(expects=("nav_back_colors_to_settings",)) def test_back_colors_to_settings(): # Home -> Settings -> Colors (depth 2), then one BACK must restore Settings. reached = and_enter_colors() ok = False if reached: before = and_showing() # Colors surface and_back() # pop one surface after = and_showing() # parent (Language section) reappeared AND child (Minimalistic Mode) left. ok = and_reach(before, after, "Language", "Minimalistic Mode") record("nav_back_colors_to_settings", ok, "" if ok else "behavior_wrong: BACK from Colors did not restore Settings " "('Language' section did not reappear / Colors row still showing)", depth=2, jump_kind="reach", expect="After BACK: Settings 'Language' reappeared; Colors 'Minimalistic Mode' gone") @test @and_test(expects=("nav_back_settings_to_home",)) def test_back_settings_to_home(): reached = and_enter_settings() # Home -> Settings (depth 1) ok = False if reached: before = and_showing() # Settings surface and_back() after = and_showing() # Home FAB reappeared AND a Settings-only section (Behavior) left. ok = and_reach(before, after, "New Note", "Behavior") record("nav_back_settings_to_home", ok, "" if ok else "behavior_wrong: BACK from Settings did not restore Home " "('New Note' did not reappear / 'Behavior' still showing)", depth=1, jump_kind="reach", expect="After BACK: Home 'New Note' reappeared; Settings 'Behavior' gone") @test @and_test(expects=("nav_backstack_2hop_unwind",)) def test_backstack_2hop_unwind(): # Full deepest->home unwind: Home -> Settings -> Colors, then BACK, BACK. reached = and_enter_colors() # depth 2 via two and_reach_surface calls step1 = step2 = False if reached: before1 = and_showing() # Colors and_back() mid = and_showing() # expect Settings step1 = and_reach(before1, mid, "Behavior", "Minimalistic Mode") and_back() home = and_showing() # expect Home step2 = and_reach(mid, home, "New Note", "Behavior") ok = reached and step1 and step2 record("nav_backstack_2hop_unwind", ok, "" if ok else "behavior_wrong: 2-hop BACK did not unwind Colors->Settings->Home " "hop by hop", depth=2, jump_kind="reach", expect="BACK #1 -> Settings ('Behavior' back), BACK #2 -> Home ('New Note' back)") # ══════════════════════════════════════════════════════════════════════════════ # 8. Editor -> Home via Back and via Done # ══════════════════════════════════════════════════════════════════════════════ @test @and_test(expects=("nav_back_editor_to_home",)) def test_back_editor_to_home(): nodes = _home_nodes() reached = False if nodes: fab = find_node(nodes, content_desc="New Note") reached = fab is not None and and_reach_surface(fab, "Done", "New Note") ok = False if reached: before = and_showing() # Edit surface and_back() # empty note discarded, returns Home after = and_showing() ok = and_reach(before, after, "New Note", "Done") record("nav_back_editor_to_home", ok, "" if ok else "behavior_wrong: BACK from the editor did not restore Home " "('New Note' did not reappear / 'Done' still showing)", depth=1, jump_kind="reach", expect="After BACK: Home 'New Note' reappeared; editor 'Done' gone") @test @and_test(expects=("nav_done_editor_to_home",)) def test_done_editor_to_home(): nodes = _home_nodes() reached = False if nodes: fab = find_node(nodes, content_desc="New Note") reached = fab is not None and and_reach_surface(fab, "Done", "New Note") ok = False if reached: # Name the note something WITHOUT the source token 'Done' (else the card # text keeps a 'done' key alive and the disappearance check fails). fields = find_by_class(ui(), "EditText") if fields: type_text(fields[0], "SaveNav") done = find_node(ui(), content_desc="Done") if done is not None: before = and_showing() # Edit surface tap_node(done) after = and_showing() ok = and_reach(before, after, "New Note", "Done") record("nav_done_editor_to_home", ok, "" if ok else "behavior_wrong: Done did not return to Home " "('New Note' did not reappear / 'Done' still showing)", depth=1, jump_kind="reach", expect="After Done: Home 'New Note' reappeared; editor 'Done' gone") # ══════════════════════════════════════════════════════════════════════════════ # Preview -> back to Home (back-stack of a note preview) # ══════════════════════════════════════════════════════════════════════════════ @test @and_test(expects=("nav_back_preview_to_home",)) def test_back_preview_to_home(): reached, _body = and_reach_preview() ok = False if reached: before = and_showing() # Preview surface and_back() after = and_showing() ok = and_reach(before, after, "New Note", "Info") record("nav_back_preview_to_home", ok, "" if ok else "behavior_wrong: BACK from Preview did not restore Home " "('New Note' did not reappear / 'Info' still showing)", depth=1, jump_kind="reach", expect="After BACK: Home 'New Note' reappeared; Preview 'Info' gone") if __name__ == "__main__": if not device_online(): print("device offline — aborting navigation suite") sys.exit(2) run_suite(TESTS, "navigation")