This commit is contained in:
Your Name
2026-08-14 14:37:30 +08:00
parent 21790e35f4
commit 18c15d1262
117 changed files with 28157 additions and 8080 deletions
+73 -18
View File
@@ -6,6 +6,7 @@ from typing import Any
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
import pytest
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QApplication, QWidget
from doctor_workstation.ui import shell as shell_module
@@ -35,6 +36,22 @@ def application() -> QApplication:
return QApplication.instance() or QApplication([])
def test_patients_navigation_ignores_the_legacy_server_menu_title() -> None:
resolved = shell_module._resolve_navigation(
[
{
"name": "我的患者",
"component": "first_visit/my_patients",
"perms": "firstvisit.myPatient/lists",
}
],
{"firstvisit.myPatient/lists"},
demo_mode=False,
)
assert [(item.key, title) for item, title in resolved] == [("patients", "接诊台")]
@pytest.fixture
def shell_window(
application: QApplication,
@@ -45,16 +62,23 @@ def shell_window(
for key, title, glyph, permission in (
("reception", "接诊台", "", "doctor.appointment/lists"),
("appointments", "挂号列表", "", "doctor.appointment/lists"),
("prescription_library", "我的处方库", "", "tcm.prescriptionLibrary/lists"),
(
"prescription_library",
"我的处方库",
"",
"tcm.prescriptionLibrary/lists",
),
("prescriptions", "已开处方", "", "tcm.prescription/lists"),
("patients", "我的患者", "", "firstvisit.myPatient/lists"),
("patients", "接诊台", "", "firstvisit.myPatient/lists"),
("consultations", "问诊列表", "", "tcm.diagnosis/lists"),
)
]
monkeypatch.setattr(
shell_module,
"_resolve_navigation",
lambda _menu, _permissions, *, demo_mode: [(item, item.title) for item in navigation],
lambda _menu, _permissions, *, demo_mode: [
(item, item.title) for item in navigation
],
)
window = ShellWindow(
object(),
@@ -71,7 +95,7 @@ def shell_window(
application.processEvents()
def test_shell_matches_admin_geometry_at_both_acceptance_sizes(
def test_shell_matches_reference_geometry_at_both_acceptance_sizes(
application: QApplication,
shell_window: ShellWindow,
) -> None:
@@ -79,19 +103,24 @@ def test_shell_matches_admin_geometry_at_both_acceptance_sizes(
shell_window.resize(width, height)
application.processEvents()
assert shell_window.sidebar.width() == 208
assert shell_window.topbar.height() == 58
assert shell_window.tabs_host.height() == 42
assert shell_window.workspace.width() == width - 208
assert shell_window.stack.width() == width - 208
assert shell_window.stack.height() == height - 100
assert shell_window.sidebar.width() == 199
assert shell_window.topbar.height() == 62
assert shell_window.tabs_host.height() == 0
assert shell_window.workspace.width() == width - 26 - 199
assert shell_window.stack.width() == width - 26 - 199
assert shell_window.stack.height() == height - 26 - 62
assert shell_window.stack.geometry().right() < shell_window.workspace.width()
assert shell_window.stack.geometry().bottom() < shell_window.workspace.height()
image = shell_window.grab().toImage()
assert image.pixelColor(20, 300).name().lower() == "#ffffff"
assert image.pixelColor(500, 10).name().lower() == "#ffffff"
assert image.pixelColor(220, 110).name().lower() == "#f5f7fb"
assert image.pixelColor(20, 300).name().lower() in {
"#f2f5fd",
"#f3f6fd",
"#f2f6fe",
"#f3f6fe",
}
assert image.pixelColor(610, 20).name().lower() == "#ffffff"
assert image.pixelColor(220, 90).name().lower() == "#fcfdfe"
def test_registered_pages_are_not_top_level_windows(shell_window: ShellWindow) -> None:
@@ -100,6 +129,25 @@ def test_registered_pages_are_not_top_level_windows(shell_window: ShellWindow) -
assert not page.isWindow()
def test_reference_shell_has_integrated_search_ai_card_and_window_controls(
shell_window: ShellWindow,
) -> None:
assert shell_window.windowFlags() & Qt.WindowType.FramelessWindowHint
assert (
shell_window.global_search.placeholderText() == "搜索患者姓名、手机号、病历号"
)
assert shell_window.assistant_card.isVisible()
assert shell_window.assistant_button.text() == "开始对话"
assert "服务端自动匹配" in shell_window.model_label.text()
assert shell_window.minimize_button.text() == ""
assert shell_window.close_button.text() == ""
shell_window.set_connection_state(False)
assert "离线" in shell_window.assistant_status.text()
shell_window.set_connection_state(True)
assert "在线" in shell_window.assistant_status.text()
def test_every_visible_page_navigates_and_visited_tabs_track_active_page(
shell_window: ShellWindow,
) -> None:
@@ -146,10 +194,15 @@ def test_non_fixed_tabs_close_and_active_close_renavigates(
assert not shell_window.close_tab("reception")
assert shell_window.close_tab("patients")
assert "patients" not in shell_window.visited_tab_keys()
assert shell_window.tab_bar.tabData(shell_window.tab_bar.currentIndex()) == "consultations"
assert (
shell_window.tab_bar.tabData(shell_window.tab_bar.currentIndex())
== "consultations"
)
assert shell_window.close_current_tab()
assert shell_window.tab_bar.tabData(shell_window.tab_bar.currentIndex()) == "reception"
assert (
shell_window.tab_bar.tabData(shell_window.tab_bar.currentIndex()) == "reception"
)
assert shell_window.stack.currentWidget() is shell_window.pages["reception"]
assert shell_window.nav_buttons["reception"].isChecked()
@@ -158,16 +211,18 @@ def test_non_fixed_tabs_close_and_active_close_renavigates(
assert shell_window.stack.currentWidget() is shell_window.pages["reception"]
def test_sidebar_collapse_preserves_active_navigation(shell_window: ShellWindow) -> None:
def test_sidebar_collapse_preserves_active_navigation(
shell_window: ShellWindow,
) -> None:
assert shell_window.navigate("consultations")
shell_window.toggle_sidebar()
assert shell_window.sidebar.width() == 72
assert shell_window.sidebar.width() == 68
assert shell_window.nav_buttons["consultations"].text() == ""
assert shell_window.nav_buttons["consultations"].isChecked()
shell_window.toggle_sidebar()
assert shell_window.sidebar.width() == 208
assert shell_window.sidebar.width() == 195
assert shell_window.nav_buttons["consultations"].text().endswith("问诊列表")
assert shell_window.nav_buttons["consultations"].isChecked()