#!/usr/bin/env python3 """TEXT lane for TimePlanner (package from argv[1]). Owns CONTENT strings that an interaction PRODUCES, and is the sole owner of exact-string equality. Every test is TRIGGER (tap / navigate) -> OBSERVATION (a specific app-authored string that the running ORIGINAL rendered on that surface). Existence-on-a-dead-shell must FAIL: the strong tests assert a string that is ABSENT before the trigger and PRESENT only after it (transition), or that appears only after a real surface jump proven with and_reach (reach). Every expected string below was OBSERVED live on the original via a fresh ui() dump — never read from source, never a version/build constant (those are excluded on purpose: a faithful recreation cannot know them). Run: ADB_PATH=... DEVICE_SERIAL=... python3 test_android_text.py """ import os import sys sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from android_testgen_kit import * # noqa: F403,E402 require_kit(1) # ══════════════════════════════════════════════════════════════════════════════ # Onboarding + LeakCanary recovery (the two documented traps; helpers are the # exact idiom the other five lanes use). # (A) After clear_data() a notification-permission dialog is on screen # ("Allow" / "Don't allow" — curly apostrophe); ui() sees it, so dismiss it. # (B) The .debug build bundles a SECOND launcher activity in the SAME package; # monkey LAUNCHER may open the wrong screen and wait_for_foreground() LIES # (same package). Detect by the ABSENCE of a Home surface; recover with # force_stop + relaunch (NOT HOME). # ══════════════════════════════════════════════════════════════════════════════ def dismiss_onboarding(nodes=None): nodes = nodes if nodes is not None else ui() btn = next((n for n in nodes if (n.get("text") or "") in ("Allow", "Don't allow", "Don’t allow")), None) if btn is None: return False tap_node(btn) return True def _home_ready(nodes): return (find_node_ci(nodes, "Schedule") is not None or find_node_ci(nodes, "Plan now") is not None or find_node_ci(nodes, "Nothing planned yet") is not None) def ensure_home(max_tries=12): for _ in range(max_tries): nodes = ui() if dismiss_onboarding(nodes): settle("tap"); continue if _home_ready(nodes): settle("launch") if _home_ready(ui()): return True continue force_stop(); settle("key") launch_app(); settle("launch") return _home_ready(ui()) def start_home_clean(): clear_data(); launch_app(); return ensure_home() def start_home(): restart_app(); return ensure_home() # ══════════════════════════════════════════════════════════════════════════════ # Compose tap helpers — leaf labels report clickable="false"; tap the clickable # ancestor whose bounds enclose the label's centre (same idiom as the other lanes). # ══════════════════════════════════════════════════════════════════════════════ def _clickable_ancestor(nodes, anchor): 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 _tap_anchor(nodes, anchor): if anchor is None: return False anc = _clickable_ancestor(nodes, anchor) return tap_node(anc) if anc else tap_node(anchor) # ── text-reading helpers ──────────────────────────────────────────────────────── def all_text(nodes): """Every visible text + content-desc, joined — one blob to search.""" parts = [] for n in nodes: t = (n.get("text") or "").strip() cd = (n.get("content-desc") or "").strip() if t: parts.append(t) if cd: parts.append(cd) return " | ".join(parts) def has_ci(nodes, needle): """Case-insensitive substring test over text + content-desc.""" return needle.strip().casefold() in all_text(nodes).casefold() def exact_text(nodes, value): """True iff some node's text is EXACTLY `value` (after strip). This is the exact-string equality this lane owns — no substring slack.""" v = value.strip() return any((n.get("text") or "").strip() == v for n in nodes) # ══════════════════════════════════════════════════════════════════════════════ # NAMED navigation helpers — the and_reach_*/and_enter_* NAME backs every depth>=1 # and jump_kind="reach" claim (the depth audit looks for a call from this family, # directly or in a helper a test calls). Each returns bool and, on success, has # counted the surface it entered. # # The bottom-nav tab label collides with the top-bar title (both key # "TextView|Analytics"), so a tab's own name is useless as a reach target — we # target a screen-BODY element instead: Analytics -> "Category stats", # Settings -> "Appearance". # ══════════════════════════════════════════════════════════════════════════════ def and_reach_analytics(): """Home -> tap the Analytics bottom tab -> Analytics screen. Proves the body element 'Category stats' appeared and Home's 'Schedule' title left. Ensures the Time sub-tab (donut + legend) is shown. Counts one surface.""" nodes = ui() tab = find_node(nodes, content_desc="Analytics") or find_node(nodes, text="Analytics") if tab is None: return False before = and_showing(nodes) if not _tap_anchor(nodes, tab): return False settle("launch") after = and_showing() if not and_reach(before, after, "Category stats", "Schedule"): return False and_enter("analytics") t = find_node(ui(), content_desc="Time") if t is not None: _tap_anchor(ui(), t) settle("tap") return True def and_reach_settings(): """Home -> tap the Settings bottom tab -> Settings screen. Proves the body section 'Appearance' appeared and Home's 'Schedule' title left. Counts one surface.""" nodes = ui() tab = find_node(nodes, content_desc="Settings") or find_node(nodes, text="Settings") if tab is None: return False before = and_showing(nodes) if not _tap_anchor(nodes, tab): return False settle("launch") after = and_showing() if not and_reach(before, after, "Appearance", "Schedule"): return False and_enter("settings") return True def and_reach_editor(): """Home -> (Plan now creates the day) -> tap the free 'Unassigned'/'Add a task' row -> Editor. Proves Editor's 'Statistics' appeared and Home's 'Schedule' left. Counts one surface.""" n = find_node_ci(ui(), "Plan now") if n is not None: tap_node(n) # creates the day's schedule settle("tap") row = find_node_ci(ui(), "Unassigned") or find_node_ci(ui(), "Add a task") if row is None: return False nodes = ui() before = and_showing(nodes) if not _tap_anchor(nodes, row): return False after = and_showing() if not and_reach(before, after, "Statistics", "Schedule"): return False and_enter("editor") return True 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'). Counts one surface.""" nodes = ui() card = _clickable_ancestor(nodes, find_node(nodes, text="Category")) if card is None: return False before = and_showing(nodes) if not tap_node(card): return False after = and_showing() if not and_reach(before, after, "Select", "Save"): return False and_enter("category_sheet") return True def and_reach_drawer(): """Home -> tap the hamburger ('Open menu') -> the navigation drawer. Proves the drawer header 'Time Planner' appeared (Home never renders it). Counts one surface.""" nodes = ui() menu = find_node(nodes, content_desc="Open menu") if menu is None: return False before = and_showing(nodes) if not tap_node(menu): return False after = and_showing() if not and_reach(before, after, "Time Planner"): return False and_enter("drawer") return True def and_reach_templates(): """(drawer already open) tap 'Templates' -> Templates screen. Proves 'List is empty' appeared and the drawer header 'Time Planner' left. Counts one surface.""" item = find_node(ui(), text="Templates") if item is None: return False if not and_reach_surface(item, "List is empty", "Time Planner"): return False return True def and_reach_overview(): """Home -> tap the top-bar grid icon ('Overview') -> Overview screen. Proves the 'Schedules' section appeared and Home's 'Compact view' toggle left. Counts one surface.""" ov = find_node(ui(), content_desc="Overview") if ov is None: return False return and_reach_surface(ov, "Schedules", "Compact view") # ══════════════════════════════════════════════════════════════════════════════ # TESTS # ══════════════════════════════════════════════════════════════════════════════ # 1) Home top-bar title. A depth-0 dump read of the app's own screen title. @and_test(expects=("text_home_title",)) def test_home_title(): ok_home = start_home() nodes = ui() # The bottom-nav "Home" tab also exists; the top-bar TITLE is the exact # "Schedule" TextView, which only the real Home surface renders. ok = ok_home and exact_text(nodes, "Schedule") record("text_home_title", ok, "" if ok else "feature_missing: Home top-bar title 'Schedule' not shown", depth=0, jump_kind="none", expect="top-bar title == 'Schedule'") # 2) Virgin-Home empty state. Only a genuinely empty schedule renders this prompt, # so it must be read on a freshly-cleared database. @and_test(expects=("text_empty_state",)) def test_empty_state(): ok_home = start_home_clean() nodes = ui() ok = ok_home and exact_text(nodes, "Nothing planned yet") \ and exact_text(nodes, "Plan now") record("text_empty_state", ok, "" if ok else "feature_missing: virgin-Home empty state 'Nothing planned yet' / 'Plan now' not shown", depth=0, jump_kind="none", expect="empty-state 'Nothing planned yet' + button 'Plan now'") # 3) Transition PRODUCED by tapping "Plan now": the free-time slot row labelled # "Unassigned" is ABSENT on the virgin day and appears only after the tap. This # is text an interaction produces, and it fails on a shell that renders no rows. @and_test(expects=("text_unassigned_after_plan",)) def test_unassigned_after_plan(): if not start_home_clean(): record("text_unassigned_after_plan", False, "setup_failed: could not reach virgin Home", depth=1, jump_kind="transition", expect="'Unassigned' absent before Plan now, present after") return absent_before = not has_ci(ui(), "Unassigned") plan = find_node_ci(ui(), "Plan now") if plan is None: record("text_unassigned_after_plan", False, "feature_missing: no 'Plan now' control on the empty Home", depth=1, jump_kind="transition", expect="'Unassigned' absent before Plan now, present after") return tap_node(plan) and_enter("day_schedule") # tapping Plan now materialises the day's schedule settle("tap") present_after = exact_text(ui(), "Unassigned") ok = absent_before and present_after record("text_unassigned_after_plan", ok, "" if ok else ("behavior_wrong: free-slot 'Unassigned' row did not appear after Plan now" if absent_before else "behavior_wrong: 'Unassigned' already present before Plan now (bad baseline)"), depth=1, jump_kind="transition", expect="'Unassigned' absent before Plan now, present after") # 4) Analytics screen strings reached from the Analytics tab: the screen title # "Analytics" AND the section header "Category stats" (a body element that only # the reached screen shows). Plus the ONE VLM for this lane. @and_test(expects=("text_analytics_headers", "text_pie_center_total_vlm")) def test_analytics_headers(): ok_home = start_home() reached = ok_home and and_reach_analytics() if not reached: record("text_analytics_headers", False, "feature_missing: Analytics screen not reachable from the Analytics tab", depth=1, jump_kind="reach", expect="'Analytics' title + 'Category stats' / 'Planning stats' headers") vlm_assert("text_pie_center_total", "In the centre of the circular donut/ring chart under the " "'Category stats' section, is a time total drawn as " "'h m' (for example '0h 0m') positioned INSIDE " "the ring's hole (surrounded by the coloured ring), rather than " "off to the side in the legend?", RESULTS_DIR, expect="YES", depth=1, jump_kind="none", tag="position") return nodes = ui() ok = exact_text(nodes, "Analytics") \ and (has_ci(nodes, "Category stats") or has_ci(nodes, "Planning stats")) record("text_analytics_headers", ok, "" if ok else "behavior_wrong: Analytics title / stats section headers not shown after reaching Analytics", depth=1, jump_kind="reach", expect="'Analytics' title + 'Category stats' / 'Planning stats' headers") # THE lane's one VLM: the summed-time total is RENDERED centred inside the # donut ring. Its exact position (inside the ring's hole, not in the flat # legend list) is a rendered layout property the view-tree geometry does not # make trivially checkable — a fine-grained POSITION question. vlm_assert("text_pie_center_total", "In the centre of the circular donut/ring chart under the " "'Category stats' section, is a time total drawn as " "'h m' (for example '0h 0m') positioned INSIDE the " "ring's hole (surrounded by the coloured ring), rather than off to " "the side in the legend?", RESULTS_DIR, expect="YES", depth=1, jump_kind="none", tag="position") # 5) Analytics category-legend names reached via the tab: "Misc" and "Else" are # app-unique legend labels that only the reached Analytics Time tab renders. @and_test(expects=("text_analytics_legend",)) def test_analytics_legend(): ok_home = start_home() reached = ok_home and and_reach_analytics() if not reached: record("text_analytics_legend", False, "setup_failed: could not reach the Analytics Time tab", depth=1, jump_kind="reach", expect="legend category names 'Misc' and 'Else'") return nodes = ui() ok = exact_text(nodes, "Misc") and exact_text(nodes, "Else") record("text_analytics_legend", ok, "" if ok else "behavior_wrong: Analytics category legend ('Misc'/'Else') not shown", depth=1, jump_kind="reach", expect="legend category names 'Misc' and 'Else'") # 6) Settings section headers reached from the Settings tab: "Appearance" (a body # header the reached screen shows and Home never does). @and_test(expects=("text_settings_appearance",)) def test_settings_appearance(): ok_home = start_home() reached = ok_home and and_reach_settings() if not reached: record("text_settings_appearance", False, "feature_missing: Settings screen not reachable from the Settings tab", depth=1, jump_kind="reach", expect="Settings section header 'Appearance'") return nodes = ui() ok = exact_text(nodes, "Appearance") and exact_text(nodes, "Theme") record("text_settings_appearance", ok, "" if ok else "behavior_wrong: Settings 'Appearance' / 'Theme' headers not shown after reaching Settings", depth=1, jump_kind="reach", expect="Settings 'Appearance' section + 'Theme' row") # 7) Settings 'Developer' value — a concrete exact-string content assertion. The # "About the app" rows live below the fold, so scroll them into view. The VALUE # "Stanislav Aleshin" is an app-authored string (NOT a version/build constant). @and_test(expects=("text_settings_developer",)) def test_settings_developer(): ok_home = start_home() reached = ok_home and and_reach_settings() if not reached: record("text_settings_developer", False, "setup_failed: could not reach Settings", depth=1, jump_kind="reach", expect="Developer value 'Stanislav Aleshin'") return row = scroll_into_view("Developer", max_swipes=5) nodes = ui() ok = row is not None and exact_text(nodes, "Developer") \ and exact_text(nodes, "Stanislav Aleshin") record("text_settings_developer", ok, "" if ok else "behavior_wrong: 'Developer' row value 'Stanislav Aleshin' not shown in Settings > About", depth=1, jump_kind="reach", expect="Developer row value == 'Stanislav Aleshin'") # 8) Editor title + a field label PRODUCED by opening the Editor: "Editor" title, # "Statistics" field with its subtitle "Include in analytics". @and_test(expects=("text_editor_statistics",)) def test_editor_statistics(): ok_home = start_home() reached = ok_home and and_reach_editor() if not reached: record("text_editor_statistics", False, "feature_missing: could not open the Editor from Home", depth=1, jump_kind="reach", expect="Editor 'Statistics' + subtitle 'Include in analytics'") return nodes = ui() ok = exact_text(nodes, "Editor") and exact_text(nodes, "Statistics") \ and exact_text(nodes, "Include in analytics") record("text_editor_statistics", ok, "" if ok else "behavior_wrong: Editor 'Statistics' / 'Include in analytics' text not shown", depth=1, jump_kind="reach", expect="Editor title 'Editor' + 'Statistics' / 'Include in analytics'") # 9) A second Editor field label pair: "Notifications" + subtitle "Set a reminder # for the task start" — proves the Editor renders its authored labels, not a # generic form. @and_test(expects=("text_editor_notifications",)) def test_editor_notifications(): ok_home = start_home() reached = ok_home and and_reach_editor() if not reached: record("text_editor_notifications", False, "feature_missing: could not open the Editor from Home", depth=1, jump_kind="reach", expect="Editor 'Notifications' + 'Set a reminder for the task start'") return nodes = ui() ok = exact_text(nodes, "Notifications") \ and exact_text(nodes, "Set a reminder for the task start") record("text_editor_notifications", ok, "" if ok else "behavior_wrong: Editor 'Notifications' / reminder subtitle not shown", depth=1, jump_kind="reach", expect="Editor 'Notifications' + 'Set a reminder for the task start'") # 10) Category bottom-sheet (Editor -> Category card): sheet header "Category", # search placeholder "Select a category", and radio row "Study". Depth 2. @and_test(expects=("text_category_sheet",)) def test_category_sheet(): ok_home = start_home() in_editor = ok_home and and_reach_editor() in_sheet = in_editor and and_reach_category_sheet() if not in_sheet: record("text_category_sheet", False, "feature_missing: Category bottom sheet did not open from the Editor", depth=2, jump_kind="reach", expect="sheet 'Select a category' placeholder + 'Study' row") return nodes = ui() ok = has_ci(nodes, "Select a category") \ and exact_text(nodes, "Study") and exact_text(nodes, "Shopping") record("text_category_sheet", ok, "" if ok else "behavior_wrong: Category sheet placeholder / radio labels ('Study'/'Shopping') not shown", depth=2, jump_kind="reach", expect="'Select a category' + radio rows 'Study' / 'Shopping'") # 11) Drawer header + item PRODUCED by tapping the hamburger: header "Time Planner" # and item "Templates" (both absent on Home, present only in the open drawer). @and_test(expects=("text_drawer_header",)) def test_drawer_header(): ok_home = start_home() if not ok_home: record("text_drawer_header", False, "setup_failed: could not reach Home", depth=1, jump_kind="reach", expect="drawer header 'Time Planner' + item 'Templates'") return before_absent = not has_ci(ui(), "Time Planner") opened = and_reach_drawer() nodes = ui() ok = before_absent and opened and exact_text(nodes, "Time Planner") \ and exact_text(nodes, "Templates") and exact_text(nodes, "Categories") record("text_drawer_header", ok, "" if ok else "feature_missing: drawer header 'Time Planner' + items 'Templates'/'Categories' not shown", depth=1, jump_kind="reach", expect="drawer header 'Time Planner' + items 'Templates' / 'Categories'") # 12) Templates empty-state reached through the drawer (depth 2): the exact # "List is empty" string plus the "Sort" label. Only the reached Templates # screen renders these. @and_test(expects=("text_templates_empty",)) def test_templates_empty(): ok_home = start_home() opened = ok_home and and_reach_drawer() reached = opened and and_reach_templates() if not reached: record("text_templates_empty", False, "feature_missing: Templates screen not reachable from the drawer", depth=2, jump_kind="reach", expect="Templates 'List is empty' + 'Sort'") return nodes = ui() ok = exact_text(nodes, "List is empty") and exact_text(nodes, "Sort") record("text_templates_empty", ok, "" if ok else "behavior_wrong: Templates 'List is empty' / 'Sort' text not shown", depth=2, jump_kind="reach", expect="Templates empty-state 'List is empty' + 'Sort'") # 13) Overview screen reached from the Home top-bar grid icon: section headers # "Schedules" and "Undistributed tasks", and a status chip "Planned". @and_test(expects=("text_overview_headers",)) def test_overview_headers(): ok_home = start_home() reached = ok_home and and_reach_overview() if not reached: record("text_overview_headers", False, "feature_missing: Overview not reachable from the Home top bar", depth=1, jump_kind="reach", expect="Overview 'Schedules' + 'Undistributed tasks' + chip 'Planned'") return nodes = ui() ok = exact_text(nodes, "Schedules") \ and exact_text(nodes, "Undistributed tasks") \ and (exact_text(nodes, "Planned") or exact_text(nodes, "Current")) record("text_overview_headers", ok, "" if ok else "behavior_wrong: Overview headers ('Schedules'/'Undistributed tasks') / status chip not shown", depth=1, jump_kind="reach", expect="Overview 'Schedules' + 'Undistributed tasks' + status chip") TESTS = [ test_home_title, test_empty_state, test_unassigned_after_plan, test_analytics_headers, test_analytics_legend, test_settings_appearance, test_settings_developer, test_editor_statistics, test_editor_notifications, test_category_sheet, test_drawer_header, test_templates_empty, test_overview_headers, ] if __name__ == "__main__": run_suite(TESTS, "text")