246 lines
7.9 KiB
Python
246 lines
7.9 KiB
Python
"""独立窗口全屏查看:切换、快捷键与退出后的几何 / 停靠状态恢复(offscreen,全程离线)。"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
|
|
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
|
|
|
|
import pytest
|
|
from PySide6.QtCore import QRect
|
|
from PySide6.QtTest import QTest
|
|
from PySide6.QtWidgets import QApplication, QDialog, QLabel, QVBoxLayout
|
|
|
|
from doctor_workstation.core.permissions import PermissionSet
|
|
from doctor_workstation.services.demo_repository import DEMO_PERMISSIONS, DemoDoctorRepository
|
|
from doctor_workstation.ui.fullscreen import (
|
|
FULLSCREEN_ENTER_TEXT,
|
|
FULLSCREEN_EXIT_TEXT,
|
|
install_window_fullscreen,
|
|
window_fullscreen_controller,
|
|
)
|
|
from doctor_workstation.ui.shell_spatial import SpatialShellWindow
|
|
from doctor_workstation.ui.theme import apply_theme
|
|
|
|
|
|
def _settle(app: QApplication, rounds: int = 8) -> None:
|
|
for _ in range(rounds):
|
|
app.processEvents()
|
|
QTest.qWait(8)
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
def application() -> QApplication:
|
|
app = QApplication.instance() or QApplication([])
|
|
apply_theme(app)
|
|
return app
|
|
|
|
|
|
def _plain_dialog() -> QDialog:
|
|
dialog = QDialog()
|
|
dialog.setProperty("doctorSkipOpenGeometry", True)
|
|
layout = QVBoxLayout(dialog)
|
|
layout.addWidget(QLabel("诊断与药方 · AI 分析报告", dialog))
|
|
return dialog
|
|
|
|
|
|
def test_controller_toggles_fullscreen_and_restores_geometry(application: QApplication) -> None:
|
|
dialog = _plain_dialog()
|
|
dialog.show()
|
|
dialog.setGeometry(120, 90, 640, 480)
|
|
_settle(application)
|
|
original = QRect(dialog.geometry())
|
|
controller = install_window_fullscreen(dialog)
|
|
assert install_window_fullscreen(dialog) is controller
|
|
states: list[bool] = []
|
|
controller.toggled.connect(states.append)
|
|
try:
|
|
# 非全屏时 Esc 不被拦截,保留对话框原有的取消语义。
|
|
assert controller.toggle_shortcut.isEnabled()
|
|
assert not controller.escape_shortcut.isEnabled()
|
|
|
|
controller.toggle_shortcut.activated.emit() # 模拟 F11
|
|
_settle(application)
|
|
assert dialog.isFullScreen()
|
|
assert controller.escape_shortcut.isEnabled()
|
|
assert controller.saved_geometry == original
|
|
|
|
controller.escape_shortcut.activated.emit() # 模拟 Esc
|
|
_settle(application)
|
|
assert not dialog.isFullScreen()
|
|
assert dialog.isVisible()
|
|
assert dialog.geometry() == original
|
|
assert not controller.escape_shortcut.isEnabled()
|
|
assert states == [True, False]
|
|
|
|
# F11 再按两次:进入后再退出,同样回到原位。
|
|
controller.toggle()
|
|
_settle(application)
|
|
controller.toggle()
|
|
_settle(application)
|
|
assert not dialog.isFullScreen()
|
|
assert dialog.geometry() == original
|
|
finally:
|
|
dialog.close()
|
|
dialog.deleteLater()
|
|
|
|
|
|
def test_controller_restores_maximized_state(application: QApplication) -> None:
|
|
dialog = _plain_dialog()
|
|
dialog.setGeometry(100, 100, 600, 420)
|
|
dialog.showMaximized()
|
|
_settle(application)
|
|
controller = install_window_fullscreen(dialog)
|
|
try:
|
|
controller.enter()
|
|
_settle(application)
|
|
assert dialog.isFullScreen()
|
|
controller.exit()
|
|
_settle(application)
|
|
assert not dialog.isFullScreen()
|
|
assert dialog.isMaximized()
|
|
finally:
|
|
dialog.close()
|
|
dialog.deleteLater()
|
|
|
|
|
|
def test_top_level_business_dialog_gets_fullscreen_on_show(application: QApplication) -> None:
|
|
dialog = _plain_dialog()
|
|
dialog.resize(700, 500)
|
|
try:
|
|
dialog.show()
|
|
_settle(application)
|
|
controller = window_fullscreen_controller(dialog)
|
|
assert controller is not None
|
|
controller.enter()
|
|
_settle(application)
|
|
assert dialog.isFullScreen()
|
|
controller.exit()
|
|
_settle(application)
|
|
assert not dialog.isFullScreen()
|
|
finally:
|
|
dialog.close()
|
|
dialog.deleteLater()
|
|
|
|
|
|
@pytest.fixture()
|
|
def shell(application: QApplication):
|
|
repo = DemoDoctorRepository()
|
|
session = repo.login(repo.DEMO_ACCOUNT, repo.DEMO_PASSWORD)
|
|
window = SpatialShellWindow(
|
|
repo,
|
|
{"session": session, "user": session.user, "demo_mode": True},
|
|
PermissionSet(DEMO_PERMISSIONS),
|
|
)
|
|
window.resize(1520, 920)
|
|
window.show()
|
|
_settle(application, 24)
|
|
try:
|
|
yield window
|
|
finally:
|
|
window.wing_manager.close_all()
|
|
window.close()
|
|
window.deleteLater()
|
|
_settle(application, 4)
|
|
|
|
|
|
def test_docked_wing_fullscreen_and_restores_dock(shell, application: QApplication) -> None:
|
|
shell._open_active_patient_ai_report()
|
|
_settle(application)
|
|
wm = shell.wing_manager
|
|
header = wm.card.header
|
|
assert wm.is_open and wm.mode == "docked" and wm.side == "right"
|
|
assert header.fullscreen_btn.text() == FULLSCREEN_ENTER_TEXT
|
|
shell_geom = QRect(shell.geometry())
|
|
|
|
header.fullscreen_btn.click()
|
|
_settle(application)
|
|
assert wm.is_fullscreen
|
|
assert wm.sidecar is not None and wm.sidecar.isFullScreen()
|
|
assert wm.card.window() is wm.sidecar
|
|
assert header.fullscreen_btn.text() == FULLSCREEN_EXIT_TEXT
|
|
assert header.fullscreen_btn.isChecked()
|
|
# 全屏下卡片铺满整个窗口,内容不再被挤压。
|
|
assert wm.card.width() >= wm.sidecar.width() - 2
|
|
assert not shell.right_wing_dock.isVisible()
|
|
|
|
# 全屏时 Esc 只退出全屏,不关闭视窗。
|
|
wm._on_escape()
|
|
_settle(application)
|
|
assert wm.is_open
|
|
assert not wm.is_fullscreen
|
|
assert wm.mode == "docked" and wm.side == "right"
|
|
assert shell.right_wing_dock.isVisible()
|
|
assert wm.card.window() is shell
|
|
assert not wm.sidecar.isVisible()
|
|
assert header.fullscreen_btn.text() == FULLSCREEN_ENTER_TEXT
|
|
assert not header.fullscreen_btn.isChecked()
|
|
assert shell.geometry() == shell_geom
|
|
|
|
# 非全屏时 Esc 仍然关闭视窗。
|
|
wm._on_escape()
|
|
_settle(application)
|
|
assert not wm.is_open
|
|
|
|
|
|
def test_left_sidecar_fullscreen_restores_side_mode_and_geometry(
|
|
shell, application: QApplication
|
|
) -> None:
|
|
shell._open_active_patient_ai_report()
|
|
_settle(application)
|
|
wm = shell.wing_manager
|
|
wm.set_side("left")
|
|
wm.set_mode("sidecar")
|
|
_settle(application)
|
|
sidecar = wm.sidecar
|
|
assert sidecar is not None and sidecar.isVisible()
|
|
sidecar.setGeometry(sidecar.x(), sidecar.y(), 460, 700)
|
|
_settle(application)
|
|
before = QRect(sidecar.geometry())
|
|
|
|
wm.toggle_fullscreen() # F11 与按钮共用同一入口
|
|
_settle(application)
|
|
assert sidecar.isFullScreen()
|
|
assert wm.card.header.left_btn.isChecked()
|
|
|
|
wm.toggle_fullscreen()
|
|
_settle(application)
|
|
assert not sidecar.isFullScreen()
|
|
assert wm.mode == "sidecar" and wm.side == "left"
|
|
assert sidecar.geometry() == before
|
|
assert wm.card.header.detach_btn.text() == "↙ 嵌回主窗"
|
|
|
|
|
|
def test_switching_side_while_fullscreen_exits_first(shell, application: QApplication) -> None:
|
|
shell._open_active_patient_ai_report()
|
|
_settle(application)
|
|
wm = shell.wing_manager
|
|
wm.enter_fullscreen()
|
|
_settle(application)
|
|
assert wm.is_fullscreen
|
|
|
|
wm.card.header.left_btn.click()
|
|
_settle(application)
|
|
assert not wm.is_fullscreen
|
|
assert wm.mode == "docked" and wm.side == "left"
|
|
assert shell.left_wing_dock.isVisible()
|
|
assert not wm.sidecar.isVisible()
|
|
|
|
|
|
def test_close_wing_while_fullscreen_restores_placement(shell, application: QApplication) -> None:
|
|
shell._open_active_patient_ai_report()
|
|
_settle(application)
|
|
wm = shell.wing_manager
|
|
wm.enter_fullscreen()
|
|
_settle(application)
|
|
wm.close_wing()
|
|
_settle(application)
|
|
assert not wm.is_fullscreen
|
|
assert not wm.sidecar.isVisible()
|
|
assert wm.mode == "docked"
|
|
|
|
shell._open_active_patient_ai_report()
|
|
_settle(application)
|
|
assert wm.mode == "docked" and shell.right_wing_dock.isVisible()
|
|
assert wm.card.header.fullscreen_btn.text() == FULLSCREEN_ENTER_TEXT
|