fix: prewarm and reuse WebEngine reader
This commit is contained in:
+31
-1
@@ -8,7 +8,7 @@ import time
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from PySide6.QtCore import QSettings, QThreadPool
|
||||
from PySide6.QtCore import QSettings, QThreadPool, Signal
|
||||
from PySide6.QtWidgets import QApplication, QTextBrowser
|
||||
|
||||
from mdhelper import main_window, startup_scan
|
||||
@@ -45,6 +45,36 @@ def test_welcome_does_not_create_browser_process(gui, tmp_path, monkeypatch):
|
||||
window.close()
|
||||
|
||||
|
||||
def test_prewarmed_reader_replaces_welcome_without_empty_tab(gui, tmp_path, monkeypatch):
|
||||
class StandbyReader(QTextBrowser):
|
||||
loadFinished = Signal(bool)
|
||||
|
||||
def setHtml(self, html, _base_url=None):
|
||||
super().setHtml(html)
|
||||
self.loadFinished.emit(True)
|
||||
|
||||
window = main_window.MainWindow(None, app_root=tmp_path)
|
||||
standby = StandbyReader()
|
||||
standby.navigation_history = None
|
||||
tab_counts: list[int] = []
|
||||
try:
|
||||
monkeypatch.setattr(window, "_create_reader_view", lambda: standby)
|
||||
window._prewarm_reader_view()
|
||||
assert window._standby_reader_view is standby
|
||||
|
||||
window.tabs.currentChanged.connect(lambda _index: tab_counts.append(window.tabs.count()))
|
||||
target = window._prepare_target_tab(False, "Guide")
|
||||
|
||||
assert target is standby
|
||||
assert window._standby_reader_view is None
|
||||
assert window._welcome_tab_index() == -1
|
||||
assert window.tabs.count() == 1
|
||||
assert window.tabs.currentWidget() is standby
|
||||
assert all(count > 0 for count in tab_counts)
|
||||
finally:
|
||||
window.close()
|
||||
|
||||
|
||||
def test_directory_scan_does_not_block_first_window(gui, tmp_path, monkeypatch):
|
||||
(tmp_path / "guide.md").write_text("# Guide\n", encoding="utf-8")
|
||||
entered, release = threading.Event(), threading.Event()
|
||||
|
||||
Reference in New Issue
Block a user