"""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 , snapshot the SHOWING set with the menu items present, open_modal the (async click -> dialog, no hang), snapshot AFTER, and return (reached, before, after). rb.enter() marks the real crossing (depth 1). NEVER do_action a dialog-opener (nested modal loop hangs the module). Capturing `before` AFTER the menu is open means rb_reach proves the dialog genuinely APPEARED on top of the open-menu state, not that it was pre-present.""" _open_menu(frame, menu_name) item = rb_atspi.find_first(frame, role="menu item", name=item_name) assert item is not None, f"{item_name!r} not found under {menu_name!r}" before = rb_showing(_approot()) rb.enter(slug) rb_atspi.open_modal(item) # poll for the dialog instead of a fixed sleep rb_atspi.wait_for( lambda: any( target.lower() in (d.get_name() or "").lower() and rb_atspi.is_showing(d) for d in rb_atspi.find_all(_approot(), role="dialog") ), timeout=4.0, ) time.sleep(0.4) after = rb_showing(_approot()) reached = rb_reach(before, after, target=target) return reached, before, after _APP = [None] def _approot(): return _APP[0] def _dismiss(): """Close a dialog (twice for nested/child dialogs) and settle.""" rb_atspi.press_escape(); time.sleep(0.3) rb_atspi.press_escape(); time.sleep(0.3) # --------------------------------------------------------------------------- # # 1. Help > About -> "About DB Browser for SQLite" dialog. # --------------------------------------------------------------------------- # @pytest.mark.rb(jump_kind="reach", expect="About dialog titled 'About DB Browser for SQLite' visible") def test_help_about_opens_dialog(app, rb, results_dir): _APP[0] = app frame = _reset(app) reached, before, after = _open_dialog_via_menu( frame, rb, "Help", "About", "About DB Browser for SQLite", "about") check.is_true( reached, "Help > About did not open the 'About DB Browser for SQLite' dialog " f"(newly-shown dialogs: " f"{[k for k in (after - before) if 'dialog|' in k]})", ) # confirm identity + the app-authored version text inside the dialog dlg = rb_atspi.find_first(app, role="dialog", name="About DB Browser for SQLite") check.is_true(dlg is not None and rb_atspi.is_showing(dlg), "About dialog not present/showing") if dlg is not None: blob = " ".join(rb_atspi.get_text(l) for l in rb_atspi.find_all(dlg, role="label")) check.is_true("DB Browser for SQLite" in blob and "Version" in blob, f"About dialog missing app/version text (got: {blob[:80]!r})") rb_atspi.screenshot_assert( "test_help_about_opens_dialog", "The 'About DB Browser for SQLite' dialog is open, showing the app name, " "a version string (Version 3.13...) and a description of the program.", results_dir, ) _dismiss() # --------------------------------------------------------------------------- # # 2. Edit > Preferences... -> "Preferences" settings dialog. # --------------------------------------------------------------------------- # @pytest.mark.rb(jump_kind="reach", expect="Preferences settings dialog visible") def test_edit_preferences_opens_dialog(app, rb, results_dir): _APP[0] = app frame = _reset(app) reached, before, after = _open_dialog_via_menu( frame, rb, "Edit", "Preferences...", "Preferences", "preferences") check.is_true( reached, "Edit > Preferences... did not open the 'Preferences' dialog " f"(newly-shown dialogs: {[k for k in (after - before) if 'dialog|' in k]})", ) dlg = rb_atspi.find_first(app, role="dialog", name="Preferences") check.is_true(dlg is not None and rb_atspi.is_showing(dlg), "Preferences dialog not present/showing") rb_atspi.screenshot_assert( "test_edit_preferences_opens_dialog", "The 'Preferences' settings dialog is open, showing configuration tabs " "(e.g. General / Data Browser / SQL) and their option controls.", results_dir, ) _dismiss() # --------------------------------------------------------------------------- # # 3. Edit > Create Table... -> "Edit table definition" dialog. # --------------------------------------------------------------------------- # @pytest.mark.rb(jump_kind="reach", expect="Edit table definition dialog visible") def test_edit_create_table_opens_dialog(app, rb, results_dir): _APP[0] = app frame = _reset(app) reached, before, after = _open_dialog_via_menu( frame, rb, "Edit", "Create Table...", "Edit table definition", "create_table") check.is_true( reached, "Edit > Create Table... did not open the 'Edit table definition' dialog " f"(newly-shown dialogs: {[k for k in (after - before) if 'dialog|' in k]})", ) dlg = rb_atspi.find_first(app, role="dialog", name="Edit table definition") check.is_true(dlg is not None and rb_atspi.is_showing(dlg), "Edit table definition dialog not present/showing") rb_atspi.screenshot_assert( "test_edit_create_table_opens_dialog", "The 'Edit table definition' dialog is open, showing a table-name text " "field and a column editor grid with Add/Remove field controls.", results_dir, ) _dismiss() # --------------------------------------------------------------------------- # # 4. Edit > Create Index... -> "Edit Index Schema" dialog (observed live title). # --------------------------------------------------------------------------- # @pytest.mark.rb(jump_kind="reach", expect="Edit Index Schema dialog visible") def test_edit_create_index_opens_dialog(app, rb, results_dir): _APP[0] = app frame = _reset(app) reached, before, after = _open_dialog_via_menu( frame, rb, "Edit", "Create Index...", "Edit Index Schema", "create_index") check.is_true( reached, "Edit > Create Index... did not open the 'Edit Index Schema' dialog " f"(newly-shown dialogs: {[k for k in (after - before) if 'dialog|' in k]})", ) dlg = rb_atspi.find_first(app, role="dialog", name="Edit Index Schema") check.is_true(dlg is not None and rb_atspi.is_showing(dlg), "Edit Index Schema dialog not present/showing") rb_atspi.screenshot_assert( "test_edit_create_index_opens_dialog", "The 'Edit Index Schema' dialog is open, showing an index-name field and " "a table selector for choosing the columns to index.", results_dir, ) _dismiss() # --------------------------------------------------------------------------- # # 5. Tools menu OPEN -> its items gain SHOWING (nav-open proof, not a dialog). # A dead shell with a static menu bar but no popup fails this: the items are # NOT showing before the click and MUST become showing after. # --------------------------------------------------------------------------- # @pytest.mark.rb(jump_kind="reach", expect="Tools menu opens revealing Integrity Check / Compact Database / Optimize items") def test_tools_menu_opens_shows_items(app, rb, results_dir): _APP[0] = app frame = _reset(app) expected = ["Integrity Check", "Compact Database...", "Optimize"] # precondition: the items are NOT showing while the menu is closed. for nm in expected: it = rb_atspi.find_first(frame, role="menu item", name=nm) check.is_false(bool(it and rb_atspi.is_showing(it)), f"{nm!r} already showing before Tools opened") before = rb_showing(app) rb.enter("tools_menu") _open_menu(frame, "Tools") after = rb_showing(app) # reach: the discriminating item newly APPEARED in the showing set == menu opened. check.is_true( rb_reach(before, after, target="Integrity Check"), "Tools menu did not reveal 'Integrity Check' (menu never opened)", ) # all three expected items are now showing (the app-authored menu content). for nm in expected: it = rb_atspi.find_first(frame, role="menu item", name=nm) check.is_true(bool(it and rb_atspi.is_showing(it)), f"{nm!r} not showing after Tools opened") rb_atspi.screenshot_assert( "test_tools_menu_opens_shows_items", "The Tools menu is open, listing entries including Compact Database..., " "Integrity Check, Quick Integrity Check, Foreign-Key Check and Optimize.", results_dir, ) rb_atspi.press_escape(); time.sleep(0.25) # teardown proof (not scored): items lose SHOWING once the menu closes. # --------------------------------------------------------------------------- # # 6. View menu OPEN -> its dock-toggle items gain SHOWING (second nav-open, # a DISTINCT rendered menu from Tools). Behavioral open proof; this lane does # NOT assert the CHECKED bit (state lane owns that) — only reachability. # --------------------------------------------------------------------------- # @pytest.mark.rb(jump_kind="reach", expect="View menu opens revealing SQL Log / Plot / DB Schema dock-toggle items") def test_view_menu_opens_shows_items(app, rb, results_dir): _APP[0] = app frame = _reset(app) target = "SQL Log" it0 = rb_atspi.find_first(frame, role="menu item", name=target) check.is_false(bool(it0 and rb_atspi.is_showing(it0)), f"{target!r} already showing before View opened") before = rb_showing(app) rb.enter("view_menu") _open_menu(frame, "View") after = rb_showing(app) check.is_true( rb_reach(before, after, target=target), f"View menu did not reveal {target!r} (menu never opened)", ) shown = [nm for nm in ("SQL Log", "Plot", "DB Schema") if (lambda x: bool(x and rb_atspi.is_showing(x)))( rb_atspi.find_first(frame, role="menu item", name=nm))] check.is_true(len(shown) >= 2, f"expected >=2 View dock-toggle items showing, got {shown}") rb_atspi.screenshot_assert( "test_view_menu_opens_shows_items", "The View menu is open, listing dock-visibility toggle entries including " "SQL Log, Plot and DB Schema.", results_dir, ) rb_atspi.press_escape(); time.sleep(0.25)