RecreationBench / android /kin69-easynotes /tests /test_android_interaction.py
VoyagerXHF's picture
Upload folder using huggingface_hub (part 3)
c1c6a0c verified
Raw History Blame Contribute Delete
53.7 kB
#!/usr/bin/env python3
"""INTERACTION lane — EFFECT-BY-CONSEQUENCE on user DATA for EasyNotes.
Every test drives the app to a data-mutating action through the real user path,
then reads the CONSEQUENCE back out of a fresh ui(): a card appeared / changed /
disappeared, a selection count changed, a markdown token landed in the body.
Ground truth (verified live against the original before writing):
* Create: New Note FAB -> Edit page (Name/Description EditTexts) -> Done. Empty
notes (no title AND no body) are discarded. A note created via Done stays on
Home (app foreground).
* Home card = a title TextView (bold) + a body-preview TextView. The app
CAPITALISES the first character of the displayed TITLE (a title typed as
'kitI_x' renders as 'KitI_x'), so all title read-backs are case-insensitive.
The body preview is shown verbatim.
* Edit existing: tap card -> Preview (Back/Info) -> tap the pencil toggle (left
half of the top-center switch, cx~466) -> Edit page (Done appears) -> change
Description -> BACK. Leaving Edit that was reached FROM Preview pops back past
Home to the launcher, so the suite RELAUNCHES to read the persisted result.
* Delete via More: Preview -> Info -> Delete menu item. NO confirmation; the app
backgrounds afterwards, so relaunch to observe. DB reflects the deletion.
* Delete via selection bar: long-press card -> Delete -> confirm "Yes".
* Selection mode: long-press a card -> top bar Close / count TextView / Pin /
Delete, and (when selected != total) `Select All` (content-desc, capital A).
Cards render in a 2-col grid; the selected card gets a coloured border.
* Markdown toolbar (Description focused): the two arrow buttons ALSO carry
content-desc `Bullet List`; the REAL Bullet List is the interior node (sort by
x, take the middle). Bullet inserts `- `, Checkbox inserts `[ ] `.
* Notes + edits persist across process death (Room DB).
"""
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from android_testgen_kit import * # noqa: F403,F401
# ── distinctive markers (so a read-back cannot match pre-existing content) ──────
M_CREATE = "kitI_CreateA"
M_BODY_T = "kitI_BodyT"
M_BODY_B = "kitI_bodybtext"
M_TWO_1 = "kitI_TwoA"
M_TWO_2 = "kitI_TwoB"
M_EDIT_T = "kitI_EditMe"
M_EDIT_MARK = "kitiedited" # goes in the BODY (verbatim), lower-case safe
M_DEL_T = "kitI_DelTarget"
M_KEEP_T = "kitI_KeepSafe"
M_SOLO = "kitI_Solo"
M_PERSIST = "kitI_Persist"
M_EDITP_T = "kitI_EditPersist"
M_LP = "kitI_LongPress"
M_SEL1 = "kitI_SelOne"
M_SEL2 = "kitI_SelTwo"
M_SA1 = "kitI_SaOne"
M_SA2 = "kitI_SaTwo"
M_SDEL_DEL = "kitI_SbDel"
M_SDEL_KEEP = "kitI_SbKeep"
M_MK = "kitI_MarkNote"
M_MK2 = "kitI_MarkCheck"
# body texts (shown verbatim on the card — chosen distinctive, lower-case ok)
B_ORIG = "origbody"
B_TRI = ("btrione", "btritwo", "btrithree")
# ══════════════════════════════════════════════════════════════════════════════
# Helpers (plain; the and_enter_* / and_reach_* NAMES back the declared depth)
# ══════════════════════════════════════════════════════════════════════════════
def _ci(nodes, marker):
"""Case-insensitive text/desc lookup. EasyNotes CAPITALISES the first char of
a displayed note TITLE ('kitI_x' -> 'KitI_x'), so every title/body read-back
matches case-insensitively — never exact."""
return find_node_ci(nodes, marker)
def find_card(nodes, marker):
"""The node carrying `marker` as a note title/body (case-insensitive)."""
return _ci(nodes, marker)
def has_text(nodes, marker):
return _ci(nodes, marker) is not None
def sorted_edittexts(nodes):
"""EditTexts top-to-bottom: [0]=Name, [1]=Description on the Edit page."""
return sorted(find_by_class(nodes, "EditText"),
key=lambda e: e.get("_bounds", (0, 0, 0, 0))[1])
def _on_home(nodes=None):
nodes = nodes or ui()
return find_node(nodes, content_desc="New Note") is not None
def ensure_home():
"""Return to the app's Home surface, launcher-proof.
Deleting or editing a note opened from Preview pops the app PAST Home to the
launcher; is_app_foreground() is unreliable there (the app still shows in
`dumpsys window`), so this keys ONLY off the New Note FAB — Home's
discriminator. It first tries BACK (in case we are one surface above Home),
then RELAUNCHES unconditionally until the FAB reappears."""
for attempt in range(4):
if _on_home():
return
# one BACK may drop Preview/Edit -> Home without a relaunch
back()
settle("tap")
if _on_home():
return
launch_app()
wait_for_foreground()
settle("tap")
# last resort: relaunch once more and settle harder
if not _on_home():
launch_app()
wait_for_foreground()
settle("dump")
def and_enter_editor():
"""Open the note editor via the New Note FAB. Backs depth>=1."""
n = ui()
fab = find_node(n, content_desc="New Note")
if fab is None or not tap_node(fab):
return False
and_enter("editor")
return True
def create_note(title, body=""):
"""Full create path: FAB -> type Name (+Description) -> Done. Leaves the app
on Home (verified: Done from a fresh note keeps the app foreground)."""
if not and_enter_editor():
return False
ets = sorted_edittexts(ui())
if not ets:
return False
if title:
type_text(ets[0], title)
if body:
ets = sorted_edittexts(ui())
if len(ets) > 1:
type_text(ets[1], body)
hide_keyboard()
done = find_node(ui(), content_desc="Done") or find_node(ui(), content_desc="Back")
if done:
tap_node(done)
wait_for_foreground()
settle("tap")
return True
def and_reach_preview(title):
"""Tap a note card and PROVE Preview opened: Info appeared, the FAB (a Home
discriminator) vanished. Backs depth>=1 with a real reach."""
n = ui()
card = find_card(n, title)
if card is None:
return False
before = and_showing(n)
if not tap_node(card):
return False
after = and_showing()
ok = and_reach(before, after, "Info", "New Note")
if ok:
and_enter("preview")
return ok
def find_edit_pencil(nodes):
"""The Edit (pencil) half of the top-center mode toggle: a small anonymous
View at cx~466 in the top strip (the eye/Preview half sits at cx~613)."""
cands = []
for x in nodes:
b = x.get("_bounds")
if not b:
continue
cx, cy = x.get("_center", (0, 0))
w, h = b[2] - b[0], b[3] - b[1]
if (100 < cy < 200 and 40 < w < 200 and 40 < h < 200
and 380 < cx < 520 and x.get("class", "").endswith("View")):
cands.append(x)
cands.sort(key=lambda x: x.get("_center", (0, 0))[0])
return cands[0] if cands else None
def and_enter_edit_from_preview():
"""From Preview, tap the pencil toggle to enter Edit. Confirms via Done. Backs
one more surface (depth>=2 when chained after and_reach_preview)."""
pencil = find_edit_pencil(ui())
if pencil is None or not tap_node(pencil):
return False
settle("tap")
if find_node(ui(), content_desc="Done") is None:
return False
and_enter("edit")
return True
def save_edit():
"""Persist the current Edit and return to Home DETERMINISTICALLY. Tapping the
Done checkmark saves and lands directly on Home (verified) — unlike
hide_keyboard()+BACK, whose BACK can overshoot Home to the launcher."""
done = find_node(ui(), content_desc="Done")
if done:
tap_node(done)
settle("tap")
ensure_home()
def and_enter_selection(title):
"""Long-press a card to enter selection mode. Confirms via the Close control
(selection-bar discriminator). Backs depth>=1."""
n = ui()
card = find_card(n, title)
if card is None:
return False
if not long_press(card, ms=900):
return False
settle("tap")
if find_node(ui(), content_desc="Close") is None:
return False
and_enter("selection")
return True
def and_enter_more_menu():
"""From Preview, tap Info to open the More dropdown. Confirms via the Delete
item. Backs one more surface."""
info = find_node(ui(), content_desc="Info")
if info is None or not tap_node(info):
return False
settle("tap")
if find_node(ui(), text="Delete") is None and find_node(ui(), content_desc="Delete") is None:
return False
and_enter("more_menu")
return True
def selection_count(nodes=None):
"""The selection-bar count as an int (the lone digit TextView), or None."""
nodes = nodes or ui()
for n in nodes:
t = n.get("text", "").strip()
if t.isdigit() and n.get("class", "").endswith("TextView"):
return int(t)
return None
def focus_description_toolbar():
"""In Edit, focus the Description field so the markdown toolbar appears.
Returns the toolbar nodes, or None."""
ets = sorted_edittexts(ui())
if len(ets) < 2:
return None
type_text(ets[1], "x") # focuses + gives the field content
n = ui()
if find_node(n, content_desc="Checkbox") is None:
return None
return n
def markdown_bullet_node(nodes):
"""The interior Bullet List button (the two arrows share that content-desc)."""
bl = sorted(find_nodes(nodes, content_desc="Bullet List"),
key=lambda x: x.get("_center", (0, 0))[0])
if len(bl) >= 3:
return bl[1]
if bl:
return bl[len(bl) // 2]
return None
# ══════════════════════════════════════════════════════════════════════════════
# 1. Create note -> new card with that title appears on Home
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_create_note",
"interaction_create_note_vlm"))
def test_create_note():
clear_data()
restart_app()
if not wait_for_foreground():
record("interaction_create_note", False,
"setup_failed: app did not reach foreground",
depth=1, jump_kind="value", expect=f"card {M_CREATE!r} on Home")
record("interaction_create_note_vlm", False,
"setup_failed: app did not reach foreground",
depth=1, jump_kind="value", expect="bold title card", tag="content")
return
absent_before = not has_text(ui(), M_CREATE)
if not create_note(M_CREATE, "somebody"):
record("interaction_create_note", False,
"feature_missing: could not open editor / type / save",
depth=1, jump_kind="value", expect=f"card {M_CREATE!r} on Home")
record("interaction_create_note_vlm", False,
"feature_missing: could not create note",
depth=1, jump_kind="value", expect="bold title card", tag="content")
return
ensure_home()
present_after = has_text(ui(), M_CREATE)
ok = absent_before and present_after
record("interaction_create_note", ok,
"" if ok else "behavior_wrong: created card did not appear on Home",
depth=1, jump_kind="value", expect=f"card {M_CREATE!r} on Home")
# VLM: the created note renders as a card with a bold title.
vlm_assert("interaction_create_note",
f"Is there a note card near the top of the list whose title "
f"'{M_CREATE}' is shown in BOLD (heavier weight than the body text "
f"below it)?",
depth=1, jump_kind="value", tag="content")
# ══════════════════════════════════════════════════════════════════════════════
# 2. Create note -> the body preview also shows on the card
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_create_body_preview",))
def test_create_body_preview():
clear_data()
restart_app()
wait_for_foreground()
absent_before = not has_text(ui(), M_BODY_B)
if not create_note(M_BODY_T, M_BODY_B):
record("interaction_create_body_preview", False,
"feature_missing: could not create note with a body",
depth=1, jump_kind="value", expect=f"body preview {M_BODY_B!r} on card")
return
ensure_home()
n = ui()
ok = absent_before and has_text(n, M_BODY_T) and has_text(n, M_BODY_B)
record("interaction_create_body_preview", ok,
"" if ok else "behavior_wrong: card body preview text did not appear",
depth=1, jump_kind="value", expect=f"body preview {M_BODY_B!r} on card")
# ══════════════════════════════════════════════════════════════════════════════
# 3. Create TWO notes -> both cards present (multi-record integrity)
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_two_notes",
"interaction_two_notes_vlm"))
def test_two_notes():
clear_data()
restart_app()
wait_for_foreground()
ok1 = create_note(M_TWO_1, "aaa")
ok2 = create_note(M_TWO_2, "bbb")
ensure_home()
n = ui()
both = ok1 and ok2 and has_text(n, M_TWO_1) and has_text(n, M_TWO_2)
record("interaction_two_notes", both,
"" if both else "behavior_wrong: both created cards are not both present",
depth=1, jump_kind="value",
expect=f"cards {M_TWO_1!r} and {M_TWO_2!r} both on Home")
# VLM: two distinct cards, laid out as a grid/stack (not one merged row).
vlm_assert("interaction_two_notes",
"Are there exactly two separate note cards laid out in the list "
"area (arranged as a grid or stacked column), each a distinct "
"rounded rectangle?",
depth=1, jump_kind="value", tag="layout")
# ══════════════════════════════════════════════════════════════════════════════
# 4. Edit existing note body -> card body preview updates
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_edit_body",))
def test_edit_body():
clear_data()
restart_app()
wait_for_foreground()
if not create_note(M_EDIT_T, B_ORIG):
record("interaction_edit_body", False,
"setup_failed: could not create the note to edit",
depth=2, jump_kind="value", expect=f"card body contains {M_EDIT_MARK!r}")
return
ensure_home()
if not and_reach_preview(M_EDIT_T):
record("interaction_edit_body", False,
"setup_failed: could not open the note's Preview",
depth=2, jump_kind="value", expect=f"card body contains {M_EDIT_MARK!r}")
return
if not and_enter_edit_from_preview():
record("interaction_edit_body", False,
"setup_failed: could not switch Preview -> Edit",
depth=2, jump_kind="value", expect=f"card body contains {M_EDIT_MARK!r}")
return
ets = sorted_edittexts(ui())
if len(ets) < 2:
record("interaction_edit_body", False,
"setup_failed: Description field not found in Edit",
depth=2, jump_kind="value", expect=f"card body contains {M_EDIT_MARK!r}")
return
type_text(ets[1], " " + M_EDIT_MARK) # append the distinctive marker
save_edit() # Done -> Home (deterministic)
n = ui()
body = has_text(n, B_ORIG + " " + M_EDIT_MARK)
ok = has_text(n, M_EDIT_T) and body
record("interaction_edit_body", ok,
"" if ok else "behavior_wrong: edited body preview did not update on the card",
depth=2, jump_kind="value",
expect=f"card {M_EDIT_T!r} body now '{B_ORIG} {M_EDIT_MARK}'")
# ══════════════════════════════════════════════════════════════════════════════
# 5. Delete via More menu -> card GONE (and placeholder returns if it was the last)
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_delete_via_menu",
"interaction_delete_via_menu_vlm"))
def test_delete_via_menu():
clear_data()
restart_app()
wait_for_foreground()
if not create_note(M_SOLO, "byebye"):
record("interaction_delete_via_menu", False,
"setup_failed: could not create the note to delete",
depth=2, jump_kind="value", expect=f"{M_SOLO!r} gone; placeholder shown")
record("interaction_delete_via_menu_vlm", False,
"setup_failed: could not create note",
depth=2, jump_kind="value", expect="empty-state placeholder", tag="layout")
return
ensure_home()
present_before = has_text(ui(), M_SOLO)
if not and_reach_preview(M_SOLO):
record("interaction_delete_via_menu", False,
"setup_failed: could not open Preview",
depth=2, jump_kind="value", expect=f"{M_SOLO!r} gone; placeholder shown")
record("interaction_delete_via_menu_vlm", False,
"setup_failed: could not open Preview",
depth=2, jump_kind="value", expect="empty-state placeholder", tag="layout")
return
if not and_enter_more_menu():
record("interaction_delete_via_menu", False,
"feature_missing: no More menu / Delete item",
depth=2, jump_kind="value", expect=f"{M_SOLO!r} gone; placeholder shown")
record("interaction_delete_via_menu_vlm", False,
"feature_missing: no Delete item",
depth=2, jump_kind="value", expect="empty-state placeholder", tag="layout")
return
n = ui()
dele = find_node(n, text="Delete") or find_node(n, content_desc="Delete")
if dele is None or not tap_node(dele):
record("interaction_delete_via_menu", False,
"feature_missing: Delete menu item not tappable",
depth=2, jump_kind="value", expect=f"{M_SOLO!r} gone; placeholder shown")
record("interaction_delete_via_menu_vlm", False,
"feature_missing: Delete not tappable",
depth=2, jump_kind="value", expect="empty-state placeholder", tag="layout")
return
settle("tap")
ensure_home() # deleting from Preview backgrounds
n = ui()
gone = not has_text(n, M_SOLO)
placeholder = find_node(n, text="No created notes.") is not None
ok = present_before and gone and placeholder
record("interaction_delete_via_menu", ok,
"" if ok else "behavior_wrong: note not removed after menu Delete",
depth=2, jump_kind="value",
expect=f"{M_SOLO!r} gone from Home; 'No created notes.' shown")
# VLM: empty-state placeholder (list icon + text) now shown.
vlm_assert("interaction_delete_via_menu",
"Does the screen show an empty-state placeholder — a centered icon "
"with the message 'No created notes.' — and no note cards at all?",
depth=2, jump_kind="value", tag="layout")
# ══════════════════════════════════════════════════════════════════════════════
# 6. Delete via menu leaves OTHER notes intact
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_delete_leaves_others",))
def test_delete_leaves_others():
clear_data()
restart_app()
wait_for_foreground()
create_note(M_KEEP_T, "keepbody")
create_note(M_DEL_T, "delbody")
ensure_home()
if not (has_text(ui(), M_KEEP_T) and has_text(ui(), M_DEL_T)):
record("interaction_delete_leaves_others", False,
"setup_failed: could not create both notes",
depth=2, jump_kind="value",
expect=f"{M_KEEP_T!r} remains after deleting {M_DEL_T!r}")
return
if not and_reach_preview(M_DEL_T):
record("interaction_delete_leaves_others", False,
"setup_failed: could not open Preview of the delete target",
depth=2, jump_kind="value",
expect=f"{M_KEEP_T!r} remains after deleting {M_DEL_T!r}")
return
if not and_enter_more_menu():
record("interaction_delete_leaves_others", False,
"feature_missing: no More menu / Delete item",
depth=2, jump_kind="value",
expect=f"{M_KEEP_T!r} remains after deleting {M_DEL_T!r}")
return
n = ui()
dele = find_node(n, text="Delete") or find_node(n, content_desc="Delete")
if dele is None or not tap_node(dele):
record("interaction_delete_leaves_others", False,
"feature_missing: Delete menu item not tappable",
depth=2, jump_kind="value",
expect=f"{M_KEEP_T!r} remains after deleting {M_DEL_T!r}")
return
settle("tap")
ensure_home()
n = ui()
ok = (not has_text(n, M_DEL_T)) and has_text(n, M_KEEP_T)
record("interaction_delete_leaves_others", ok,
"" if ok else "behavior_wrong: sibling note lost (or target survived) after delete",
depth=2, jump_kind="value",
expect=f"{M_DEL_T!r} gone, {M_KEEP_T!r} still on Home")
# ══════════════════════════════════════════════════════════════════════════════
# 7. Note persists across process death (signature test)
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_note_persists",))
def test_note_persists():
clear_data()
restart_app()
wait_for_foreground()
absent_before = not has_text(ui(), M_PERSIST)
if not create_note(M_PERSIST, "survive"):
record("interaction_note_persists", False,
"setup_failed: could not create the note",
depth=0, jump_kind="value", expect=f"card {M_PERSIST!r} after relaunch")
return
ensure_home()
present_before = has_text(ui(), M_PERSIST)
force_stop_and_relaunch()
wait_for_foreground()
settle("tap")
ensure_home()
present_after = has_text(ui(), M_PERSIST)
ok = absent_before and present_before and present_after
record("interaction_note_persists", ok,
"" if ok else "behavior_wrong: note did not survive process death",
depth=0, jump_kind="value", expect=f"card {M_PERSIST!r} still on Home after relaunch")
# ══════════════════════════════════════════════════════════════════════════════
# 8. Edit persists across process death
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_edit_persists",))
def test_edit_persists():
clear_data()
restart_app()
wait_for_foreground()
if not create_note(M_EDITP_T, "beforeedit"):
record("interaction_edit_persists", False,
"setup_failed: could not create the note to edit",
depth=2, jump_kind="value", expect=f"body 'beforeedit {M_EDIT_MARK}' after relaunch")
return
ensure_home()
if not and_reach_preview(M_EDITP_T):
record("interaction_edit_persists", False,
"setup_failed: could not open Preview",
depth=2, jump_kind="value", expect=f"body 'beforeedit {M_EDIT_MARK}' after relaunch")
return
if not and_enter_edit_from_preview():
record("interaction_edit_persists", False,
"setup_failed: could not enter Edit",
depth=2, jump_kind="value", expect=f"body 'beforeedit {M_EDIT_MARK}' after relaunch")
return
ets = sorted_edittexts(ui())
if len(ets) < 2:
record("interaction_edit_persists", False,
"setup_failed: Description field missing",
depth=2, jump_kind="value", expect=f"body 'beforeedit {M_EDIT_MARK}' after relaunch")
return
type_text(ets[1], " " + M_EDIT_MARK)
save_edit() # commit the edit to the DB first
force_stop_and_relaunch()
wait_for_foreground()
settle("tap")
ensure_home()
n = ui()
ok = has_text(n, M_EDITP_T) and has_text(n, "beforeedit " + M_EDIT_MARK)
record("interaction_edit_persists", ok,
"" if ok else "behavior_wrong: edited body did not survive process death",
depth=2, jump_kind="value",
expect=f"card {M_EDITP_T!r} body 'beforeedit {M_EDIT_MARK}' after relaunch")
# ══════════════════════════════════════════════════════════════════════════════
# 9. Long-press -> selection mode (SOLE OWNER of long-press)
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_longpress_selection",
"interaction_longpress_selection_vlm"))
def test_longpress_selection():
clear_data()
restart_app()
wait_for_foreground()
if not create_note(M_LP, "lp"):
record("interaction_longpress_selection", False,
"setup_failed: could not create a card to long-press",
depth=1, jump_kind="transition", expect="selection bar: Close/Pin/Delete + count 1")
record("interaction_longpress_selection_vlm", False,
"setup_failed: could not create note",
depth=1, jump_kind="transition", expect="selected card border", tag="color")
return
ensure_home()
n = ui()
before = and_showing(n)
normal_mode = find_node(n, content_desc="Close") is None
if not and_enter_selection(M_LP):
record("interaction_longpress_selection", False,
"feature_missing: long-press did not enter selection mode",
depth=1, jump_kind="transition", expect="selection bar: Close/Pin/Delete + count 1")
record("interaction_longpress_selection_vlm", False,
"feature_missing: no selection mode",
depth=1, jump_kind="transition", expect="selected card border", tag="color")
return
after = and_showing()
n = ui()
bar = (find_node(n, content_desc="Close") is not None
and find_node(n, content_desc="Pin") is not None
and find_node(n, content_desc="Delete") is not None)
count1 = selection_count(n) == 1
flipped = normal_mode and and_reach(before, after, "Close", "Settings")
ok = bar and count1 and flipped
record("interaction_longpress_selection", ok,
"" if ok else "behavior_wrong: selection bar (Close/Pin/Delete + count 1) not shown",
depth=1, jump_kind="transition",
expect="selection top bar shows Close/Pin/Delete and count '1'")
# VLM: the long-pressed card gains a coloured highlighted border outline.
vlm_assert("interaction_longpress_selection",
f"The note card '{M_LP}' is selected. Does that card have a "
f"clearly visible coloured (blue/dark) BORDER outline around its "
f"edges, distinguishing it as selected?",
depth=1, jump_kind="transition", tag="color")
# ══════════════════════════════════════════════════════════════════════════════
# 10. Selection count increments 1 -> 2
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_selection_count",
"interaction_selection_count_vlm"))
def test_selection_count():
clear_data()
restart_app()
wait_for_foreground()
create_note(M_SEL1, "s1")
create_note(M_SEL2, "s2")
ensure_home()
if not (has_text(ui(), M_SEL1) and has_text(ui(), M_SEL2)):
record("interaction_selection_count", False,
"setup_failed: could not create both notes",
depth=1, jump_kind="value", expect="selection count 1 -> 2")
record("interaction_selection_count_vlm", False,
"setup_failed: could not create notes",
depth=1, jump_kind="value", expect="both cards selected border", tag="color")
return
if not and_enter_selection(M_SEL1):
record("interaction_selection_count", False,
"feature_missing: long-press did not enter selection mode",
depth=1, jump_kind="value", expect="selection count 1 -> 2")
record("interaction_selection_count_vlm", False,
"feature_missing: no selection mode",
depth=1, jump_kind="value", expect="both cards selected border", tag="color")
return
c1 = selection_count(ui())
# tap the OTHER card to add it to the selection
other = find_card(ui(), M_SEL2)
tapped = tap_node(other) if other else False
settle("tap")
c2 = selection_count(ui())
ok = tapped and c1 == 1 and c2 == 2
record("interaction_selection_count", ok,
"" if ok else f"behavior_wrong: count did not go 1->2 (got {c1}->{c2})",
depth=1, jump_kind="value", expect="selection count text '1' then '2'")
# VLM: two cards, both now selected (both show a highlighted border).
vlm_assert("interaction_selection_count",
"Two note cards are selected. Do BOTH cards show a coloured "
"(blue/dark) highlighted border outline indicating they are both "
"selected?",
depth=1, jump_kind="value", tag="color")
# ══════════════════════════════════════════════════════════════════════════════
# 11. Select-all with 2 notes -> count reaches total (2)
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_select_all",))
def test_select_all():
clear_data()
restart_app()
wait_for_foreground()
create_note(M_SA1, "sa1")
create_note(M_SA2, "sa2")
ensure_home()
if not (has_text(ui(), M_SA1) and has_text(ui(), M_SA2)):
record("interaction_select_all", False,
"setup_failed: could not create both notes",
depth=1, jump_kind="value", expect="count reaches 2 after Select All")
return
if not and_enter_selection(M_SA1):
record("interaction_select_all", False,
"feature_missing: long-press did not enter selection mode",
depth=1, jump_kind="value", expect="count reaches 2 after Select All")
return
n = ui()
sa = find_node(n, content_desc="Select All") or find_node_ci(n, "Select all")
if sa is None:
record("interaction_select_all", False,
"feature_missing: 'Select All' control not present with 1 of 2 selected",
depth=1, jump_kind="value", expect="count reaches 2 after Select All")
return
present_when_partial = True
tap_node(sa)
settle("tap")
c = selection_count(ui())
ok = present_when_partial and c == 2
record("interaction_select_all", ok,
"" if ok else f"behavior_wrong: Select All did not select all (count={c})",
depth=1, jump_kind="value", expect="selection count '2' after tapping Select All")
# ══════════════════════════════════════════════════════════════════════════════
# 12. Delete via selection mode -> target gone, other remains
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_selection_delete",
"interaction_selection_delete_vlm"))
def test_selection_delete():
clear_data()
restart_app()
wait_for_foreground()
create_note(M_SDEL_KEEP, "keep")
create_note(M_SDEL_DEL, "del")
ensure_home()
if not (has_text(ui(), M_SDEL_KEEP) and has_text(ui(), M_SDEL_DEL)):
record("interaction_selection_delete", False,
"setup_failed: could not create both notes",
depth=1, jump_kind="value",
expect=f"{M_SDEL_DEL!r} gone, {M_SDEL_KEEP!r} remains")
record("interaction_selection_delete_vlm", False,
"setup_failed: could not create notes",
depth=1, jump_kind="content", expect="pin + trash icons", tag="content")
return
if not and_enter_selection(M_SDEL_DEL):
record("interaction_selection_delete", False,
"feature_missing: long-press did not enter selection mode",
depth=1, jump_kind="value",
expect=f"{M_SDEL_DEL!r} gone, {M_SDEL_KEEP!r} remains")
record("interaction_selection_delete_vlm", False,
"feature_missing: no selection mode",
depth=1, jump_kind="content", expect="pin + trash icons", tag="content")
return
# VLM (before we destroy anything): the selection bar shows Pin + trash icons.
vlm_assert("interaction_selection_delete",
"In the top action bar of this selection mode, are BOTH a pin icon "
"and a delete (trash can) icon visible on the right-hand side?",
depth=1, jump_kind="content", tag="content")
n = ui()
dele = find_node(n, content_desc="Delete")
if dele is None or not tap_node(dele):
record("interaction_selection_delete", False,
"feature_missing: selection-bar Delete not tappable",
depth=1, jump_kind="value",
expect=f"{M_SDEL_DEL!r} gone, {M_SDEL_KEEP!r} remains")
return
settle("tap")
# confirmation dialog: "Are you sure ..." -> Yes
yes = find_node(ui(), text="Yes")
if yes is not None:
tap_node(yes)
settle("tap")
ensure_home()
n = ui()
ok = (not has_text(n, M_SDEL_DEL)) and has_text(n, M_SDEL_KEEP)
record("interaction_selection_delete", ok,
"" if ok else "behavior_wrong: selection-delete removed wrong note(s)",
depth=1, jump_kind="value",
expect=f"{M_SDEL_DEL!r} gone, {M_SDEL_KEEP!r} still on Home")
# ══════════════════════════════════════════════════════════════════════════════
# 13. Markdown bullet insert -> Description value contains "- "
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_markdown_bullet",))
def test_markdown_bullet():
clear_data()
restart_app()
wait_for_foreground()
if not and_enter_editor():
record("interaction_markdown_bullet", False,
"setup_failed: could not open the editor",
depth=1, jump_kind="value", expect="Description value contains '- '")
return
ets = sorted_edittexts(ui())
if ets:
type_text(ets[0], M_MK)
toolbar = focus_description_toolbar()
if toolbar is None:
record("interaction_markdown_bullet", False,
"feature_missing: markdown toolbar did not appear on Description focus",
depth=1, jump_kind="value", expect="Description value contains '- '")
return
bullet = markdown_bullet_node(toolbar)
if bullet is None or not tap_node(bullet):
record("interaction_markdown_bullet", False,
"feature_missing: Bullet List button not found/tappable",
depth=1, jump_kind="value", expect="Description value contains '- '")
return
settle("tap")
ets = sorted_edittexts(ui())
desc_val = ets[1].get("text", "") if len(ets) > 1 else ""
# XML encodes the inserted newline as &#10;; the "- " token is what we assert.
ok = "- " in desc_val
record("interaction_markdown_bullet", ok,
"" if ok else f"behavior_wrong: bullet token not inserted (desc={desc_val!r})",
depth=1, jump_kind="value", expect="Description value contains '- '")
# ══════════════════════════════════════════════════════════════════════════════
# 14. Markdown checkbox insert -> Description value contains "[ ] "
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_markdown_checkbox",))
def test_markdown_checkbox():
clear_data()
restart_app()
wait_for_foreground()
if not and_enter_editor():
record("interaction_markdown_checkbox", False,
"setup_failed: could not open the editor",
depth=1, jump_kind="value", expect="Description value contains '[ ] '")
return
ets = sorted_edittexts(ui())
if ets:
type_text(ets[0], M_MK2)
toolbar = focus_description_toolbar()
if toolbar is None:
record("interaction_markdown_checkbox", False,
"feature_missing: markdown toolbar did not appear on Description focus",
depth=1, jump_kind="value", expect="Description value contains '[ ] '")
return
cb = find_node(toolbar, content_desc="Checkbox")
if cb is None or not tap_node(cb):
record("interaction_markdown_checkbox", False,
"feature_missing: Checkbox button not found/tappable",
depth=1, jump_kind="value", expect="Description value contains '[ ] '")
return
settle("tap")
ets = sorted_edittexts(ui())
desc_val = ets[1].get("text", "") if len(ets) > 1 else ""
ok = "[ ] " in desc_val
record("interaction_markdown_checkbox", ok,
"" if ok else f"behavior_wrong: checkbox token not inserted (desc={desc_val!r})",
depth=1, jump_kind="value", expect="Description value contains '[ ] '")
# ══════════════════════════════════════════════════════════════════════════════
# 15. Empty note discarded -> no new card, placeholder stays
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_empty_discarded",))
def test_empty_note_discarded():
clear_data()
restart_app()
wait_for_foreground()
placeholder_before = find_node(ui(), text="No created notes.") is not None
if not and_enter_editor():
record("interaction_empty_discarded", False,
"setup_failed: could not open the editor",
depth=1, jump_kind="value", expect="'No created notes.' still shown")
return
# leave without typing anything -> should discard
done = find_node(ui(), content_desc="Done") or find_node(ui(), content_desc="Back")
if done:
tap_node(done)
settle("tap")
ensure_home()
n = ui()
placeholder_after = find_node(n, text="No created notes.") is not None
ok = placeholder_before and placeholder_after
record("interaction_empty_discarded", ok,
"" if ok else "behavior_wrong: empty note was NOT discarded",
depth=1, jump_kind="value", expect="'No created notes.' still shown after empty note")
# ══════════════════════════════════════════════════════════════════════════════
# 16. Three notes -> edit the MIDDLE -> first & third intact and still present
# ══════════════════════════════════════════════════════════════════════════════
M_TRI_1 = "kitI_TriOne"
M_TRI_2 = "kitI_TriTwo"
M_TRI_3 = "kitI_TriThree"
@and_test(expects=("interaction_three_edit_middle",))
def test_three_edit_middle():
clear_data()
restart_app()
wait_for_foreground()
create_note(M_TRI_1, B_TRI[0])
create_note(M_TRI_2, B_TRI[1])
create_note(M_TRI_3, B_TRI[2])
ensure_home()
n = ui()
if not (has_text(n, M_TRI_1) and has_text(n, M_TRI_2) and has_text(n, M_TRI_3)):
record("interaction_three_edit_middle", False,
"setup_failed: could not create all three notes",
depth=2, jump_kind="value",
expect=f"{M_TRI_1!r} & {M_TRI_3!r} intact after editing {M_TRI_2!r}")
return
# edit the middle note's body
if not and_reach_preview(M_TRI_2):
record("interaction_three_edit_middle", False,
"setup_failed: could not open Preview of the middle note",
depth=2, jump_kind="value",
expect=f"{M_TRI_1!r} & {M_TRI_3!r} intact after editing {M_TRI_2!r}")
return
if not and_enter_edit_from_preview():
record("interaction_three_edit_middle", False,
"setup_failed: could not enter Edit for the middle note",
depth=2, jump_kind="value",
expect=f"{M_TRI_1!r} & {M_TRI_3!r} intact after editing {M_TRI_2!r}")
return
ets = sorted_edittexts(ui())
if len(ets) >= 2:
type_text(ets[1], " " + M_EDIT_MARK)
save_edit()
n = ui()
middle_edited = has_text(n, B_TRI[1] + " " + M_EDIT_MARK)
others_intact = (has_text(n, M_TRI_1) and has_text(n, M_TRI_3)
and has_text(n, B_TRI[0]) and has_text(n, B_TRI[2]))
ok = middle_edited and others_intact
record("interaction_three_edit_middle", ok,
"" if ok else "behavior_wrong: neighbours lost/changed after editing the middle note",
depth=2, jump_kind="value",
expect=f"{M_TRI_2!r} body '{B_TRI[1]} {M_EDIT_MARK}'; {M_TRI_1!r}({B_TRI[0]}) & {M_TRI_3!r}({B_TRI[2]}) intact")
# ══════════════════════════════════════════════════════════════════════════════
# 17. Multi-record persistence: create 2, force-stop+relaunch, BOTH survive
# ══════════════════════════════════════════════════════════════════════════════
M_MP_1 = "kitI_MpOne"
M_MP_2 = "kitI_MpTwo"
@and_test(expects=("interaction_multi_persist",
"interaction_multi_persist_vlm"))
def test_multi_persist():
clear_data()
restart_app()
wait_for_foreground()
create_note(M_MP_1, "mp1")
create_note(M_MP_2, "mp2")
ensure_home()
both_before = has_text(ui(), M_MP_1) and has_text(ui(), M_MP_2)
if not both_before:
record("interaction_multi_persist", False,
"setup_failed: could not create both notes",
depth=0, jump_kind="value", expect="both cards after process death")
record("interaction_multi_persist_vlm", False,
"setup_failed: could not create notes",
depth=0, jump_kind="value", expect="two cards after relaunch", tag="layout")
return
force_stop_and_relaunch()
wait_for_foreground()
settle("tap")
ensure_home()
n = ui()
ok = has_text(n, M_MP_1) and has_text(n, M_MP_2)
record("interaction_multi_persist", ok,
"" if ok else "behavior_wrong: not both notes survived process death",
depth=0, jump_kind="value",
expect=f"cards {M_MP_1!r} and {M_MP_2!r} both present after relaunch")
# VLM: after relaunch, two cards are laid out in the list.
vlm_assert("interaction_multi_persist",
"After the app restarted, are there two note cards displayed in the "
"list area (a grid or stacked column of two rounded cards)?",
depth=0, jump_kind="value", tag="layout")
# ══════════════════════════════════════════════════════════════════════════════
# 18. Pin via More menu -> the note is grouped under a PINNED header (data effect)
# EasyNotes renders NO pin badge on the card; pinning instead splits Home into
# `PINNED` and `OTHERS` sections and moves the note under PINNED. That grouping is
# a dump-readable DATA consequence, so this is a rule (value) test, not a VLM one.
# ══════════════════════════════════════════════════════════════════════════════
M_PIN = "kitI_PinNote"
M_PIN_OTHER = "kitI_PinOther"
def _y_of(nodes, marker):
n = find_card(nodes, marker)
return n.get("_bounds", (0, 0, 10 ** 9, 10 ** 9))[1] if n else None
@and_test(expects=("interaction_pin_note",))
def test_pin_note():
clear_data()
restart_app()
wait_for_foreground()
create_note(M_PIN, "pinbody")
create_note(M_PIN_OTHER, "otherbody")
ensure_home()
n = ui()
if not (has_text(n, M_PIN) and has_text(n, M_PIN_OTHER)):
record("interaction_pin_note", False,
"setup_failed: could not create both notes to pin",
depth=2, jump_kind="value",
expect=f"{M_PIN!r} under a PINNED section header")
return
grouped_before = find_node_ci(n, "PINNED") is not None
if not and_reach_preview(M_PIN):
record("interaction_pin_note", False,
"setup_failed: could not open Preview to pin",
depth=2, jump_kind="value",
expect=f"{M_PIN!r} under a PINNED section header")
return
if not and_enter_more_menu():
record("interaction_pin_note", False,
"feature_missing: no More menu / Pinned item",
depth=2, jump_kind="value",
expect=f"{M_PIN!r} under a PINNED section header")
return
n = ui()
pin = find_node(n, text="Pinned") or find_node(n, content_desc="Pin")
if pin is None or not tap_node(pin):
record("interaction_pin_note", False,
"feature_missing: Pinned menu item not tappable",
depth=2, jump_kind="value",
expect=f"{M_PIN!r} under a PINNED section header")
return
settle("tap")
ensure_home()
n = ui()
pinned_hdr = find_node_ci(n, "PINNED")
others_hdr = find_node_ci(n, "OTHERS")
# the pinned note must sit BELOW the PINNED header and ABOVE the OTHERS header;
# the other note must sit BELOW OTHERS -> a real regrouping, not just presence.
grouped = pinned_hdr is not None and others_hdr is not None
y_pin = _y_of(n, M_PIN)
y_other = _y_of(n, M_PIN_OTHER)
ordered = (grouped and y_pin is not None and y_other is not None
and pinned_hdr.get("_bounds", (0, 0, 0, 0))[1] < y_pin < others_hdr.get("_bounds", (0, 0, 0, 0))[1] < y_other)
ok = (not grouped_before) and grouped and ordered
record("interaction_pin_note", ok,
"" if ok else "behavior_wrong: pinned note not grouped under a PINNED header",
depth=2, jump_kind="value",
expect=f"'PINNED' header with {M_PIN!r} above the 'OTHERS' header holding {M_PIN_OTHER!r}")
# ══════════════════════════════════════════════════════════════════════════════
# 19. Editor surface VLM: the markdown toolbar row renders its icons
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_markdown_toolbar_vlm",))
def test_markdown_toolbar_vlm():
clear_data()
restart_app()
wait_for_foreground()
if not and_enter_editor():
record("interaction_markdown_toolbar_vlm", False,
"setup_failed: could not open the editor",
depth=1, jump_kind="content", expect="formatting icon row", tag="position")
return
ets = sorted_edittexts(ui())
if ets:
type_text(ets[0], "TB")
toolbar = focus_description_toolbar()
if toolbar is None:
record("interaction_markdown_toolbar_vlm", False,
"feature_missing: markdown toolbar did not appear",
depth=1, jump_kind="content", expect="formatting icon row", tag="position")
return
# VLM: a horizontal row of formatting icons sits just above the keyboard.
vlm_assert("interaction_markdown_toolbar",
"Is there a horizontal row of formatting icons (such as a bullet-"
"list icon, a checkbox icon and an image icon) positioned above the "
"on-screen keyboard, below the note text area?",
depth=1, jump_kind="content", tag="position")
TESTS = [
test_create_note,
test_create_body_preview,
test_two_notes,
test_edit_body,
test_delete_via_menu,
test_delete_leaves_others,
test_note_persists,
test_edit_persists,
test_longpress_selection,
test_selection_count,
test_select_all,
test_selection_delete,
test_markdown_bullet,
test_markdown_checkbox,
test_empty_note_discarded,
test_three_edit_middle,
test_multi_persist,
test_pin_note,
test_markdown_toolbar_vlm,
]
if __name__ == "__main__":
run_suite(TESTS, "interaction")