"""MENU lane — DB Browser for SQLite (Qt5).
MENU == NAVIGATION. A top-level menu OPENS (its child items become SHOWING) and a
SAFE item triggers an app-authored EFFECT: a downstream DIALOG with a specific
identity, or a menu-open that reveals its items. The verdict is always the effect,
proven with rb_showing(before) -> trigger -> rb_showing(after) + rb_reach (the
target surface APPEARED). A GTK/Qt menu bar is static in the tree, so SHOWING alone
never counts — every test pairs the open with the app-authored consequence.
This lane does NOT own CHECKED/radio flips (state lane). It proves reachability +
downstream effect only.
Verified live on the running reference:
* Help > About -> dialog "About DB Browser for SQLite" (version text).
* Edit > Preferences... -> dialog "Preferences".
* Edit > Create Table... -> dialog "Edit table definition".
* Edit > Create Index... -> dialog "Edit Index Schema".
* Tools menu open -> reveals Integrity Check / Compact Database / Optimize
(items gain SHOWING; a dead static menu bar fails this).
Every dialog-opener uses open_modal() (async xdotool click) so the app's nested
modal loop never hangs the module; every menu-opener uses click_node() (real
click). Each test opens its OWN entry point and dismisses with Escape, so the
suite is order-independent.
"""
import time
import pytest, pytest_check as check
import rb_atspi
from rb_atspi import rb_showing, rb_reach
DB = "/workspace/output/fixtures/sample.db"
# --------------------------------------------------------------------------- #
# Module fixture — ensure sample.db is open (cold baseline starts with no DB).
# --------------------------------------------------------------------------- #
@pytest.fixture(scope="module", autouse=True)
def _load_db(app):
rb_atspi.focus_app_window(app)
frame = rb_atspi.get_main_frame(app)
for _ in range(4):
rb_atspi.press_escape(); time.sleep(0.15)
if "sample.db" not in (frame.get_name() or ""):
fm = rb_atspi.find_first(frame, role="menu item", name="File")
if fm:
rb_atspi.click_node(fm); time.sleep(0.4)
op = rb_atspi.find_first(frame, role="menu item", name="Open Database...")
if op:
rb_atspi.open_modal(op); time.sleep(1.2)
rb_atspi.type_text(DB); time.sleep(0.4)
rb_atspi.key("Return"); time.sleep(1.5)
yield
# --------------------------------------------------------------------------- #
# Helpers (all verified live on the running reference).
# --------------------------------------------------------------------------- #
def _reset(app):
"""Re-derive the frame and clear any stray popup/menu/dialog at test start,
so each test is independent of whatever a prior test left on screen."""
frame = rb_atspi.get_main_frame(app)
for _ in range(3):
rb_atspi.press_escape(); time.sleep(0.15)
return frame
def _open_menu(frame, menu_name, settle=0.55):
"""Open a top-level menu with a REAL click (never do_action — a menu-open can
enter a grab/nested loop). Returns the menu-item node."""
m = rb_atspi.find_first(frame, role="menu item", name=menu_name)
assert m is not None, f"top-level menu {menu_name!r} not found"
rb_atspi.click_node(m)
time.sleep(settle)
return m
def _open_dialog_via_menu(frame, rb, menu_name, item_name, target, slug):
"""DRY the dialog tests: open