更新bug
This commit is contained in:
@@ -6,11 +6,17 @@ 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 PySide6.QtCore import QSize, Qt
|
||||
from PySide6.QtWidgets import QApplication, QDialog, QFrame, QToolButton, QWidget
|
||||
|
||||
from doctor_workstation.ui import shell as shell_module
|
||||
from doctor_workstation.ui.shell import NavigationItem, ShellWindow
|
||||
from doctor_workstation.ui.theme import apply_theme
|
||||
|
||||
|
||||
def _logical_pixel(image: Any, x: int, y: int):
|
||||
device_scale = image.devicePixelRatio()
|
||||
return image.pixelColor(round(x * device_scale), round(y * device_scale))
|
||||
|
||||
|
||||
class _ShellPageDouble(QWidget):
|
||||
@@ -39,7 +45,26 @@ class _ShellPageDouble(QWidget):
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def application() -> QApplication:
|
||||
return QApplication.instance() or QApplication([])
|
||||
app = QApplication.instance() or QApplication([])
|
||||
apply_theme(app)
|
||||
return app
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("available_size", "expected_size"),
|
||||
[
|
||||
(QSize(1920, 1080), QSize(1710, 920)),
|
||||
(QSize(1486, 1000), QSize(1486, 920)),
|
||||
(QSize(1600, 800), QSize(1600, 800)),
|
||||
(QSize(800, 600), QSize(1024, 640)),
|
||||
(None, QSize(1710, 920)),
|
||||
],
|
||||
)
|
||||
def test_shell_initial_size_is_bounded_by_logical_available_geometry(
|
||||
available_size: QSize | None,
|
||||
expected_size: QSize,
|
||||
) -> None:
|
||||
assert shell_module._bounded_initial_window_size(available_size) == expected_size
|
||||
|
||||
|
||||
def test_patients_navigation_keeps_the_product_menu_title() -> None:
|
||||
@@ -145,14 +170,60 @@ def test_shell_matches_reference_geometry_at_both_acceptance_sizes(
|
||||
assert shell_window.stack.geometry().bottom() < shell_window.workspace.height()
|
||||
|
||||
image = shell_window.grab().toImage()
|
||||
assert image.pixelColor(20, 300).name().lower() in {
|
||||
assert _logical_pixel(image, 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"
|
||||
assert _logical_pixel(image, 610, 20).name().lower() == "#ffffff"
|
||||
assert _logical_pixel(image, 220, 90).name().lower() == "#fcfdfe"
|
||||
|
||||
|
||||
def test_topbar_search_actions_and_navigation_controls_stay_aligned(
|
||||
application: QApplication,
|
||||
shell_window: ShellWindow,
|
||||
) -> None:
|
||||
for width, height in ((1024, 640), (1366, 768)):
|
||||
shell_window.resize(width, height)
|
||||
application.processEvents()
|
||||
|
||||
search_host = shell_window.topbar.findChild(QFrame, "ShellGlobalSearch")
|
||||
shortcut_hint = search_host.findChild(QWidget, "ShellShortcutHint")
|
||||
assert search_host.size().toTuple() == (265, 36)
|
||||
assert shell_window.fold_button.size().toTuple() == (38, 38)
|
||||
assert shortcut_hint.size() == shortcut_hint.sizeHint()
|
||||
assert (
|
||||
abs(search_host.geometry().center().y() - shell_window.fold_button.geometry().center().y())
|
||||
<= 1
|
||||
)
|
||||
assert (
|
||||
abs(
|
||||
shortcut_hint.mapTo(search_host, shortcut_hint.rect().center()).y()
|
||||
- search_host.rect().center().y()
|
||||
)
|
||||
<= 1
|
||||
)
|
||||
|
||||
shell_window.global_search.setText("患者")
|
||||
application.processEvents()
|
||||
action_buttons = shell_window.global_search.findChildren(QToolButton)
|
||||
assert len(action_buttons) == 2
|
||||
for button in action_buttons:
|
||||
assert button.size().toTuple() == (22, 18)
|
||||
assert shell_window.global_search.rect().contains(button.geometry())
|
||||
assert (
|
||||
abs(
|
||||
button.geometry().center().y()
|
||||
- shell_window.global_search.rect().center().y()
|
||||
)
|
||||
<= 1
|
||||
)
|
||||
|
||||
clear_button = max(action_buttons, key=lambda button: button.x())
|
||||
clear_right = clear_button.mapTo(search_host, clear_button.rect().topRight()).x()
|
||||
assert clear_right < shortcut_hint.x()
|
||||
shell_window.global_search.clear()
|
||||
|
||||
|
||||
def test_registered_pages_are_not_top_level_windows(shell_window: ShellWindow) -> None:
|
||||
@@ -170,7 +241,11 @@ def test_reference_shell_has_integrated_search_ai_card_and_window_controls(
|
||||
)
|
||||
assert shell_window.assistant_card.isVisible()
|
||||
assert shell_window.assistant_button.text() == "开始对话"
|
||||
assert "GPT-4o 医疗版" in shell_window.model_label.text()
|
||||
assert shell_window.upload_settings_button.text().strip().startswith("设置")
|
||||
assert (
|
||||
shell_window.upload_settings_button.accessibleName() == "本机录音上传设置"
|
||||
)
|
||||
assert shell_window.model_label is shell_window.upload_settings_button
|
||||
assert shell_window.minimize_button.text() == ""
|
||||
assert shell_window.close_button.text() == ""
|
||||
|
||||
@@ -180,6 +255,42 @@ def test_reference_shell_has_integrated_search_ai_card_and_window_controls(
|
||||
assert "在线" in shell_window.assistant_status.text()
|
||||
|
||||
|
||||
def test_shell_settings_opens_global_local_audio_upload_manager(
|
||||
application: QApplication,
|
||||
shell_window: ShellWindow,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
captured: dict[str, Any] = {}
|
||||
|
||||
def dialog_factory(
|
||||
repository: Any,
|
||||
diagnosis_id: int | None,
|
||||
parent: QWidget,
|
||||
) -> QDialog:
|
||||
dialog = QDialog(parent)
|
||||
dialog.setObjectName("LocalAudioQueueDialog")
|
||||
captured.update(
|
||||
repository=repository,
|
||||
diagnosis_id=diagnosis_id,
|
||||
parent=parent,
|
||||
dialog=dialog,
|
||||
)
|
||||
return dialog
|
||||
|
||||
monkeypatch.setattr(shell_module, "LocalAudioQueueDialog", dialog_factory)
|
||||
shell_window.upload_settings_button.click()
|
||||
application.processEvents()
|
||||
|
||||
assert captured["repository"] is shell_window.repository
|
||||
assert captured["diagnosis_id"] is None
|
||||
assert captured["parent"] is shell_window
|
||||
assert captured["dialog"].isVisible()
|
||||
|
||||
captured["dialog"].reject()
|
||||
application.processEvents()
|
||||
assert shell_window._local_audio_settings_dialog is None
|
||||
|
||||
|
||||
def test_every_visible_page_navigates_and_visited_tabs_track_active_page(
|
||||
shell_window: ShellWindow,
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user