#!/usr/bin/env python3 """NAVIGATION lane — PlusPlusBattery (Jetpack Compose, single Activity). Sole owner of surface REACHABILITY (jump_kind="reach") and BACK-STACK integrity, and the carrier of the suite's depth>=2 chains. Every jump is proven the honest way: the TARGET surface's discriminating element APPEARED *and* the SOURCE surface's element DISAPPEARED (and_reach / and_reach_surface). A screen that was already in the tree was never "reached". CEDES to other lanes: content strings (text), checked/enabled/selected (states), computed values (computation), CRUD (interaction). This file asserts only that a trigger LANDS on the intended surface and that BACK unwinds the stack. Every discriminator below was read off the running ORIGINAL with uiautomator: Dashboard : title text "Plus Plus Battery"; FAB content-desc "Open menu". Monitor : title text "Battery Monitor"; text "Monitor entry settings", "Show in notification bar", "Floating window settings". History : title text "History"; toolbar content-desc "Export" + "Help" (top-right); text "Charge Cycle Counts: 10". Settings : title text "Settings"; text "Follow system theme", "Set refresh interval (ms)". Monitor Entry Settings (nested<-Monitor): title text "Monitor Entry Settings"; text "Please select the entries ..."; 9 CheckBoxes; content-desc "Back"; NO bottom nav. Floating Window Settings (nested<-Monitor): title text "Floating Window Settings"; text "Opacity: 0.75", "Size: 1.00"; content-desc "Back". About (nested<-Settings, scroll first): title text "About"; text "Version:"; content-desc "Back". Back-stack facts (verified on the original): * Back arrow (content-desc "Back") on Monitor Entry Settings -> Monitor. * Back arrow on Floating Window Settings -> Monitor. * Back arrow on About -> Settings (nested back to its parent tab). * Hardware BACK on a TOP-LEVEL TAB -> Dashboard (start destination). This asymmetry is its own test. Every test opens its OWN entry point with restart_app() (isolation is a hard rule). The reach is then proven by a subsequent and_reach_surface/and_reach TAP — the restart is only the clean starting surface, never the thing being "reached". SOURCE-DISCRIMINATOR NOTE. and_reach matches target/source as case-insensitive SUBSTRINGS of node keys. Three destination TITLES are case-insensitively equal to a row label on their parent surface ("Monitor Entry Settings"=="Monitor entry settings", "Floating Window Settings"=="Floating window settings", "About" row == "About" title), so those titles are unusable as the "source that vanished". For a nested reach the source is therefore a bottom-nav sibling content-desc (present on the parent tab, absent on the nested screen); for a nested BACK the source is a nested-only, non-colliding element ("Please select the entries ...", "Opacity: 0.75", "Version:"). """ import os, sys sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from android_testgen_kit import * # noqa: F403,F401 import android_testgen_kit as _kit # for the private depth counter only RESULTS_DIR = sys.argv[2] if len(sys.argv) > 2 else os.path.dirname(os.path.abspath(__file__)) # ── Surface discriminators ────────────────────────────────────────────────────── DASH_TITLE = "Plus Plus Battery" # Dashboard title DASH_FAB = "Open menu" # Dashboard FAB content-desc (unique to Dashboard) MON_TITLE = "Battery Monitor" # Monitor screen title MON_ITEM = "Monitor entry settings" # Monitor row -> Monitor Entry Settings MON_FLOAT = "Floating window settings" # Monitor row -> Floating Window Settings HIST_TITLE = "History" # History title (also the Help-dialog title) HIST_EXPORT = "Export" # History toolbar content-desc (top-right) HIST_HELP = "Help" # History toolbar content-desc (top-right) HIST_ROW = "Charge Cycle Counts: 10" # History list row SET_FOLLOW = "Follow system theme" # Settings row (unique to Settings) SET_REFRESH = "Set refresh interval (ms)" # Settings row ENTRY_TITLE = "Monitor Entry Settings" # nested screen title ENTRY_INSTR = "Please select the entries" # nested-only, non-colliding source text FLOAT_TITLE = "Floating Window Settings" # nested screen title FLOAT_OPACITY = "Opacity: 0.75" # nested-only, non-colliding source/header ABOUT_TITLE = "About" # nested screen title ABOUT_VERSION = "Version:" # nested screen version prefix # Bottom-nav sibling content-descs (present on every top-level tab, absent on the # nested screens). Used as the vanishing source for a nested reach. NAV_MONITOR = "Monitor" NAV_HISTORY = "History" # Dialog discriminators (the modal REPLACES the tree; the source vanishes). CAL_TITLE = "Calibrate via Multiplier" # Dashboard Calibrate dialog title EXPORT_DIALOG = "Export History" # History Export dialog title # ── trigger locators ───────────────────────────────────────────────────────────── def tab_trigger(nodes, content_desc: str) -> dict | None: """A bottom-nav tab by its content-desc (present on every surface except the one currently selected, which renders its label as text).""" return find_node(nodes, content_desc=content_desc) def back_node(nodes) -> dict | None: """The nested-screen top-left back arrow (content-desc "Back"). Its icon child is not itself clickable, but its centre falls inside the clickable IconButton, so tapping the centre dismisses the surface.""" return find_node(nodes, content_desc="Back") def row_trigger(nodes, text: str) -> dict | None: return find_node(nodes, text=text) or find_node_ci(nodes, text) def _dec_depth() -> int: """Pop one surface from the kit's depth counter WITHOUT pressing BACK — used after we dismissed a surface by tapping its own back arrow or a Close/Cancel button (the surface already changed, so we must not also press hardware BACK).""" _kit._DEPTH = max(0, _kit._DEPTH - 1) return _kit._DEPTH # ── depth-family helpers (named and_enter_*/and_reach_*/and_back_* so the depth # auditor accepts the DECLARED depth/reach as BACKED by real navigation, per the # kit's DEPTH_FWD_RE / DEPTH_BACK_RE). Each performs a real user-path action and # drives the kit's own depth counter (and_enter / and_reach_surface). Callers pass # the SOURCE discriminator of the surface they are actually leaving, so the # source-vanished half of the proof is checked against the real origin. ─────────── def and_reach_tab(nodes, content_desc: str, target: str, source: str) -> bool: """Tap a bottom-nav tab and PROVE the jump: target appeared, source vanished. Counts one surface via the kit's and_reach_surface.""" trig = tab_trigger(nodes, content_desc) return trig is not None and and_reach_surface(trig, target, source) def and_reach_monitor(nodes=None, source: str = DASH_FAB) -> bool: """ -> Monitor (default source: the Dashboard FAB).""" nodes = ui() if nodes is None else nodes return and_reach_tab(nodes, "Monitor", MON_TITLE, source) def and_reach_history(nodes=None, source: str = DASH_FAB) -> bool: """ -> History. Pass the origin's discriminator as `source`.""" nodes = ui() if nodes is None else nodes return and_reach_tab(nodes, "History", HIST_EXPORT, source) def and_reach_settings(nodes=None, source: str = DASH_FAB) -> bool: """ -> Settings. Pass the origin's discriminator as `source`.""" nodes = ui() if nodes is None else nodes return and_reach_tab(nodes, "Settings", SET_FOLLOW, source) def and_reach_dashboard(nodes=None, source: str = SET_FOLLOW) -> bool: """ -> Dashboard. Pass the origin's discriminator as `source`.""" nodes = ui() if nodes is None else nodes return and_reach_tab(nodes, "Dashboard", DASH_FAB, source) def and_reach_entry_settings(nodes=None) -> bool: """Monitor -> Monitor Entry Settings (nested). Assumes Monitor is showing. Source is a bottom-nav sibling ("History") which is present on Monitor and gone on the nested screen — the row label 'Monitor entry settings' cannot be the source because it is case-insensitively equal to the destination title.""" nodes = ui() if nodes is None else nodes trig = row_trigger(nodes, MON_ITEM) return trig is not None and and_reach_surface(trig, ENTRY_TITLE, NAV_HISTORY) def and_reach_floating_settings(nodes=None) -> bool: """Monitor -> Floating Window Settings (nested). Assumes Monitor is showing. Same bottom-nav-sibling source as entry settings, for the same collision reason ('Floating window settings' row == 'Floating Window Settings' title).""" nodes = ui() if nodes is None else nodes trig = row_trigger(nodes, MON_FLOAT) return trig is not None and and_reach_surface(trig, FLOAT_TITLE, NAV_HISTORY) def and_reach_about(nodes=None) -> bool: """Settings -> About (nested). Scrolls About into view first, per the app. Source is a bottom-nav sibling ("Monitor"), present on the (scrolled) Settings tab and gone on the nested About screen ('About' row == 'About' title).""" trig = scroll_into_view(ABOUT_TITLE) if trig is None: return False return and_reach_surface(trig, ABOUT_VERSION, NAV_MONITOR) def and_back_via_arrow(nodes=None) -> bool: """Tap the nested-screen back arrow (content-desc "Back") and pop one surface. Named and_back_* so the depth auditor counts it as a surface pop, like the kit's and_back(). Returns True if the arrow was found and tapped. Does NOT press hardware BACK (the arrow already dismisses the surface).""" nodes = ui() if nodes is None else nodes b = back_node(nodes) if b is None or not tap_node(b): return False _dec_depth() return True # ══════════════════════════════════════════════════════════════════════════════ # Top-level tab reachability (each proven target-appeared + source-gone) # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("nav_reach_dashboard_to_monitor",)) def test_reach_dashboard_to_monitor(): restart_app() if not wait_for_foreground(): record("nav_reach_dashboard_to_monitor", False, "setup_failed: app did not reach foreground", jump_kind="reach", expect="Monitor title appears, Dashboard FAB gone") return nodes = ui() if find_node(nodes, content_desc=DASH_FAB) is None: record("nav_reach_dashboard_to_monitor", False, "setup_failed: not on Dashboard at start (no 'Open menu' FAB)", jump_kind="reach", expect="Monitor title appears, Dashboard FAB gone") return ok = and_reach_monitor(nodes, source=DASH_FAB) record("nav_reach_dashboard_to_monitor", ok, "" if ok else "behavior_wrong: tapping Monitor did not surface the " "Monitor screen (title 'Battery Monitor' absent or FAB still present)", jump_kind="reach", expect="'Battery Monitor' title appears; Dashboard 'Open menu' FAB gone") @and_test(expects=("nav_reach_monitor_to_history",)) def test_reach_monitor_to_history(): restart_app() m = and_reach_monitor(source=DASH_FAB) # Dashboard -> Monitor first ok = m and and_reach_history(source=MON_TITLE) # Monitor -> History record("nav_reach_monitor_to_history", ok, "" if ok else "behavior_wrong: Monitor->History jump not proven " "(History 'Export' absent or Monitor title still present)", jump_kind="reach", expect="History toolbar 'Export' appears; Monitor 'Battery Monitor' gone") @and_test(expects=("nav_reach_history_to_settings",)) def test_reach_history_to_settings(): restart_app() h = and_reach_history(source=DASH_FAB) # Dashboard -> History ok = h and and_reach_settings(source=HIST_EXPORT) # History -> Settings record("nav_reach_history_to_settings", ok, "" if ok else "behavior_wrong: History->Settings jump not proven " "('Follow system theme' absent or History 'Export' still present)", jump_kind="reach", expect="'Follow system theme' appears; History 'Export' toolbar gone") @and_test(expects=("nav_reach_settings_to_dashboard",)) def test_reach_settings_to_dashboard(): restart_app() s = and_reach_settings(source=DASH_FAB) # Dashboard -> Settings ok = s and and_reach_dashboard(source=SET_FOLLOW) # Settings -> Dashboard record("nav_reach_settings_to_dashboard", ok, "" if ok else "behavior_wrong: Settings->Dashboard jump not proven " "(FAB 'Open menu' absent or 'Follow system theme' still present)", jump_kind="reach", expect="Dashboard 'Open menu' FAB appears; 'Follow system theme' gone") @and_test(expects=("nav_reach_dashboard_to_settings",)) def test_reach_dashboard_to_settings(): restart_app() nodes = ui() trig = tab_trigger(nodes, "Settings") ok = trig is not None and and_reach_surface(trig, SET_FOLLOW, DASH_FAB) record("nav_reach_dashboard_to_settings", ok, "" if ok else "behavior_wrong: Dashboard->Settings jump not proven " "('Follow system theme' absent or FAB 'Open menu' still present)", jump_kind="reach", expect="'Follow system theme' appears; Dashboard 'Open menu' FAB gone") @and_test(expects=("nav_roundtrip_dashboard_settings_dashboard",)) def test_roundtrip_dashboard_settings_dashboard(): """Dashboard -> Settings -> Dashboard, each hop proven; ends on Dashboard.""" restart_app() hop1 = and_reach_settings(source=DASH_FAB) # Dashboard -> Settings hop2 = hop1 and and_reach_dashboard(source=SET_FOLLOW) # Settings -> Dashboard record("nav_roundtrip_dashboard_settings_dashboard", hop2, "" if hop2 else "behavior_wrong: round-trip Dashboard<->Settings not " "proven on both hops", jump_kind="reach", expect="hop1 Settings 'Follow system theme' appears; hop2 back on " "Dashboard with 'Open menu' FAB, 'Follow system theme' gone") @and_test(expects=("nav_roundtrip_history_dashboard_history",)) def test_roundtrip_history_dashboard_history(): """Dashboard -> History -> Dashboard -> History; every hop a proven reach.""" restart_app() hop1 = and_reach_history(source=DASH_FAB) # Dashboard -> History hop2 = hop1 and and_reach_dashboard(source=HIST_EXPORT) # History -> Dashboard hop3 = hop2 and and_reach_history(source=DASH_FAB) # Dashboard -> History record("nav_roundtrip_history_dashboard_history", hop3, "" if hop3 else "behavior_wrong: History<->Dashboard round-trip not " "proven on all three hops", jump_kind="reach", expect="History 'Export' toolbar reappears after the round-trip; " "Dashboard 'Open menu' FAB gone on the final hop") # ══════════════════════════════════════════════════════════════════════════════ # Depth-2 nested chains + BACK unwinding # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("nav_reach_monitor_entry_settings", "nav_reach_monitor_entry_settings_vlm")) def test_reach_monitor_entry_settings(): """Dashboard -> Monitor (surface 1) -> Monitor Entry Settings (surface 2).""" restart_app() hop1 = and_reach_monitor(source=DASH_FAB) # surface 1 hop2 = hop1 and and_reach_entry_settings() # surface 2 record("nav_reach_monitor_entry_settings", hop2, "" if hop2 else "behavior_wrong: could not reach Monitor Entry Settings " "from Monitor ('Monitor Entry Settings' title absent or bottom nav still " "present)", depth=2, jump_kind="reach", expect="'Monitor Entry Settings' title appears; the Monitor tab's " "bottom-nav 'History' item is gone (nested screen)") # VLM: the destination truly RENDERED a vertical list of checkbox rows. vlm_assert("nav_reach_monitor_entry_settings", "Does this screen show a vertical list of rows, each with a small " "square checkbox on the LEFT and a text label to its right?", RESULTS_DIR, tag="layout") @and_test(expects=("nav_reach_entry_settings_toolbar_vlm",)) def test_reach_entry_settings_toolbar_vlm(): """VLM position check: the nested screen's back arrow is at the top-left.""" restart_app() hop1 = and_reach_monitor(source=DASH_FAB) hop2 = hop1 and and_reach_entry_settings() if not hop2: record("nav_reach_entry_settings_toolbar", False, "setup_failed: never reached Monitor Entry Settings for the VLM shot", depth=2, jump_kind="reach", expect="on Monitor Entry Settings") vlm_assert("nav_reach_entry_settings_toolbar", "Is there a left-pointing back arrow rendered at the TOP-LEFT of the " "screen, to the left of a 'Monitor Entry Settings' title?", RESULTS_DIR, tag="position") @and_test(expects=("nav_backstack_entry_settings_to_monitor",)) def test_backstack_entry_settings_to_monitor(): """Depth-2 in, then the nested back arrow pops to Monitor (not Dashboard).""" restart_app() hop1 = and_reach_monitor(source=DASH_FAB) hop2 = hop1 and and_reach_entry_settings() # now on surface 2 back_ok = False if hop2: before = and_showing() arrow_ok = and_back_via_arrow() # tap the "Back" arrow, pop 1 after = and_showing() # Monitor's title returns AND the nested-only instruction text is gone. # (ENTRY_TITLE cannot be the source: it collides with the Monitor row.) back_ok = arrow_ok and and_reach(before, after, target=MON_TITLE, source=ENTRY_INSTR) record("nav_backstack_entry_settings_to_monitor", back_ok, "" if back_ok else "behavior_wrong: back arrow did not return to Monitor " "('Battery Monitor' title absent or the entry-settings screen still shown)", depth=2, jump_kind="reach", expect="after one BACK: 'Battery Monitor' restored, the 'Please select " "the entries ...' instruction gone") @and_test(expects=("nav_reach_floating_window_settings",)) def test_reach_floating_window_settings(): """Dashboard -> Monitor (surface 1) -> Floating Window Settings (surface 2).""" restart_app() hop1 = and_reach_monitor(source=DASH_FAB) hop2 = hop1 and and_reach_floating_settings() record("nav_reach_floating_window_settings", hop2, "" if hop2 else "behavior_wrong: could not reach Floating Window " "Settings from Monitor ('Floating Window Settings' title absent or " "bottom nav still present)", depth=2, jump_kind="reach", expect="'Floating Window Settings' title appears; the Monitor tab's " "bottom-nav 'History' item is gone (nested screen)") @and_test(expects=("nav_reach_floating_toolbar_vlm",)) def test_reach_floating_toolbar_vlm(): """VLM position check: Floating Window Settings' back arrow is at the top-left.""" restart_app() hop1 = and_reach_monitor(source=DASH_FAB) hop2 = hop1 and and_reach_floating_settings() if not hop2: record("nav_reach_floating_toolbar", False, "setup_failed: never reached Floating Window Settings for the VLM shot", depth=2, jump_kind="reach", expect="on Floating Window Settings") vlm_assert("nav_reach_floating_toolbar", "Is there a left-pointing back arrow rendered at the TOP-LEFT of the " "screen, to the left of a 'Floating Window Settings' title?", RESULTS_DIR, tag="position") @and_test(expects=("nav_backstack_floating_settings_to_monitor",)) def test_backstack_floating_settings_to_monitor(): restart_app() hop1 = and_reach_monitor(source=DASH_FAB) hop2 = hop1 and and_reach_floating_settings() back_ok = False if hop2: before = and_showing() arrow_ok = and_back_via_arrow() after = and_showing() # FLOAT_TITLE collides with the Monitor row, so use the nested-only header. back_ok = arrow_ok and and_reach(before, after, target=MON_TITLE, source=FLOAT_OPACITY) record("nav_backstack_floating_settings_to_monitor", back_ok, "" if back_ok else "behavior_wrong: back arrow did not return to Monitor " "from Floating Window Settings", depth=2, jump_kind="reach", expect="after one BACK: 'Battery Monitor' restored, the 'Opacity: 0.75' " "header gone") @and_test(expects=("nav_reach_about",)) def test_reach_about(): """Settings -> About (scroll then tap). Nested reach.""" restart_app() s = and_reach_settings(source=DASH_FAB) # Dashboard -> Settings (surface 1) ok = s and and_reach_about() # scroll + tap About (surface 2) record("nav_reach_about", ok, "" if ok else "behavior_wrong: could not reach About from Settings " "('Version:' absent or Settings bottom nav still present)", depth=2, jump_kind="reach", expect="'Version:' line appears; the Settings tab's bottom-nav 'Monitor' " "item is gone (nested screen)") @and_test(expects=("nav_reach_about_toolbar_vlm",)) def test_reach_about_toolbar_vlm(): """VLM position check: About's back arrow is at the top-left.""" restart_app() s = and_reach_settings(source=DASH_FAB) ok = s and and_reach_about() if not ok: record("nav_reach_about_toolbar", False, "setup_failed: never reached About for the VLM shot", depth=2, jump_kind="reach", expect="on About") vlm_assert("nav_reach_about_toolbar", "Is there a left-pointing back arrow rendered at the TOP-LEFT of the " "screen, to the left of an 'About' title?", RESULTS_DIR, tag="position") @and_test(expects=("nav_backstack_about_to_settings",)) def test_backstack_about_to_settings(): """About's back arrow returns to its PARENT tab (Settings), not to Dashboard.""" restart_app() s = and_reach_settings(source=DASH_FAB) ok = s and and_reach_about() back_ok = False if ok: before = and_showing() arrow_ok = and_back_via_arrow() # tap About's "Back" arrow after = and_showing() # The Settings tab is restored (its bottom-nav 'Monitor' sibling returns) # and the About 'Version:' line is gone. back_ok = arrow_ok and and_reach(before, after, target=NAV_MONITOR, source=ABOUT_VERSION) record("nav_backstack_about_to_settings", back_ok, "" if back_ok else "behavior_wrong: About back arrow did not return to " "the Settings tab", depth=2, jump_kind="reach", expect="after About BACK: Settings tab restored (bottom-nav 'Monitor' " "returns), 'Version:' gone") @and_test(expects=("nav_backstack_deep_unwind_to_dashboard",)) def test_backstack_deep_unwind_to_dashboard(): """Full unwind: Dashboard -> Monitor -> Entry Settings, then back arrow to Monitor, then hardware BACK from the Monitor TAB lands on Dashboard.""" restart_app() hop1 = and_reach_monitor(source=DASH_FAB) # surface 1 (Monitor) hop2 = hop1 and and_reach_entry_settings() # surface 2 (Entry Settings) at_monitor = False at_dashboard = False if hop2: before = and_showing() arrow_ok = and_back_via_arrow() # pop nested -> Monitor mid = and_showing() # ENTRY_TITLE collides with the Monitor row; use the nested-only text. at_monitor = arrow_ok and and_reach(before, mid, target=MON_TITLE, source=ENTRY_INSTR) if at_monitor: and_back() # hardware BACK from Monitor TAB after = and_showing() at_dashboard = and_reach(mid, after, target=DASH_FAB, source=MON_TITLE) ok = at_monitor and at_dashboard record("nav_backstack_deep_unwind_to_dashboard", ok, "" if ok else "behavior_wrong: two BACKs from Entry Settings did not " "unwind Monitor then land on Dashboard", depth=2, jump_kind="reach", expect="1st BACK: Monitor restored; 2nd BACK: Dashboard 'Open menu' FAB, " "Monitor title gone") @and_test(expects=("nav_backstack_tab_back_to_dashboard",)) def test_backstack_tab_back_to_dashboard(): """The top-level asymmetry: hardware BACK on a NON-start tab (Settings) goes to the START destination (Dashboard), not to the previously visited tab.""" restart_app() s = and_reach_settings(source=DASH_FAB) # surface 1 (Settings tab) at_dash = False if s: before = and_showing() and_back() # hardware BACK from the tab after = and_showing() at_dash = and_reach(before, after, target=DASH_FAB, source=SET_FOLLOW) record("nav_backstack_tab_back_to_dashboard", at_dash, "" if at_dash else "behavior_wrong: hardware BACK on the Settings tab " "did not return to the Dashboard start destination", depth=1, jump_kind="reach", expect="BACK from Settings tab lands on Dashboard ('Open menu' FAB " "appears, 'Follow system theme' gone)") # ══════════════════════════════════════════════════════════════════════════════ # Dialog reach (modal REPLACES the tree; the source element genuinely vanishes) # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("nav_reach_calibrate_dialog",)) def test_reach_calibrate_dialog(): """Dashboard Calibrate opens a modal: title appears, the FAB vanishes. Close dismisses it and the FAB returns.""" restart_app() nodes = ui() trig = find_node(nodes, content_desc="Calibrate") opened = trig is not None and and_reach_surface(trig, CAL_TITLE, DASH_FAB) closed = False if opened: n2 = ui() close = row_trigger(n2, "Close") # app's Close (safe dismiss control) if close is not None: before = and_showing(n2) tap_node(close) _dec_depth() # modal dismissed -> pop counter after = and_showing() closed = and_reach(before, after, target=DASH_FAB, source=CAL_TITLE) ok = opened and closed record("nav_reach_calibrate_dialog", ok, "" if ok else "behavior_wrong: Calibrate dialog did not open onto a " "modal ('Calibrate via Multiplier') or Close did not restore Dashboard", depth=1, jump_kind="reach", expect="open: 'Calibrate via Multiplier' appears, FAB 'Open menu' gone; " "Close: FAB restored, dialog title gone") @and_test(expects=("nav_reach_history_help_dialog",)) def test_reach_history_help_dialog(): """History Help opens a modal that replaces the toolbar; Close restores it.""" restart_app() h = and_reach_history(source=DASH_FAB) opened = False closed = False if h: n1 = ui() trig = find_node(n1, content_desc=HIST_HELP) if trig is not None: before = and_showing(n1) tap_node(trig) and_enter("history_help_dialog") # depth pop-in for the modal after = and_showing() # The dialog adds "Close" and removes the "Export" toolbar icon. opened = and_reach(before, after, target="Close", source=HIST_EXPORT) if opened: n2 = ui() close = row_trigger(n2, "Close") if close is not None: b2 = and_showing(n2) tap_node(close) _dec_depth() # modal dismissed -> pop counter a2 = and_showing() closed = and_reach(b2, a2, target=HIST_EXPORT, source="Close") ok = opened and closed record("nav_reach_history_help_dialog", ok, "" if ok else "behavior_wrong: History Help dialog did not open (Close " "absent / Export toolbar still present) or Close did not restore History", depth=1, jump_kind="reach", expect="open: 'Close' appears, History 'Export' toolbar gone; " "Close: 'Export' toolbar restored, 'Close' gone") @and_test(expects=("nav_reach_history_export_dialog",)) def test_reach_history_export_dialog(): """History Export opens the 'Export History' modal; Cancel dismisses it.""" restart_app() h = and_reach_history(source=DASH_FAB) opened = False closed = False if h: n1 = ui() trig = find_node(n1, content_desc=HIST_EXPORT) if trig is not None: before = and_showing(n1) tap_node(trig) and_enter("history_export_dialog") after = and_showing() # Title 'Export History' appears; the 'Help' toolbar icon vanishes. opened = and_reach(before, after, target=EXPORT_DIALOG, source=HIST_HELP) if opened: n2 = ui() cancel = row_trigger(n2, "Cancel") # app's Cancel (safe dismiss) if cancel is not None: b2 = and_showing(n2) tap_node(cancel) _dec_depth() # modal dismissed -> pop counter a2 = and_showing() closed = and_reach(b2, a2, target=HIST_HELP, source=EXPORT_DIALOG) ok = opened and closed record("nav_reach_history_export_dialog", ok, "" if ok else "behavior_wrong: History Export dialog did not open " "('Export History' absent / Help toolbar still present) or Cancel did " "not restore History", depth=1, jump_kind="reach", expect="open: 'Export History' appears, History 'Help' toolbar gone; " "Cancel: 'Help' toolbar restored, 'Export History' gone") # ══════════════════════════════════════════════════════════════════════════════ # Remaining VLM budget: selected-tab highlight + History toolbar + Back-to-Dashboard # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("nav_history_tab_selected_vlm",)) def test_history_tab_selected_vlm(): """After switching to History, its bottom-nav item reads as selected.""" restart_app() ok = and_reach_history(source=DASH_FAB) if not ok: record("nav_history_tab_selected", False, "setup_failed: never reached History for the VLM shot", depth=1, jump_kind="reach", expect="on History") vlm_assert("nav_history_tab_selected", "In the bottom navigation bar, is the 'History' item visually " "highlighted (its icon sits on a filled rounded pill) while the " "other three items are not?", RESULTS_DIR, tag="color") @and_test(expects=("nav_history_toolbar_actions_vlm",)) def test_history_toolbar_actions_vlm(): """History renders two circular action icons at the TOP-RIGHT of its bar.""" restart_app() ok = and_reach_history(source=DASH_FAB) if not ok: record("nav_history_toolbar_actions", False, "setup_failed: never reached History for the VLM shot", depth=1, jump_kind="reach", expect="on History") vlm_assert("nav_history_toolbar_actions", "Are there exactly two circular icon buttons at the TOP-RIGHT of the " "screen, level with a 'History' title on the left?", RESULTS_DIR, tag="layout") @and_test(expects=("nav_back_to_dashboard_endstate_vlm",)) def test_back_to_dashboard_endstate_vlm(): """After a BACK from the Settings tab, the Dashboard end-state is on screen: the wrench FAB sits at the lower-right.""" restart_app() s = and_reach_settings(source=DASH_FAB) landed = False if s: before = and_showing() and_back() after = and_showing() landed = and_reach(before, after, target=DASH_FAB, source=SET_FOLLOW) if not landed: record("nav_back_to_dashboard_endstate", False, "setup_failed: BACK did not land on Dashboard for the VLM shot", depth=1, jump_kind="reach", expect="on Dashboard after BACK") vlm_assert("nav_back_to_dashboard_endstate", "Is a round floating action button showing a wrench icon rendered " "near the BOTTOM-RIGHT of the screen?", RESULTS_DIR, tag="position") TESTS = [ # top-level tab reachability test_reach_dashboard_to_monitor, test_reach_monitor_to_history, test_reach_history_to_settings, test_reach_settings_to_dashboard, test_reach_dashboard_to_settings, test_roundtrip_dashboard_settings_dashboard, test_roundtrip_history_dashboard_history, # depth-2 nested chains + back unwinding test_reach_monitor_entry_settings, test_reach_entry_settings_toolbar_vlm, test_backstack_entry_settings_to_monitor, test_reach_floating_window_settings, test_reach_floating_toolbar_vlm, test_backstack_floating_settings_to_monitor, test_reach_about, test_reach_about_toolbar_vlm, test_backstack_about_to_settings, test_backstack_deep_unwind_to_dashboard, test_backstack_tab_back_to_dashboard, # dialog reach + dismiss test_reach_calibrate_dialog, test_reach_history_help_dialog, test_reach_history_export_dialog, # remaining VLM budget test_history_tab_selected_vlm, test_history_toolbar_actions_vlm, test_back_to_dashboard_endstate_vlm, ] if __name__ == "__main__": run_suite(TESTS, "navigation")