更新
This commit is contained in:
@@ -11,7 +11,7 @@ import pytest
|
||||
from PySide6.QtCore import Signal
|
||||
from PySide6.QtWidgets import QApplication, QWidget
|
||||
|
||||
from doctor_workstation.core.errors import ApiBusinessError, ApiProtocolError
|
||||
from doctor_workstation.core.errors import ApiBusinessError, ApiProtocolError, ApiTimeoutError
|
||||
from doctor_workstation.services.repository import RemoteDoctorRepository
|
||||
from doctor_workstation.ui.pages import consultations as module
|
||||
|
||||
@@ -160,8 +160,8 @@ def test_permission_error_stays_scoped_and_retry_recovers(page: Any, monkeypatch
|
||||
widget._load_departments()
|
||||
assert not widget._departments_loaded
|
||||
assert not widget._departments_loading
|
||||
assert widget.department_combo.currentText() == "部门加载失败"
|
||||
assert "无权限" in widget.department_combo.toolTip()
|
||||
assert widget.department_combo.currentText() == "暂无部门筛选权限"
|
||||
assert "联系管理员" in widget.department_combo.toolTip()
|
||||
assert not widget.department_retry_button.isHidden()
|
||||
client.departments = TREE
|
||||
widget.department_retry_button.click()
|
||||
@@ -170,6 +170,19 @@ def test_permission_error_stays_scoped_and_retry_recovers(page: Any, monkeypatch
|
||||
assert all(params == {"apply_data_scope": 1} for _, params in client.calls)
|
||||
|
||||
|
||||
def test_network_failure_remains_retryable_and_is_not_reported_as_permission_denied(page: Any, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
widget, client = page
|
||||
monkeypatch.setattr(module, "run_async", immediate)
|
||||
client.departments = ApiTimeoutError("request timed out")
|
||||
widget._load_departments()
|
||||
assert widget.department_combo.currentText() == "部门加载失败"
|
||||
assert "超时" in widget.department_combo.toolTip()
|
||||
assert "联系管理员" not in widget.department_combo.toolTip()
|
||||
client.departments = TREE
|
||||
widget.department_retry_button.click()
|
||||
assert widget._departments_loaded
|
||||
|
||||
|
||||
def test_inflight_dedup_and_stale_success_or_failure_cannot_override_selection(page: Any, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
widget, _client = page
|
||||
jobs: list[dict[str, Any]] = []
|
||||
|
||||
@@ -7,8 +7,8 @@ from typing import Any
|
||||
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
|
||||
|
||||
import pytest
|
||||
from PySide6.QtCore import Qt
|
||||
from PySide6.QtWidgets import QApplication, QDialog
|
||||
from PySide6.QtCore import QPoint, Qt
|
||||
from PySide6.QtWidgets import QApplication, QDialog, QPushButton
|
||||
|
||||
from doctor_workstation.core import PermissionSet
|
||||
from doctor_workstation.ui import widgets
|
||||
@@ -412,6 +412,114 @@ def _finish_queued(callback: dict[str, Any], result: Any) -> None:
|
||||
callback["on_finished"]()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("owner_width", [1024, 1440])
|
||||
def test_embedded_prescription_history_opens_full_detail_without_changing_draft(
|
||||
application: QApplication, monkeypatch: pytest.MonkeyPatch, owner_width: int,
|
||||
) -> None:
|
||||
listed: list[int] = []
|
||||
fetched: list[int] = []
|
||||
shown: list[int] = []
|
||||
|
||||
class Repository(_DiagnosisRepository):
|
||||
def get_doctor_notes(self, _diagnosis_id: int) -> list[Any]:
|
||||
return []
|
||||
|
||||
def list_prescriptions_by_diagnosis(self, diagnosis_id: int) -> list[dict[str, Any]]:
|
||||
listed.append(diagnosis_id)
|
||||
return [
|
||||
{"id": 92, "diagnosis_id": diagnosis_id, "prescription_date": "2026-11-03",
|
||||
"doctor_name": "陈医生", "clinical_diagnosis": "气阴两虚", "audit_status": 1},
|
||||
{"id": 81, "diagnosis_id": diagnosis_id, "prescription_date": "2026-10-20",
|
||||
"doctor_name": "李医生", "clinical_diagnosis": "脾虚", "void_status": 1},
|
||||
]
|
||||
|
||||
def get_prescription(self, prescription_id: int) -> dict[str, Any]:
|
||||
fetched.append(prescription_id)
|
||||
return {"id": prescription_id, "diagnosis_id": 745, "patient_name": "测试患者",
|
||||
"herbs": [{"name": "黄芪", "dosage": 15}], "usage_instruction": "水煎服"}
|
||||
|
||||
def inspect_detail(dialog: dialog_module.PrescriptionDetailDialog) -> int:
|
||||
shown.append(dialog.prescription["id"])
|
||||
assert "黄芪" in dialog.document.toPlainText()
|
||||
assert "水煎服" in dialog.document.toPlainText()
|
||||
assert dialog.diagnosis_button.isHidden()
|
||||
assert dialog.orders_button.isHidden()
|
||||
return QDialog.DialogCode.Rejected
|
||||
|
||||
monkeypatch.setattr(diagnosis_module, "run_async", _immediate_async)
|
||||
monkeypatch.setattr(dialog_module.PrescriptionDetailDialog, "exec", inspect_detail)
|
||||
owner = QDialog()
|
||||
owner.resize(owner_width, 800)
|
||||
owner.show()
|
||||
editor = PrescriptionEditorDialog(
|
||||
Repository(), {"diagnosis_id": 745, "patient_name": "测试患者"}, mode="edit",
|
||||
permissions=PermissionSet(["tcm.diagnosis/readonlyDetail", "tcm.diagnosis/chufang"]),
|
||||
parent=owner,
|
||||
)
|
||||
editor.show()
|
||||
application.processEvents()
|
||||
editor.clinical_diagnosis.setPlainText("尚未保存的新诊断")
|
||||
draft = editor.payload()
|
||||
editor.diagnosis_button.click()
|
||||
for _ in range(6):
|
||||
application.processEvents()
|
||||
detail = editor._diagnosis_view
|
||||
assert detail is not None
|
||||
table = detail.readonly_prescriptions_table
|
||||
assert listed == [745]
|
||||
assert table.rowCount() == 2
|
||||
assert table.item(0, 5).text() == "审核通过"
|
||||
assert table.item(1, 5).text() == "已作废"
|
||||
assert table.horizontalScrollBar().maximum() == 0
|
||||
assert table.mapToGlobal(QPoint(table.width(), 0)).x() <= detail.readonly_scroll.viewport().mapToGlobal(
|
||||
QPoint(detail.readonly_scroll.viewport().width(), 0)
|
||||
).x()
|
||||
assert detail._readonly_sections["prescription"].y() < detail.case_grid.y()
|
||||
actions = table.cellWidget(1, 6).findChildren(QPushButton)
|
||||
assert [button.text() for button in actions] == ["查看"]
|
||||
actions[0].click()
|
||||
assert fetched == [81] and shown == [81]
|
||||
assert editor.payload() == draft
|
||||
assert editor.diagnosis_host.isVisibleTo(editor)
|
||||
detail.readonly_close_button.click()
|
||||
editor.diagnosis_button.click()
|
||||
assert listed == [745, 745]
|
||||
assert editor.payload() == draft
|
||||
editor.reject()
|
||||
owner.close()
|
||||
application.processEvents()
|
||||
|
||||
|
||||
def test_readonly_history_respects_permission_and_shows_empty_and_failure(
|
||||
application: QApplication, monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
calls: list[int] = []
|
||||
|
||||
class Repository(_DiagnosisRepository):
|
||||
def get_doctor_notes(self, _diagnosis_id: int) -> list[Any]:
|
||||
return []
|
||||
|
||||
def list_prescriptions_by_diagnosis(self, diagnosis_id: int) -> list[Any]:
|
||||
calls.append(diagnosis_id)
|
||||
if len(calls) > 1:
|
||||
raise RuntimeError("测试加载失败")
|
||||
return []
|
||||
|
||||
monkeypatch.setattr(diagnosis_module, "run_async", _immediate_async)
|
||||
dialog = DiagnosisDialog(Repository(), permissions=PermissionSet(["tcm.diagnosis/readonlyDetail"]))
|
||||
dialog.open_for(745, editable=False)
|
||||
assert dialog._readonly_sections["prescription"].isHidden()
|
||||
assert calls == []
|
||||
dialog.refresh_permissions(PermissionSet(["tcm.diagnosis/readonlyDetail", "tcm.diagnosis/chufang"]))
|
||||
dialog.open_for(745, editable=False)
|
||||
assert "暂无历史处方" in dialog.readonly_prescriptions_table.empty_label.text()
|
||||
dialog.open_for(745, editable=False)
|
||||
assert "加载失败" in dialog.readonly_prescriptions_table.empty_label.text()
|
||||
assert dialog.readonly_prescriptions_table.rowCount() == 0
|
||||
dialog.close()
|
||||
application.processEvents()
|
||||
|
||||
|
||||
def test_prescription_lists_snapshot_queries_and_supersede_stale_refresh(
|
||||
application: QApplication,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
|
||||
@@ -246,6 +246,94 @@ def test_blue_icon_disabled_variant_does_not_modify_shared_icon_cache(applicatio
|
||||
assert shared.pixmap(size, size, QIcon.Mode.Disabled).toImage() == original_disabled
|
||||
|
||||
|
||||
@pytest.mark.parametrize("column", [1, 3, 4, 5, 6, 7, 8, 9, 10])
|
||||
def test_all_prescription_data_cells_select_and_copy_without_editing(
|
||||
shell_factory, application, column,
|
||||
) -> None:
|
||||
_shell, page = shell_factory()
|
||||
table = page.table
|
||||
item = table.item(0, column)
|
||||
original = item.text()
|
||||
row_id = _record_id(table, 0)
|
||||
QTest.mouseClick(table.viewport(), Qt.MouseButton.LeftButton, pos=table.visualItemRect(item).center())
|
||||
assert table.copy_text.isVisible()
|
||||
assert _record_id(table, table.currentRow()) == row_id
|
||||
assert table.cellWidget(0, column) is None
|
||||
QTest.keyClick(table.copy_text, Qt.Key.Key_A, Qt.KeyboardModifier.ControlModifier)
|
||||
QTest.keyClick(table.copy_text, Qt.Key.Key_C, Qt.KeyboardModifier.ControlModifier)
|
||||
copied = application.clipboard().text()
|
||||
if column == 1:
|
||||
assert original in copied and f"ID: {row_id}" in copied
|
||||
elif column == 5:
|
||||
assert copied == original.replace(" · ", "\n", 1).replace(" · ", " · ")
|
||||
elif column == 10:
|
||||
assert copied == "\n".join(original.rsplit(" ", 1))
|
||||
else:
|
||||
assert copied == original
|
||||
QTest.keyClicks(table.copy_text, "must-not-edit")
|
||||
assert item.text() == original
|
||||
assert table.item(0, 0).checkState() == Qt.CheckState.Unchecked
|
||||
|
||||
|
||||
def test_text_drag_copy_and_double_click_do_not_open_prescription(shell_factory, application, monkeypatch):
|
||||
_shell, page = shell_factory()
|
||||
table = page.table
|
||||
opened = []
|
||||
monkeypatch.setattr(page, "_view_selected", lambda: opened.append(True))
|
||||
item = table.item(1, 8)
|
||||
rect = table.visualItemRect(item)
|
||||
start = QPoint(rect.left() + 12, rect.center().y())
|
||||
end = QPoint(rect.right() - 12, start.y())
|
||||
QTest.mousePress(table.viewport(), Qt.MouseButton.LeftButton, pos=start)
|
||||
QTest.mouseMove(table.viewport(), end, 30)
|
||||
QTest.mouseRelease(table.viewport(), Qt.MouseButton.LeftButton, pos=end)
|
||||
assert table.copy_text.textCursor().selectedText() == item.text()
|
||||
QTest.keyClick(table.copy_text, Qt.Key.Key_C, Qt.KeyboardModifier.ControlModifier)
|
||||
assert application.clipboard().text() == item.text()
|
||||
table.copy_text.customContextMenuRequested.emit(QPoint(4, 4))
|
||||
menu = page._ai_context_menu
|
||||
selected_action = next(action for action in menu.actions() if action.text() == "复制选中文字")
|
||||
application.clipboard().clear()
|
||||
selected_action.trigger()
|
||||
assert application.clipboard().text() == item.text()
|
||||
menu.close()
|
||||
QTest.mouseDClick(table.viewport(), Qt.MouseButton.LeftButton, pos=start + QPoint(8, 0))
|
||||
assert table.copy_text.textCursor().hasSelection()
|
||||
assert opened == []
|
||||
|
||||
|
||||
def test_copy_context_menu_and_refresh_follow_the_visible_row(shell_factory, application):
|
||||
_shell, page = shell_factory()
|
||||
table = page.table
|
||||
# Copy remains available without AI/report permissions, including blank prescriptions.
|
||||
page.permissions = PermissionSet([])
|
||||
table.sortItems(1, Qt.SortOrder.DescendingOrder)
|
||||
item = table.item(0, 1)
|
||||
page._open_ai_context_menu(table.visualItemRect(item).center())
|
||||
menu = page._ai_context_menu
|
||||
actions = {action.text(): action for action in menu.actions()}
|
||||
assert set(actions) == {"复制单元格", "复制整行"}
|
||||
actions["复制单元格"].trigger()
|
||||
assert item.text() in application.clipboard().text()
|
||||
assert f"ID: {_record_id(table, 0)}" in application.clipboard().text()
|
||||
actions["复制整行"].trigger()
|
||||
copied = application.clipboard().text()
|
||||
for column in range(3, 11):
|
||||
assert table.item(0, column).text() in copied
|
||||
assert "\t" in copied and "复制" not in copied
|
||||
menu.close()
|
||||
QTest.mouseClick(table.viewport(), Qt.MouseButton.LeftButton, pos=table.visualItemRect(item).center())
|
||||
assert table.copy_text.isVisible()
|
||||
table.sortItems(1, Qt.SortOrder.AscendingOrder)
|
||||
assert table.copy_text.isHidden()
|
||||
table.setCurrentItem(table.item(0, 5))
|
||||
QTest.keyClick(table, Qt.Key.Key_C, Qt.KeyboardModifier.ControlModifier)
|
||||
assert application.clipboard().text() == table.item(0, 5).text()
|
||||
QTest.mouseClick(table.viewport(), Qt.MouseButton.LeftButton, pos=table.visualItemRect(table.item(0, 5)).center())
|
||||
page.refresh()
|
||||
assert table.copy_text.isHidden()
|
||||
|
||||
|
||||
def test_long_doctor_button_paints_compactly_without_truncating_real_value(shell_factory, application) -> None:
|
||||
_shell, page = shell_factory(1024, 768)
|
||||
page.filter_disclosure.set_expanded(True)
|
||||
|
||||
Reference in New Issue
Block a user