RecreationBench / android /v1tzor-timeplanner /tests /test_android_navigation.py
VoyagerXHF's picture
Upload folder using huggingface_hub (part 4)
41dfd8d verified
Raw History Blame Contribute Delete
23.9 kB
#!/usr/bin/env python3
"""NAVIGATION lane for TimePlanner (ru.aleshin.timeplanner.debug).
Owns surface REACHABILITY + back-stack integrity: every jump is proven with
and_reach (the TARGET surface's discriminating element APPEARED and the SOURCE
surface's DISAPPEARED). Sole owner of jump_kind="reach" and of depth>=2 chains.
Run:
ADB_PATH=... DEVICE_SERIAL=... python3 test_android_navigation.py <PACKAGE> <RESULTS_DIR>
"""
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from android_testgen_kit import * # noqa: F403,E402
# ══════════════════════════════════════════════════════════════════════════════
# Onboarding / launcher recovery (the two documented traps).
# (A) .debug bundles LeakCanary -> a second LAUNCHER alias; monkey LAUNCHER may
# open the wrong screen. wait_for_foreground() is True regardless (same pkg).
# (B) After clear_data() a notification-permission dialog is on screen.
# ensure_home() force-stops + relaunches until the Home title "Schedule" is stable.
# Coordinate/component-literal-free -> lint-clean.
# ══════════════════════════════════════════════════════════════════════════════
def dismiss_onboarding():
for _ in range(2):
nodes = ui()
btn = next((n for n in nodes
if (n.get("text") or "") in ("Allow", "Don't allow", "Don’t allow")),
None)
if not btn:
return
tap_node(btn)
def _home_ready(nodes):
return find_node_ci(nodes, "Schedule") is not None # top-bar title on Home
def ensure_home(max_tries=10):
for _ in range(max_tries):
dismiss_onboarding()
if _home_ready(ui()):
for _ in range(3):
settle("launch")
if _home_ready(ui()):
return True
continue
home(); settle("key"); force_stop(); settle("key")
launch_app(); wait_for_foreground()
return _home_ready(ui())
def start_home():
"""Every test's own entry point."""
restart_app()
return ensure_home()
# ── shared trigger helpers ──────────────────────────────────────────────────────
def _nav_tab(nodes, label):
"""Bottom-nav root tab (Home / Analytics / Settings) by its label."""
return find_node(nodes, text=label)
def _smallest_clickable_containing(nodes, anchor):
"""The tightest clickable node whose bounds contain `anchor`'s centre — how a
Compose card that carries only a child label is turned into a tap target."""
if not anchor or "_center" not in anchor:
return None
cx, cy = anchor["_center"]
cands = [n for n in nodes
if n.get("clickable") == "true" and "_bounds" in n
and n["_bounds"][0] <= cx <= n["_bounds"][2]
and n["_bounds"][1] <= cy <= n["_bounds"][3]]
cands.sort(key=lambda n: (n["_bounds"][2] - n["_bounds"][0])
* (n["_bounds"][3] - n["_bounds"][1]))
return cands[0] if cands else None
def _open_drawer():
"""Tap the hamburger (desc 'Open menu'). Returns True if the drawer opened
(header 'Time Planner' visible)."""
m = find_node(ui(), content_desc="Open menu")
if not m or not tap_node(m):
return False
return find_node_ci(ui(), "Time Planner") is not None
# ── depth-family helpers (the and_reach_*/and_enter_* NAME backs the depth audit;
# the implementation is ours). Each returns bool and, on success, has counted a
# surface via and_reach_surface. ─────────────────────────────────────────────
def and_reach_editor():
"""Home -> (Plan now creates the day) -> tap the free 'Unassigned'/'Add a task'
row -> Editor. Proves Editor's 'Category' appeared and Home's 'Schedule' left."""
n = find_node_ci(ui(), "Plan now")
if n:
tap_node(n) # creates the day's schedule
row = find_node_ci(ui(), "Unassigned") or find_node_ci(ui(), "Add a task")
if not row:
return False
return and_reach_surface(row, "Category", "Schedule")
def and_enter_editor():
"""Alias entry that lands on the Editor and counts the surface."""
return and_reach_editor()
def and_reach_category_sheet():
"""Editor -> tap the Category card -> Category bottom sheet. 'Select' is the
sheet's confirm button (the Editor has 'Save', not 'Select')."""
nodes = ui()
card = _smallest_clickable_containing(nodes, find_node(nodes, text="Category"))
if not card:
return False
return and_reach_surface(card, "Select", "Save")
def and_reach_time_picker():
"""Editor -> tap the Start field -> Material time picker ('Enter time'). The
Editor's 'Priority' field is fully covered by the modal."""
nodes = ui()
card = _smallest_clickable_containing(nodes, find_node(nodes, content_desc="Start"))
if not card:
return False
return and_reach_surface(card, "Enter time", "Priority")
def and_reach_templates_via_drawer():
"""(drawer already open) drawer 'Templates' -> Templates screen."""
dn = ui()
item = find_node(dn, text="Templates")
return item is not None and and_reach_surface(item, "List is empty", "Time Planner")
def and_reach_categories_via_drawer():
"""(drawer already open) drawer 'Categories' -> Categories screen."""
dn = ui()
item = find_node(dn, text="Categories")
return item is not None and and_reach_surface(item, "Subcategories", "Time Planner")
# ══════════════════════════════════════════════════════════════════════════════
# BOTTOM-NAV ROOT SWITCHES (depth 1, reach)
# The top-bar title and the bottom-nav label share the key "TextView|Analytics"
# etc., so a tab's own name is a USELESS target (already in `before`). We target a
# screen-body element instead: Analytics -> "Planning stats", Settings ->
# "Appearance", Home -> "Schedule".
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("nav_reach_analytics", "nav_reach_analytics_vlm",
"nav_reach_analytics_tabs_vlm"))
def test_reach_analytics():
ok = start_home()
nodes = ui()
tab = _nav_tab(nodes, "Analytics")
reached = ok and tab is not None and and_reach_surface(tab, "Planning stats", "Schedule")
record("nav_reach_analytics", reached,
"" if reached else "feature_missing: Analytics root not reachable from Home",
depth=1, jump_kind="reach",
expect="Analytics 'Planning stats' visible; Home 'Schedule' title gone")
vlm_assert("nav_reach_analytics",
"Is a donut or pie chart (a ring/circle segmented into colored "
"slices) shown on this analytics screen?",
RESULTS_DIR, depth=1, jump_kind="reach", tag="shape")
vlm_assert("nav_reach_analytics_tabs",
"Near the top are there two side-by-side tabs, one bearing a "
"round pie-chart icon and the other a bar-chart icon (vertical bars)?",
RESULTS_DIR, depth=1, jump_kind="none", tag="shape")
@and_test(expects=("nav_reach_settings", "nav_reach_settings_vlm"))
def test_reach_settings():
ok = start_home()
# Home -> Analytics -> Settings (tab switching between roots).
a = _nav_tab(ui(), "Analytics")
on_analytics = ok and a is not None and and_reach_surface(a, "Planning stats", "Schedule")
nodes = ui()
s = _nav_tab(nodes, "Settings")
reached = on_analytics and s is not None and and_reach_surface(s, "Appearance", "Planning stats")
record("nav_reach_settings", reached,
"" if reached else "feature_missing: Settings root not reachable via tabs",
depth=1, jump_kind="reach",
expect="Settings 'Appearance' section visible; Analytics 'Planning stats' gone")
vlm_assert("nav_reach_settings",
"Under a 'Color' label, are there four filled color swatches whose "
"shape is a rounded square (not a circle)?",
RESULTS_DIR, depth=1, jump_kind="reach", tag="shape")
@and_test(expects=("nav_reach_home_tab",))
def test_reach_home_from_settings():
ok = start_home()
s = _nav_tab(ui(), "Settings")
on_settings = ok and s is not None and and_reach_surface(s, "Appearance", "Schedule")
h = _nav_tab(ui(), "Home")
reached = on_settings and h is not None and and_reach_surface(h, "Schedule", "Appearance")
record("nav_reach_home_tab", reached,
"" if reached else "behavior_wrong: Home tab did not restore the Schedule root",
depth=1, jump_kind="reach",
expect="Home 'Schedule' title restored; Settings 'Appearance' gone")
# ══════════════════════════════════════════════════════════════════════════════
# HOME -> EDITOR (push) and BACK unwind (depth 1/2, reach)
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("nav_reach_editor", "nav_reach_editor_vlm"))
def test_reach_editor():
ok = start_home()
reached = ok and and_reach_editor()
record("nav_reach_editor", reached,
"" if reached else "feature_missing: could not open the Editor from Home",
depth=1, jump_kind="reach",
expect="Editor 'Category'/'Save' visible; Home 'Schedule' gone")
vlm_assert("nav_reach_editor",
"In the top app-bar, is a left-pointing back arrow positioned at the "
"very top-left corner, with action icons over on the right side?",
RESULTS_DIR, depth=1, jump_kind="reach", tag="position")
@and_test(expects=("nav_backstack_editor_home",))
def test_editor_back_to_home():
ok = start_home()
deep = ok and and_reach_editor()
# BACK from the Editor pops back to Home.
before = and_showing()
and_back()
after = and_showing()
back_ok = deep and and_reach(before, after, "Schedule", "Editor")
record("nav_backstack_editor_home", back_ok,
"" if back_ok else "behavior_wrong: BACK from Editor did not return to Home",
depth=1, jump_kind="reach",
expect="Home 'Schedule' restored after one BACK; Editor title gone")
# ══════════════════════════════════════════════════════════════════════════════
# HOME -> OVERVIEW via the top-bar grid icon (depth 1, reach)
# ══════════════════════════════════════════════════════════════════════════════
def and_reach_overview():
ov = find_node(ui(), content_desc="Overview")
return ov is not None and and_reach_surface(ov, "Schedules", "Compact view")
@and_test(expects=("nav_reach_overview", "nav_reach_overview_vlm"))
def test_reach_overview():
ok = start_home()
reached = ok and and_reach_overview()
record("nav_reach_overview", reached,
"" if reached else "feature_missing: Overview not reachable from the Home top bar",
depth=1, jump_kind="reach",
expect="Overview 'Schedules' section visible; Home 'Compact view' gone")
vlm_assert("nav_reach_overview",
"Does this screen show a horizontal row of date cards, each with a "
"circular progress ring and a status word like Completed/Current/Planned?",
RESULTS_DIR, depth=1, jump_kind="reach", tag="layout")
# ══════════════════════════════════════════════════════════════════════════════
# DRAWER host (open + each item) (depth 1, reach)
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("nav_open_drawer", "nav_open_drawer_vlm"))
def test_open_drawer():
ok = start_home()
nodes = ui()
menu = find_node(nodes, content_desc="Open menu")
before = and_showing(nodes)
tapped = ok and menu is not None and tap_node(menu)
after = and_showing()
# The drawer host reveals its header + item labels that Home never shows.
opened = tapped and and_reach(before, after, "Time Planner") \
and and_reach(before, after, "Templates") \
and and_reach(before, after, "Categories")
record("nav_open_drawer", opened,
"" if opened else "feature_missing: navigation drawer did not open",
depth=1, jump_kind="reach",
expect="Drawer header 'Time Planner' + items Templates/Categories appeared")
vlm_assert("nav_open_drawer",
"Has a navigation drawer panel slid in from the left, covering the "
"left portion of the screen, with a logo/title header at the top and "
"a vertical list of menu items below it?",
RESULTS_DIR, depth=1, jump_kind="reach", tag="position")
@and_test(expects=("nav_reach_templates",))
def test_reach_templates_via_drawer():
ok = start_home()
opened = ok and _open_drawer()
reached = opened and and_reach_templates_via_drawer()
record("nav_reach_templates", reached,
"" if reached else "feature_missing: Templates not reachable from the drawer",
depth=1, jump_kind="reach",
expect="Templates 'List is empty' visible; drawer 'Time Planner' gone")
@and_test(expects=("nav_reach_categories",))
def test_reach_categories_via_drawer():
ok = start_home()
opened = ok and _open_drawer()
reached = opened and and_reach_categories_via_drawer()
record("nav_reach_categories", reached,
"" if reached else "feature_missing: Categories not reachable from the drawer",
depth=1, jump_kind="reach",
expect="Categories 'Subcategories' visible; drawer 'Time Planner' gone")
@and_test(expects=("nav_reach_overview_drawer",))
def test_reach_overview_via_drawer():
ok = start_home()
opened = ok and _open_drawer()
dn = ui()
item = find_node(dn, text="Overview")
reached = opened and item is not None and and_reach_surface(item, "Schedules", "Time Planner")
record("nav_reach_overview_drawer", reached,
"" if reached else "feature_missing: Overview not reachable from the drawer",
depth=1, jump_kind="reach",
expect="Overview 'Schedules' visible; drawer 'Time Planner' gone")
# ══════════════════════════════════════════════════════════════════════════════
# DEEP CHAIN — the back-stack integrity test this lane owns (depth 2, reach)
# Home -> (drawer) Templates -> (drawer) Categories, then BACK pops Categories ->
# Templates, and BACK again pops Templates -> Home. Each hop AND each pop is a real
# and_reach. A recreation that resets to Home on BACK, or cannot stack two drawer
# screens, FAILS here.
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("nav_deepchain_backstack",))
def test_deepchain_backstack():
ok = start_home()
# hop 1: Home -> Templates
hop1 = ok and _open_drawer() and and_reach_templates_via_drawer()
# hop 2: Templates -> Categories (reopen the drawer over Templates)
hop2 = hop1 and _open_drawer() and and_reach_categories_via_drawer()
# pop 1: BACK -> Templates restored, Categories gone
before = and_showing()
and_back()
after = and_showing()
pop1 = hop2 and and_reach(before, after, "List is empty", "Subcategories")
# pop 2: BACK -> Home restored, Templates gone
before = and_showing()
and_back()
after = and_showing()
pop2 = pop1 and and_reach(before, after, "Schedule", "List is empty")
passed = bool(hop1 and hop2 and pop1 and pop2)
if passed:
msg = ""
elif not hop1:
msg = "feature_missing: could not push Templates from the drawer"
elif not hop2:
msg = "feature_missing: could not stack Categories on top of Templates"
elif not pop1:
msg = "behavior_wrong: BACK from Categories did not restore Templates"
else:
msg = "behavior_wrong: BACK from Templates did not restore Home"
record("nav_deepchain_backstack", passed, msg,
depth=2, jump_kind="reach",
expect="Templates then Categories stacked; two BACKs unwind "
"Categories->Templates->Home hop by hop")
# ══════════════════════════════════════════════════════════════════════════════
# EDITOR sub-surfaces (depth 2, reach)
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("nav_reach_category_sheet", "nav_reach_category_sheet_vlm"))
def test_reach_category_sheet():
ok = start_home()
in_editor = ok and and_reach_editor()
reached = in_editor and and_reach_category_sheet()
record("nav_reach_category_sheet", reached,
"" if reached else "feature_missing: Category bottom sheet did not open from the Editor",
depth=2, jump_kind="reach",
expect="Category sheet 'Select' button visible; Editor 'Save' gone")
vlm_assert("nav_reach_category_sheet",
"Is a panel/sheet overlaid on the lower part of the screen on top of "
"a dimmed (darkened) background behind it?",
RESULTS_DIR, depth=2, jump_kind="reach", tag="position")
@and_test(expects=("nav_backstack_sheet_editor",))
def test_category_sheet_back_to_editor():
ok = start_home()
in_editor = ok and and_reach_editor()
in_sheet = in_editor and and_reach_category_sheet()
# Cancel closes the sheet and returns to the Editor. Use the sheet-unique
# "Close sheet" desc as the source (the editor's "Select a category"/"Select a
# date" descs would substring-collide with a plain "Select" source).
nodes = ui()
cancel = find_node(nodes, text="Cancel")
before = and_showing(nodes)
closed = in_sheet and cancel is not None and tap_node(cancel)
after = and_showing()
back_ok = closed and and_reach(before, after, "Priority", "Close sheet")
record("nav_backstack_sheet_editor", back_ok,
"" if back_ok else "behavior_wrong: closing the Category sheet did not return to the Editor",
depth=2, jump_kind="reach",
expect="Editor 'Priority' field restored after Cancel; sheet 'Close sheet' gone")
@and_test(expects=("nav_reach_time_picker", "nav_reach_time_picker_vlm"))
def test_reach_time_picker():
ok = start_home()
in_editor = ok and and_reach_editor()
reached = in_editor and and_reach_time_picker()
record("nav_reach_time_picker", reached,
"" if reached else "feature_missing: time picker did not open from the Editor Start field",
depth=2, jump_kind="reach",
expect="Time picker 'Enter time' visible; Editor 'Priority' field gone")
vlm_assert("nav_reach_time_picker",
"Is a time-entry dialog shown roughly centered on the screen, with "
"large hour and minute number fields and AM / PM buttons?",
RESULTS_DIR, depth=2, jump_kind="reach", tag="position")
@and_test(expects=("nav_backstack_picker_editor",))
def test_time_picker_back_to_editor():
ok = start_home()
in_editor = ok and and_reach_editor()
in_picker = in_editor and and_reach_time_picker()
nodes = ui()
cancel = find_node(nodes, text="Cancel")
before = and_showing(nodes)
closed = in_picker and cancel is not None and tap_node(cancel)
after = and_showing()
back_ok = closed and and_reach(before, after, "Priority", "Enter time")
record("nav_backstack_picker_editor", back_ok,
"" if back_ok else "behavior_wrong: cancelling the time picker did not return to the Editor",
depth=2, jump_kind="reach",
expect="Editor 'Priority' field restored after Cancel; picker 'Enter time' gone")
# ══════════════════════════════════════════════════════════════════════════════
# HOME date chip -> date picker (depth 1, reach)
# The picker adds a day grid whose "Change to next month" affordance is
# picker-unique (Home never renders that content-desc).
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("nav_reach_date_picker",))
def test_reach_date_picker():
ok = start_home()
nodes = ui()
chip = None
for n in nodes:
if (n.get("text") or "").startswith(("Thu", "Mon", "Tue", "Wed", "Fri", "Sat", "Sun")):
chip = _smallest_clickable_containing(nodes, n)
if chip:
break
before = and_showing(nodes)
tapped = ok and chip is not None and tap_node(chip)
after = and_showing()
reached = tapped and and_reach(before, after, "Change to next month", "Compact view")
record("nav_reach_date_picker", reached,
"" if reached else "feature_missing: date picker did not open from the Home date chip",
depth=1, jump_kind="reach",
expect="Date picker (day grid, 'Change to next month') visible; Home 'Compact view' gone")
TESTS = [
test_reach_analytics,
test_reach_settings,
test_reach_home_from_settings,
test_reach_editor,
test_editor_back_to_home,
test_reach_overview,
test_open_drawer,
test_reach_templates_via_drawer,
test_reach_categories_via_drawer,
test_reach_overview_via_drawer,
test_deepchain_backstack,
test_reach_category_sheet,
test_category_sheet_back_to_editor,
test_reach_time_picker,
test_time_picker_back_to_editor,
test_reach_date_picker,
]
if __name__ == "__main__":
run_suite(TESTS, "navigation")