#!/usr/bin/env python3 """INTERACTION lane for DetoxDroid (com.flx_apps.digitaldetox). Owns EFFECT-BY-CONSEQUENCE on user DATA: schedule-rule CRUD (create / read-back / edit / delete), multi-step sequences, multi-record integrity across records and features, DATA persistence across PROCESS DEATH, the app-exception selection counter, and (sole owner) long-press gestures. Every test is TRIGGER SEQUENCE -> DATA consequence read back out of a fresh ui(); a dead shell that only echoes the last input, or an in-memory-only store, FAILS. Ground-truth anchors (verified live on the running original): Feature detail (Grayscale): InfoCard 'Removes color from distracting apps...', 'Feature Schedule' tile (content-desc 'Manage Schedule') whose subtitle is "The feature is active all the time." with NO rule and "1 rules are set." / "2 rules are set." with rules; 'App Exceptions' tile (content-desc 'Manage App Scope') whose subtitle is "Colors are allowed in N apps.". Feature Schedule screen: title 'Feature Schedule', Add FAB (content-desc 'Add'), empty-state text 'No rules yet.This feature is active all the time.' (the raw attribute contains the entity ' ', so it is matched by the substring 'No rules yet', never by an exact string). Add rule sheet: content-desc 'Close sheet', 'Weekdays'/'Every day', 'From'/'To', 'Save'. Save -> a rule row 'Every day' + 'all day' appears. Weekdays sub-dialog (tap 'Weekdays' in the sheet): Monday..Sunday CheckedTextView rows + CANCEL/SAVE Buttons; picking only Sat+Sun -> a rule row 'Sat, Sun'. Edit sheet (tap an existing rule row): same fields PLUS a 'Delete' action (bottom-left) and a 'Save' action (bottom-right). App Exceptions (Grayscale): counter 'Active in all apps except N selected.'; the app-row CheckBox is the rightmost CheckBox with y>700 (the two checkables at y~487 are the scope segments). Break's App Exceptions defaults to the other scope: 'Active only in N selected apps.'. Long-press finding: on this build a long-press on the Extra Dim row (the one the subtitle advertises as "Long-press to adjust intensity."), on the 'Allowed Daily Color Screen Time' tile, and on a schedule rule row produces NO dialog/slider and NO surface change. The rule-row long-press is therefore exercised as a DATA- INTEGRITY probe: the gesture must leave the created record intact (still exactly one 'Every day' row), which a shell that deletes/recreates on any touch fails. """ import os import sys sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from android_testgen_kit import * # noqa: F403,E402 # Home discriminator: unique to home, disappears on every child surface. HOME_FAB = "Run/Stop DetoxDroid" # Empty-state substring — robust to the ' ' entity in the raw attribute and to # a recreation that decodes it. EMPTY_MARK = "No rules yet" # ── generic predicates read back out of a FRESH ui() ───────────────────────── def _texts(ns): return [n.get("text", "") for n in ns] def schedule_is_empty(ns): """True iff the schedule shows its empty-state ('No rules yet...').""" return any(EMPTY_MARK in t for t in _texts(ns)) def rule_rows(ns): """The 'Every day' rule-row labels currently on the schedule list.""" return [n for n in ns if n.get("text", "").strip() == "Every day"] def has_rule_row(ns): return len(rule_rows(ns)) >= 1 def has_row(ns, label): return any(n.get("text", "").strip() == label for n in ns) def exceptions_counter(ns): """The Grayscale-style 'Active in all apps except N selected.' line, or None.""" for n in ns: if n.get("text", "").startswith("Active in all apps except"): return n.get("text", "") return None def exceptions_counter_only(ns): """Break-style 'Active only in N selected apps.' line, or None.""" for n in ns: if n.get("text", "").startswith("Active only in"): return n.get("text", "") return None def app_row_checkbox(ns): """The app-row CheckBox: the rightmost CheckBox with y>700 (the scope segments sit at y~487, so y>700 excludes them).""" cbs = [n for n in ns if "CheckBox" in n.get("class", "") and n.get("_bounds") and n["_bounds"][1] > 700] cbs.sort(key=lambda n: n["_bounds"][0]) return cbs[-1] if cbs else None def detail_hint(ns): """The Feature Schedule tile subtitle on a feature detail, or None.""" for n in ns: if "rules are set" in n.get("text", ""): return n.get("text", "") return None # ── NAMED navigation helpers — each taps a real trigger and backs a depth. ──── def _home(): restart_app() return wait_for_foreground() def and_enter_feature(feature_tile_text): """HOME -> a feature detail, located by its home tile text. Counts 1 surface.""" if not _home(): return False node = scroll_into_view(feature_tile_text) if node is None or not tap_node(node): return False and_enter(feature_tile_text) return True def and_reach_schedule(feature_tile_text, source_infocard): """HOME -> feature -> Feature Schedule (depth 2). Proves the jump: the Add FAB appeared and the feature's unique InfoCard left.""" if not and_enter_feature(feature_tile_text): return False tile = find_node(ui(), content_desc="Manage Schedule") return tile is not None and and_reach_surface(tile, "Add", source_infocard) def and_reach_schedule_no_source(feature_tile_text): """HOME -> feature -> Feature Schedule (depth 2), proving only that the Add FAB appeared (used after a relaunch / when the source InfoCard is not needed).""" if not and_enter_feature(feature_tile_text): return False tile = find_node(ui(), content_desc="Manage Schedule") if tile is None: return False before = and_showing() if not tap_node(tile): return False after = and_showing() if not and_reach(before, after, "Add"): return False and_enter("schedule") return True def and_enter_add_sheet(): """Feature Schedule -> Add rule sheet (one more surface). Assumes the schedule is the current surface.""" add = find_node(ui(), content_desc="Add") if add is None or not tap_node(add): return False and_enter("add_sheet") return True def and_reach_app_exceptions(feature_tile_text, source_infocard): """HOME -> feature -> App Exceptions (depth 2). The Search icon appears and the feature's InfoCard leaves.""" if not and_enter_feature(feature_tile_text): return False tile = find_node(ui(), content_desc="Manage App Scope") return tile is not None and and_reach_surface(tile, "Search", source_infocard) # ── CRUD building blocks (return True on the observed success path) ─────────── def create_default_rule(): """From the Feature Schedule surface: Add -> Save -> a rule row appears. Returns True iff a rule row is present afterward.""" if not and_enter_add_sheet(): return False save = find_node_ci(ui(), "Save") if save is None or not tap_node(save): return False return has_rule_row(ui()) def create_satsun_rule(): """From the Feature Schedule surface: Add -> Weekdays -> pick only Sat+Sun -> dialog SAVE -> sheet Save -> a 'Sat, Sun' rule row appears.""" if not and_enter_add_sheet(): return False wk = find_node(ui(), text="Weekdays") if wk is None or not tap_node(wk): return False # In the day dialog every day starts checked; unchecking Sun+Sat yields a rule # labelled 'Sat, Sun' (verified live on the original). for day in ("Sunday", "Saturday"): d = find_node(ui(), text=day) if d: tap_node(d) dlg_save = find_node(ui(), text="SAVE") or find_node_ci(ui(), "SAVE") if dlg_save is None or not tap_node(dlg_save): return False sheet_save = find_node(ui(), text="Save") if sheet_save is None or not tap_node(sheet_save): return False return has_row(ui(), "Sat, Sun") def open_edit_sheet(row_label): """Tap an existing rule row to open its edit sheet. Returns True iff the sheet (Delete + Save) is showing.""" row = find_node(ui(), text=row_label) if row is None or not tap_node(row): return False ns = ui() return find_node_ci(ns, "Delete") is not None and find_node_ci(ns, "Save") is not None # ══════════════════════════════════════════════════════════════════════════════ # 1. CREATE a rule -> rule row appears (absent -> present) # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_create_rule", "interaction_create_rule_vlm")) def test_create_rule(): clear_data() if not and_reach_schedule("Automatic Grayscale", "Removes color"): record("interaction_create_rule", False, "setup_failed: could not reach Grayscale Feature Schedule", depth=2, jump_kind="value", expect="rule row 'Every day'/'all day'") return absent_before = schedule_is_empty(ui()) and not has_rule_row(ui()) ok_create = create_default_rule() # opens Add sheet -> depth 3 ns = ui() present_after = has_rule_row(ns) and has_row(ns, "all day") ok = absent_before and ok_create and present_after record("interaction_create_rule", ok, "" if ok else "behavior_wrong: creating a rule did not add an " "'Every day'/'all day' row (absent_before=%s present_after=%s)" % (absent_before, present_after), depth=3, jump_kind="value", expect="schedule row 'Every day' + 'all day' present (was 'No rules yet')") vlm_assert("interaction_create_rule", "Is there a rule row aligned to the LEFT edge in the UPPER part of " "this list (just below the top information banner), where a centered " "empty-state 'no rules' message previously sat?", RESULTS_DIR, depth=3, jump_kind="value", tag="position") # ══════════════════════════════════════════════════════════════════════════════ # 2. CREATE a rule -> feature-detail hint consequence ("1 rules are set.") # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_rule_updates_detail_hint",)) def test_rule_updates_detail_hint(): clear_data() if not and_enter_feature("Automatic Grayscale"): record("interaction_rule_updates_detail_hint", False, "setup_failed: could not open Grayscale detail", depth=1, jump_kind="value", expect="hint '1 rules are set.'") return hint_before = find_node(ui(), text="The feature is active all the time.") is not None tile = find_node(ui(), content_desc="Manage Schedule") reached = tile is not None and and_reach_surface(tile, "Add", "Removes color") made = reached and create_default_rule() # Add sheet auto-closes on Save and_back() # schedule -> Grayscale detail hint_after = detail_hint(ui()) if made else None ok = hint_before and made and hint_after == "1 rules are set." record("interaction_rule_updates_detail_hint", ok, "" if ok else "behavior_wrong: Feature Schedule subtitle did not become " "'1 rules are set.' after creating one rule (before_all_time=%s after=%r)" % (hint_before, hint_after), depth=2, jump_kind="value", expect="Grayscale 'Feature Schedule' subtitle == '1 rules are set.' " "(was 'The feature is active all the time.')") # ══════════════════════════════════════════════════════════════════════════════ # 3. TWO distinct rules -> both rows present + "2 rules are set." (multi-record) # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_two_rules", "interaction_two_rules_vlm")) def test_two_rules_multi_record(): clear_data() if not and_reach_schedule("Automatic Grayscale", "Removes color"): record("interaction_two_rules", False, "setup_failed: could not reach Grayscale Feature Schedule", depth=2, jump_kind="value", expect="two rule rows + '2 rules are set.'") return ok1 = create_default_rule() # row 'Every day' ok2 = create_satsun_rule() # row 'Sat, Sun' ns = ui() row_every = has_row(ns, "Every day") row_satsun = has_row(ns, "Sat, Sun") both_rows = ok1 and ok2 and row_every and row_satsun # VLM must see the SCHEDULE list (two rows) — capture BEFORE popping to detail. vlm_assert("interaction_two_rules", "Are there exactly two rule rows stacked vertically in the list here, " "the second positioned directly BELOW the first, each left-aligned " "with its own day and time text?", RESULTS_DIR, depth=2, jump_kind="value", tag="position") and_back() # schedule -> detail (cross-check hint) hint = detail_hint(ui()) ok = both_rows and hint == "2 rules are set." record("interaction_two_rules", ok, "" if ok else "behavior_wrong: two distinct rules did not both persist " "(every=%s satsun=%s hint=%r) — a recreation that keeps only one row " "fails here" % (row_every, row_satsun, hint), depth=3, jump_kind="value", expect="rows 'Every day' AND 'Sat, Sun' both present; detail hint " "'2 rules are set.'") # ══════════════════════════════════════════════════════════════════════════════ # 4. MULTI-RECORD INTEGRITY: two distinct records, delete ONE, the other survives # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_delete_one_keeps_other",)) def test_delete_one_keeps_other(): clear_data() if not and_reach_schedule("Automatic Grayscale", "Removes color"): record("interaction_delete_one_keeps_other", False, "setup_failed: could not reach Grayscale Feature Schedule", depth=2, jump_kind="value", expect="after deleting one record, the other remains") return # Two DISTINCT records (two identical defaults would merge): r1='Every day', # r2='Sat, Sun'. Delete r2; r1 must survive intact. ok1 = create_default_rule() ok2 = create_satsun_rule() have_two = ok1 and ok2 and has_row(ui(), "Every day") and has_row(ui(), "Sat, Sun") deleted_ok = survivor_ok = False if have_two and open_edit_sheet("Sat, Sun"): dele = find_node_ci(ui(), "Delete") if dele is not None and tap_node(dele): after = ui() deleted_ok = not has_row(after, "Sat, Sun") survivor_ok = has_row(after, "Every day") ok = have_two and deleted_ok and survivor_ok record("interaction_delete_one_keeps_other", ok, "" if ok else "behavior_wrong: deleting one of two records did not leave " "the other intact (have_two=%s deleted=%s survivor=%s) — a recreation " "that rebuilds the whole list from one row fails here" % (have_two, deleted_ok, survivor_ok), depth=3, jump_kind="value", expect="after deleting 'Sat, Sun': 'Sat, Sun' gone AND 'Every day' " "still present") # ══════════════════════════════════════════════════════════════════════════════ # 5. DELETE the only rule -> list returns to the empty-state (present -> absent) # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_delete_rule_empties", "interaction_delete_rule_empties_vlm")) def test_delete_rule_empties(): clear_data() if not and_reach_schedule("Automatic Grayscale", "Removes color"): record("interaction_delete_rule_empties", False, "setup_failed: could not reach Grayscale Feature Schedule", depth=2, jump_kind="transition", expect="rule present -> after Delete, empty-state restored") return made = create_default_rule() present = made and has_rule_row(ui()) emptied = False if present and open_edit_sheet("Every day"): dele = find_node_ci(ui(), "Delete") if dele is not None and tap_node(dele): after = ui() emptied = schedule_is_empty(after) and not has_rule_row(after) ok = present and emptied record("interaction_delete_rule_empties", ok, "" if ok else "behavior_wrong: deleting the only rule did not restore the " "'No rules yet' empty-state (present=%s emptied=%s)" % (present, emptied), depth=3, jump_kind="transition", expect="rule row present -> after Delete, 'No rules yet' empty-state and " "no rule rows") vlm_assert("interaction_delete_rule_empties", "Does this schedule screen now show a centered empty-state message " "(text explaining there are no rules yet), with NO rule rows/cards " "listed above it?", RESULTS_DIR, depth=2, jump_kind="transition", tag="content") # ══════════════════════════════════════════════════════════════════════════════ # 6. EDIT a rule via the edit sheet -> the row text reflects the change # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_edit_rule",)) def test_edit_rule(): clear_data() if not and_reach_schedule("Automatic Grayscale", "Removes color"): record("interaction_edit_rule", False, "setup_failed: could not reach Grayscale Feature Schedule", depth=2, jump_kind="value", expect="row 'Every day' edited to 'Sat, Sun'") return made = create_default_rule() was_every = made and has_row(ui(), "Every day") changed = False if was_every and open_edit_sheet("Every day"): wk = find_node(ui(), text="Weekdays") if wk is not None and tap_node(wk): # day sub-dialog for day in ("Sunday", "Saturday"): d = find_node(ui(), text=day) if d: tap_node(d) dlg_save = find_node(ui(), text="SAVE") or find_node_ci(ui(), "SAVE") if dlg_save is not None and tap_node(dlg_save): sheet_save = find_node(ui(), text="Save") if sheet_save is not None and tap_node(sheet_save): after = ui() # the SAME single record now reads 'Sat, Sun', not 'Every day' changed = (has_row(after, "Sat, Sun") and not has_row(after, "Every day")) ok = was_every and changed record("interaction_edit_rule", ok, "" if ok else "behavior_wrong: editing the rule's days did not change the " "row from 'Every day' to 'Sat, Sun' (was_every=%s changed=%s)" % (was_every, changed), depth=3, jump_kind="value", expect="the single rule row changes from 'Every day' to 'Sat, Sun' after " "editing its days") # ══════════════════════════════════════════════════════════════════════════════ # 7. DATA PERSISTENCE across PROCESS DEATH (the marquee test) # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_rule_persists_process_death",)) def test_rule_persists_process_death(): clear_data() if not and_reach_schedule("Automatic Grayscale", "Removes color"): record("interaction_rule_persists_process_death", False, "setup_failed: could not reach Grayscale Feature Schedule", depth=2, jump_kind="value", expect="rule row still present after force-stop + relaunch") return made = create_default_rule() present_before = made and has_rule_row(ui()) force_stop_and_relaunch() wait_for_foreground() renav = and_reach_schedule_no_source("Automatic Grayscale") # depth 2 again present_after = renav and has_rule_row(ui()) ok = present_before and present_after record("interaction_rule_persists_process_death", ok, "" if ok else "behavior_wrong: the created rule did NOT survive process " "death (before=%s after=%s) — an in-memory-only store fails here" % (present_before, present_after), depth=2, jump_kind="value", expect="'Every day' rule row present again after force_stop_and_relaunch " "+ re-navigating Home->Grayscale->Feature Schedule") # ══════════════════════════════════════════════════════════════════════════════ # 8. PER-FEATURE ISOLATION: a rule on Grayscale does NOT leak into Break # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_rule_per_feature_isolation",)) def test_rule_per_feature_isolation(): clear_data() if not and_reach_schedule("Automatic Grayscale", "Removes color"): record("interaction_rule_per_feature_isolation", False, "setup_failed: could not reach Grayscale Feature Schedule", depth=2, jump_kind="value", expect="Break schedule empty while Grayscale has a rule") return made = create_default_rule() gray_has = made and has_rule_row(ui()) break_empty = break_no_rows = False if gray_has and and_reach_schedule_no_source("Break Infinite Scrolling"): ns = ui() break_empty = schedule_is_empty(ns) break_no_rows = not has_rule_row(ns) ok = gray_has and break_empty and break_no_rows record("interaction_rule_per_feature_isolation", ok, "" if ok else "behavior_wrong: a rule created under Grayscale leaked into " "Break Infinite Scrolling's schedule (gray_has=%s break_empty=%s " "break_no_rows=%s)" % (gray_has, break_empty, break_no_rows), depth=2, jump_kind="value", expect="Break Infinite Scrolling schedule shows 'No rules yet' (empty) " "even though Grayscale has one rule — rules are per-feature") # ══════════════════════════════════════════════════════════════════════════════ # 9. Rule created on Disable Apps -> its OWN detail hint (create on 2nd feature) # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_create_rule_disable_apps",)) def test_create_rule_disable_apps(): clear_data() if not and_reach_schedule("Disable Apps", "Blocks or deactivates"): record("interaction_create_rule_disable_apps", False, "setup_failed: could not reach Disable Apps Feature Schedule", depth=2, jump_kind="value", expect="Disable Apps hint '1 rules are set.'") return absent_before = schedule_is_empty(ui()) made = create_default_rule() present = made and has_rule_row(ui()) and_back() # schedule -> Disable Apps detail hint = detail_hint(ui()) if present else None ok = absent_before and present and hint == "1 rules are set." record("interaction_create_rule_disable_apps", ok, "" if ok else "behavior_wrong: creating a rule under Disable Apps did not " "produce a row + '1 rules are set.' hint (absent=%s present=%s hint=%r)" % (absent_before, present, hint), depth=3, jump_kind="value", expect="Disable Apps: rule row created AND detail hint '1 rules are set.'") # ══════════════════════════════════════════════════════════════════════════════ # 10. APP EXCEPTIONS: check the app row -> counter increments 0 -> 1 # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_app_exception_counter", "interaction_app_exception_counter_vlm")) def test_app_exception_counter(): clear_data() if not and_reach_app_exceptions("Automatic Grayscale", "Removes color"): record("interaction_app_exception_counter", False, "setup_failed: could not reach Grayscale App Exceptions", depth=2, jump_kind="value", expect="counter '...except 1 selected.' after checking the app row") return before = exceptions_counter(ui()) cb = app_row_checkbox(ui()) checked_ok = cb is not None and tap_node(cb) after = exceptions_counter(ui()) ok = (before == "Active in all apps except 0 selected." and checked_ok and after == "Active in all apps except 1 selected.") record("interaction_app_exception_counter", ok, "" if ok else "behavior_wrong: checking the DetoxDroid app row did not " "move the counter 0 -> 1 (before=%r after=%r)" % (before, after), depth=2, jump_kind="value", expect="counter 'Active in all apps except 0 selected.' -> " "'Active in all apps except 1 selected.'") vlm_assert("interaction_app_exception_counter", "In the app list on this screen, is the checkbox on the right of the " "app row now a FILLED/checked box (showing a check mark) rather than " "an empty outlined square?", RESULTS_DIR, depth=2, jump_kind="value", tag="shape") # ══════════════════════════════════════════════════════════════════════════════ # 11. APP EXCEPTIONS round-trip: check then uncheck -> counter returns to 0 # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_app_exception_roundtrip",)) def test_app_exception_roundtrip(): clear_data() if not and_reach_app_exceptions("Automatic Grayscale", "Removes color"): record("interaction_app_exception_roundtrip", False, "setup_failed: could not reach Grayscale App Exceptions", depth=2, jump_kind="value", expect="counter 0 -> 1 -> 0") return c0 = exceptions_counter(ui()) cb = app_row_checkbox(ui()) up = cb is not None and tap_node(cb) c1 = exceptions_counter(ui()) cb2 = app_row_checkbox(ui()) # re-find (coords may have shifted) down = cb2 is not None and tap_node(cb2) c2 = exceptions_counter(ui()) ok = (up and down and c0 == "Active in all apps except 0 selected." and c1 == "Active in all apps except 1 selected." and c2 == "Active in all apps except 0 selected.") record("interaction_app_exception_roundtrip", ok, "" if ok else "behavior_wrong: check+uncheck did not round-trip the " "counter 0->1->0 (c0=%r c1=%r c2=%r)" % (c0, c1, c2), depth=2, jump_kind="value", expect="counter 0 -> 1 (check) -> 0 (uncheck)") # ══════════════════════════════════════════════════════════════════════════════ # 12. APP-EXCEPTION selection PERSISTS across process death # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_app_exception_persists",)) def test_app_exception_persists(): clear_data() if not and_reach_app_exceptions("Automatic Grayscale", "Removes color"): record("interaction_app_exception_persists", False, "setup_failed: could not reach Grayscale App Exceptions", depth=2, jump_kind="value", expect="counter still '...1 selected.' after relaunch") return cb = app_row_checkbox(ui()) up = cb is not None and tap_node(cb) before = exceptions_counter(ui()) force_stop_and_relaunch() wait_for_foreground() renav = and_reach_app_exceptions("Automatic Grayscale", "Removes color") # depth 2 after = exceptions_counter(ui()) ok = (up and before == "Active in all apps except 1 selected." and renav and after == "Active in all apps except 1 selected.") record("interaction_app_exception_persists", ok, "" if ok else "behavior_wrong: the app-exception selection did not survive " "process death (before=%r after=%r) — an in-memory-only store fails here" % (before, after), depth=2, jump_kind="value", expect="counter 'Active in all apps except 1 selected.' still shown after " "force_stop_and_relaunch + re-navigation") # ══════════════════════════════════════════════════════════════════════════════ # 13. APP EXCEPTIONS on a SECOND feature (Break) -> counter increments # Break defaults to the 'Only selected apps' scope -> different counter phrase. # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_app_exception_break", "interaction_app_exception_break_vlm")) def test_app_exception_break(): clear_data() if not and_reach_app_exceptions("Break Infinite Scrolling", "EXPERIMENTAL"): record("interaction_app_exception_break", False, "setup_failed: could not reach Break App Exceptions", depth=2, jump_kind="value", expect="Break counter 'Active only in 1 selected apps.'") return before = exceptions_counter_only(ui()) cb = app_row_checkbox(ui()) up = cb is not None and tap_node(cb) after = exceptions_counter_only(ui()) ok = (up and before == "Active only in 0 selected apps." and after == "Active only in 1 selected apps.") record("interaction_app_exception_break", ok, "" if ok else "behavior_wrong: checking the app row on Break App " "Exceptions did not move the counter 0 -> 1 (before=%r after=%r)" % (before, after), depth=2, jump_kind="value", expect="Break counter 'Active only in 0 selected apps.' -> " "'Active only in 1 selected apps.'") vlm_assert("interaction_app_exception_break", "In the app list on this screen, is the checkbox on the right of the " "app row now a FILLED/checked box (with a check mark) rather than an " "empty outlined square?", RESULTS_DIR, depth=2, jump_kind="value", tag="shape") # ══════════════════════════════════════════════════════════════════════════════ # 14. IN-SESSION persistence: create a rule, navigate away & back, still there # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_rule_survives_navigation",)) def test_rule_survives_navigation(): clear_data() if not and_reach_schedule("Automatic Grayscale", "Removes color"): record("interaction_rule_survives_navigation", False, "setup_failed: could not reach Grayscale Feature Schedule", depth=2, jump_kind="value", expect="rule row present again after navigating away and back") return made = create_default_rule() present_before = made and has_rule_row(ui()) and_back() # schedule -> Grayscale detail and_back() # detail -> home renav = and_reach_schedule_no_source("Automatic Grayscale") present_after = renav and has_rule_row(ui()) ok = present_before and present_after record("interaction_rule_survives_navigation", ok, "" if ok else "behavior_wrong: the rule vanished after navigating away and " "back within the same session (before=%s after=%s)" % (present_before, present_after), depth=2, jump_kind="value", expect="'Every day' rule row present again after Home->Grayscale->" "Schedule (no restart)") # ══════════════════════════════════════════════════════════════════════════════ # 15. Full 4-step SEQUENCE as ONE test: reach empty schedule -> add -> verify list # -> back -> verify detail hint. Each step depends on the previous one. # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_sequence_add_then_hint",)) def test_sequence_add_then_hint(): clear_data() step_reach = and_reach_schedule("Automatic Grayscale", "Removes color") step_empty = step_reach and schedule_is_empty(ui()) step_made = step_empty and create_default_rule() step_list = step_made and has_rule_row(ui()) hint = None if step_list: and_back() # schedule -> detail hint = detail_hint(ui()) ok = step_reach and step_empty and step_list and hint == "1 rules are set." record("interaction_sequence_add_then_hint", ok, "" if ok else "behavior_wrong: the 4-step chain broke (reach=%s empty=%s " "list=%s hint=%r) — a dead shell that echoes only the last input fails " "here" % (step_reach, step_empty, step_list, hint), depth=3, jump_kind="value", expect="empty schedule -> Add creates a row -> BACK shows detail hint " "'1 rules are set.' (each step depends on the last)") # ══════════════════════════════════════════════════════════════════════════════ # 16. LONG-PRESS (sole owner): long-press a created rule row must not corrupt it. # On this build long-press opens no menu; the record must survive INTACT. # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_longpress_rule_integrity",)) def test_longpress_rule_integrity(): clear_data() if not and_reach_schedule("Automatic Grayscale", "Removes color"): record("interaction_longpress_rule_integrity", False, "setup_failed: could not reach Grayscale Feature Schedule", depth=2, jump_kind="value", expect="exactly one 'Every day' row still present after long-press") return made = create_default_rule() before_ct = len(rule_rows(ui())) pressed = False if made and before_ct == 1: row = find_node(ui(), text="Every day") pressed = row is not None and long_press(row, ms=900) # if the long-press happened to open the edit sheet, close it WITHOUT deleting ns = ui() if find_node_ci(ns, "Delete") is not None and find_node_ci(ns, "Save") is not None: cs = find_node(ns, content_desc="Close sheet") if cs is not None: tap(cs["_center"][0], 90) # tap the inert scrim top strip else: back() ns = ui() after_ct = len(rule_rows(ns)) empty_state_gone = not schedule_is_empty(ns) ok = made and pressed and before_ct == 1 and after_ct == 1 and empty_state_gone record("interaction_longpress_rule_integrity", ok, "" if ok else "behavior_wrong: long-pressing the rule row corrupted the " "data (before_ct=%s after_ct=%s) — the gesture must leave exactly one " "record intact" % (before_ct, after_ct), depth=3, jump_kind="value", expect="after a long-press on the 'Every day' row, still exactly one " "'Every day' rule row (no duplicate, no deletion)") # ══════════════════════════════════════════════════════════════════════════════ # 17. EDIT-SHEET affordances: opening the edit sheet on a rule shows Delete + Save # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_edit_sheet_affordances", "interaction_edit_sheet_affordances_vlm")) def test_edit_sheet_affordances(): clear_data() if not and_reach_schedule("Automatic Grayscale", "Removes color"): record("interaction_edit_sheet_affordances", False, "setup_failed: could not reach Grayscale Feature Schedule", depth=2, jump_kind="value", expect="edit sheet shows Delete + Save for an existing rule") return made = create_default_rule() opened = has_delete = has_save = False if made: row = find_node(ui(), text="Every day") if row is not None and tap_node(row): # -> edit sheet (depth 3) and_enter("edit_sheet") ns = ui() has_delete = find_node_ci(ns, "Delete") is not None has_save = find_node_ci(ns, "Save") is not None opened = find_node(ns, content_desc="Close sheet") is not None or has_save ok = made and opened and has_delete and has_save record("interaction_edit_sheet_affordances", ok, "" if ok else "behavior_wrong: the rule's edit sheet did not expose both " "Delete and Save (opened=%s delete=%s save=%s)" % (opened, has_delete, has_save), depth=3, jump_kind="value", expect="tapping an existing rule opens an edit sheet exposing BOTH a " "'Delete' and a 'Save' action") vlm_assert("interaction_edit_sheet_affordances", "Does this bottom sheet show a 'Delete' text button and a 'Save' text " "button near its bottom, positioned side by side (Delete on the left, " "Save on the right)?", RESULTS_DIR, depth=3, jump_kind="value", tag="position") # ══════════════════════════════════════════════════════════════════════════════ # 18. ADD-SHEET contents (VLM) — opening Add exposes From/To + Save (sheet content) # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_add_sheet_contents", "interaction_add_sheet_contents_vlm")) def test_add_sheet_contents(): clear_data() if not and_reach_schedule("Automatic Grayscale", "Removes color"): record("interaction_add_sheet_contents", False, "setup_failed: could not reach Grayscale Feature Schedule", depth=2, jump_kind="value", expect="Add sheet exposes From/To fields + Save") return opened = and_enter_add_sheet() # -> depth 3 ns = ui() has_from = find_node(ns, text="From") is not None has_to = find_node(ns, text="To") is not None has_save = find_node_ci(ns, "Save") is not None has_days = (find_node(ns, text="Weekdays") is not None and find_node(ns, text="Every day") is not None) ok = opened and has_from and has_to and has_save and has_days record("interaction_add_sheet_contents", ok, "" if ok else "behavior_wrong: the Add rule sheet did not expose the " "From/To fields, the Weekdays/Every day toggle and Save (from=%s to=%s " "save=%s days=%s)" % (has_from, has_to, has_save, has_days), depth=3, jump_kind="value", expect="Add sheet shows 'From' + 'To' time fields, a Weekdays/Every day " "toggle and a 'Save' button") vlm_assert("interaction_add_sheet_contents", "Is a panel anchored to the BOTTOM of the screen showing a 'From' " "time and a 'To' time with a 'Save' button inside the panel?", RESULTS_DIR, depth=3, jump_kind="value", tag="layout") # ══════════════════════════════════════════════════════════════════════════════ # 19. CANCEL a delete: open edit sheet, DISMISS without Delete -> rule survives # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_dismiss_edit_keeps_rule",)) def test_dismiss_edit_keeps_rule(): clear_data() if not and_reach_schedule("Automatic Grayscale", "Removes color"): record("interaction_dismiss_edit_keeps_rule", False, "setup_failed: could not reach Grayscale Feature Schedule", depth=2, jump_kind="value", expect="rule still present after opening & dismissing the edit sheet") return made = create_default_rule() present = made and has_rule_row(ui()) dismissed = False if present and open_edit_sheet("Every day"): back() # dismiss WITHOUT tapping Delete dismissed = True ns = ui() survived = dismissed and has_rule_row(ns) and not schedule_is_empty(ns) ok = present and survived record("interaction_dismiss_edit_keeps_rule", ok, "" if ok else "behavior_wrong: dismissing the edit sheet (no Delete) lost " "the rule (present=%s survived=%s)" % (present, survived), depth=3, jump_kind="value", expect="after opening the edit sheet and dismissing it with BACK (no " "Delete), the 'Every day' rule row is still present") # ══════════════════════════════════════════════════════════════════════════════ # 20. App-exception on Grayscale ALSO updates the feature-detail subtitle # ('Colors are allowed in 0 apps.' -> '...1 apps.') — multi-surface data. # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_app_exception_updates_detail",)) def test_app_exception_updates_detail(): clear_data() if not and_reach_app_exceptions("Automatic Grayscale", "Removes color"): record("interaction_app_exception_updates_detail", False, "setup_failed: could not reach Grayscale App Exceptions", depth=2, jump_kind="value", expect="Grayscale detail subtitle 'Colors are allowed in 1 apps.'") return cb = app_row_checkbox(ui()) up = cb is not None and tap_node(cb) counter_ok = exceptions_counter(ui()) == "Active in all apps except 1 selected." and_back() # App Exceptions -> Grayscale detail subtitle = None for n in ui(): t = n.get("text", "") if t.startswith("Colors are allowed in"): subtitle = t break ok = up and counter_ok and subtitle == "Colors are allowed in 1 apps." record("interaction_app_exception_updates_detail", ok, "" if ok else "behavior_wrong: checking one app did not update the " "Grayscale detail 'App Exceptions' subtitle to '...1 apps.' " "(counter_ok=%s subtitle=%r)" % (counter_ok, subtitle), depth=2, jump_kind="value", expect="Grayscale detail 'App Exceptions' subtitle == 'Colors are allowed " "in 1 apps.' after checking one app") TESTS = [ test_create_rule, test_rule_updates_detail_hint, test_two_rules_multi_record, test_delete_one_keeps_other, test_delete_rule_empties, test_edit_rule, test_rule_persists_process_death, test_rule_per_feature_isolation, test_create_rule_disable_apps, test_app_exception_counter, test_app_exception_roundtrip, test_app_exception_persists, test_app_exception_break, test_rule_survives_navigation, test_sequence_add_then_hint, test_longpress_rule_integrity, test_edit_sheet_affordances, test_add_sheet_contents, test_dismiss_edit_keeps_rule, test_app_exception_updates_detail, ] if __name__ == "__main__": run_suite(TESTS, "interaction")