|
47 | 47 | overview_will_render_bottom, |
48 | 48 | ) |
49 | 49 | from aqt.importing import AnkiPackageImporter |
50 | | -from aqt.qt import QAction, QDialog, QEvent, QLabel, Qt, QUrl, QWebEnginePage, QWidget, sip |
| 50 | +from aqt.qt import QAction, QDialog, QEvent, QLabel, Qt, QToolButton, QUrl, QWebEnginePage, QWidget, sip |
51 | 51 | from aqt.theme import theme_manager |
52 | 52 | from aqt.webview import AnkiWebView |
53 | 53 | from pytest import fixture |
@@ -12972,6 +12972,46 @@ def test_init_raises_when_anking_deck_not_installed( |
12972 | 12972 | with pytest.raises(AssertionError): |
12973 | 12973 | StepDeckTutorial() |
12974 | 12974 |
|
| 12975 | + def test_get_smart_search_button_target_returns_none_when_button_missing( |
| 12976 | + self, |
| 12977 | + anki_session_with_addon_data: AnkiSession, |
| 12978 | + ): |
| 12979 | + """Regression: tutorial target helper should handle missing Smart Search button.""" |
| 12980 | + from ankihub.gui.tutorial import StepDeckTutorial |
| 12981 | + |
| 12982 | + with anki_session_with_addon_data.profile_loaded(): |
| 12983 | + tutorial = StepDeckTutorial.__new__(StepDeckTutorial) |
| 12984 | + browser = Mock(sidebar=Mock()) |
| 12985 | + browser.findChild.return_value = None |
| 12986 | + tutorial._browser = browser |
| 12987 | + |
| 12988 | + assert tutorial._get_smart_search_button_target() is None |
| 12989 | + |
| 12990 | + def test_get_smart_search_button_target_uses_live_browser( |
| 12991 | + self, |
| 12992 | + anki_session_with_addon_data: AnkiSession, |
| 12993 | + mocker: MockerFixture, |
| 12994 | + ): |
| 12995 | + """Regression: target helper should resolve from the live Browser reference.""" |
| 12996 | + from ankihub.gui import tutorial as tutorial_module |
| 12997 | + from ankihub.gui.overlay_dialog import OverlayTarget |
| 12998 | + from ankihub.gui.tutorial import StepDeckTutorial |
| 12999 | + |
| 13000 | + with anki_session_with_addon_data.profile_loaded(): |
| 13001 | + tutorial = StepDeckTutorial.__new__(StepDeckTutorial) |
| 13002 | + live_browser = Mock(sidebar=Mock()) |
| 13003 | + smart_search_button = Mock(spec=QToolButton) |
| 13004 | + live_browser.findChild.return_value = smart_search_button |
| 13005 | + tutorial._browser = None |
| 13006 | + mocker.patch.object(tutorial, "_get_live_browser", return_value=live_browser) |
| 13007 | + mocker.patch.object(tutorial_module.sip, "isdeleted", return_value=False) |
| 13008 | + |
| 13009 | + target = tutorial._get_smart_search_button_target() |
| 13010 | + |
| 13011 | + assert isinstance(target, OverlayTarget) |
| 13012 | + assert target.parent is live_browser.sidebar |
| 13013 | + assert target.element is smart_search_button |
| 13014 | + |
12975 | 13015 | def test_hook_browser_startup_does_not_crash_when_browser_missing( |
12976 | 13016 | self, |
12977 | 13017 | anki_session_with_addon_data: AnkiSession, |
|
0 commit comments