更新::
This commit is contained in:
@@ -7,7 +7,8 @@ os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
|
||||
|
||||
import pytest
|
||||
from PySide6.QtCore import QSize, Qt
|
||||
from PySide6.QtWidgets import QApplication, QDialog, QFrame, QToolButton, QWidget
|
||||
from PySide6.QtTest import QTest
|
||||
from PySide6.QtWidgets import QApplication, QDialog, QFrame, QLineEdit, QToolButton, QWidget
|
||||
|
||||
from doctor_workstation.ui import shell as shell_module
|
||||
from doctor_workstation.ui.shell import NavigationItem, ShellWindow
|
||||
@@ -35,10 +36,15 @@ class _ShellPageDouble(QWidget):
|
||||
self.show_count = 0
|
||||
self.ai_context_available = False
|
||||
self.ai_open_count = 0
|
||||
self.search_queries: list[str] = []
|
||||
|
||||
def refresh(self) -> None:
|
||||
self.refresh_count += 1
|
||||
|
||||
def search_patient(self, query: str) -> None:
|
||||
self.search_queries.append(query)
|
||||
self.refresh()
|
||||
|
||||
def open_selected_ai_consult(self) -> bool:
|
||||
self.ai_open_count += 1
|
||||
return self.ai_context_available
|
||||
@@ -243,13 +249,75 @@ def test_registered_pages_are_not_top_level_windows(shell_window: ShellWindow) -
|
||||
assert not page.isWindow()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("origin,trigger,target", [
|
||||
("consultations", "enter", "consultations"),
|
||||
("appointments", "button", "consultations"),
|
||||
("prescriptions", "enter", "consultations"),
|
||||
("prescription_library", "button", "consultations"),
|
||||
("patients", "enter", "patients"),
|
||||
("legacy_reference", "action", "consultations"),
|
||||
])
|
||||
def test_topbar_search_routes_to_patient_page_once(
|
||||
shell_window: ShellWindow, application: QApplication, origin: str, trigger: str, target: str,
|
||||
) -> None:
|
||||
assert shell_window.navigate(origin)
|
||||
application.processEvents()
|
||||
unrelated = QLineEdit(shell_window.pages[origin])
|
||||
unrelated.setPlaceholderText("患者姓名")
|
||||
unrelated.setText("原页面条件")
|
||||
page = shell_window.pages[target]
|
||||
before = page.refresh_count
|
||||
shell_window.global_search.setText(" 13800138000 ")
|
||||
if trigger == "enter":
|
||||
QTest.keyClick(shell_window.global_search, Qt.Key.Key_Return)
|
||||
elif trigger == "button":
|
||||
QTest.mouseClick(shell_window.search_mark, Qt.MouseButton.LeftButton)
|
||||
else:
|
||||
shell_window._global_search_icon_action.trigger()
|
||||
application.processEvents()
|
||||
assert shell_window.stack.currentWidget() is page
|
||||
assert page.search_queries == ["13800138000"]
|
||||
assert page.refresh_count == before + 1
|
||||
assert unrelated.text() == "原页面条件"
|
||||
|
||||
|
||||
def test_topbar_search_uses_available_patient_page_and_empty_query_clears(
|
||||
shell_window: ShellWindow, application: QApplication,
|
||||
) -> None:
|
||||
shell_window.pages.pop("consultations")
|
||||
shell_window.global_search.setText("林患者")
|
||||
QTest.keyClick(shell_window.global_search, Qt.Key.Key_Return)
|
||||
application.processEvents()
|
||||
patient_page = shell_window.pages["patients"]
|
||||
assert shell_window.stack.currentWidget() is patient_page
|
||||
shell_window.global_search.clear()
|
||||
QTest.keyClick(shell_window.global_search, Qt.Key.Key_Return)
|
||||
assert patient_page.search_queries == ["林患者", ""]
|
||||
|
||||
|
||||
def test_topbar_search_without_patient_page_does_not_query_unrelated_pages(
|
||||
shell_window: ShellWindow, monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
shell_window.pages.pop("consultations")
|
||||
shell_window.pages.pop("patients")
|
||||
current = shell_window.stack.currentWidget()
|
||||
before = current.refresh_count
|
||||
messages = []
|
||||
monkeypatch.setattr(shell_module, "show_toast", lambda *args: messages.append(args))
|
||||
shell_window.global_search.setText("林患者")
|
||||
QTest.keyClick(shell_window.global_search, Qt.Key.Key_Return)
|
||||
assert current.refresh_count == before
|
||||
assert shell_window.stack.currentWidget() is current
|
||||
assert "没有可用的患者搜索页面" in messages[0][1]
|
||||
|
||||
|
||||
def test_reference_shell_has_integrated_search_ai_card_and_window_controls(
|
||||
shell_window: ShellWindow,
|
||||
) -> None:
|
||||
assert shell_window.navigate("legacy_reference")
|
||||
assert shell_window.windowFlags() & Qt.WindowType.FramelessWindowHint
|
||||
assert (
|
||||
shell_window.global_search.placeholderText() == "搜索患者姓名、手机号、病历号"
|
||||
shell_window.global_search.placeholderText() == "搜索患者姓名、手机号..."
|
||||
)
|
||||
assert shell_window.assistant_card.isVisible()
|
||||
assert shell_window.assistant_button.text() == "开始对话"
|
||||
|
||||
Reference in New Issue
Block a user