更新
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
"""Appointment medium stays attached to its own row and opens text chat without RTC."""
|
||||
import os
|
||||
|
||||
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
|
||||
|
||||
import pytest
|
||||
from PySide6.QtCore import Qt
|
||||
from PySide6.QtWidgets import QApplication, QLabel, QPushButton, QToolButton
|
||||
|
||||
from doctor_workstation.core import PermissionSet
|
||||
from doctor_workstation.core.appointment_modes import (
|
||||
appointment_type_description,
|
||||
appointment_type_value,
|
||||
can_appointment_video,
|
||||
)
|
||||
from doctor_workstation.services import DemoDoctorRepository
|
||||
from doctor_workstation.ui.diagnosis_index_widgets import _blue_appointment_text
|
||||
from doctor_workstation.ui.pages import appointments, consultations
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def application():
|
||||
return QApplication.instance() or QApplication([])
|
||||
|
||||
|
||||
@pytest.mark.parametrize("value,label,video", [
|
||||
("text", "图文问诊", False), ("video", "视频问诊", True),
|
||||
(None, "视频问诊", True), (" ", "视频问诊", True),
|
||||
("phone", "电话问诊", False), ("unexpected", "未知", False),
|
||||
])
|
||||
def test_appointment_type_never_uses_diagnosis_visit_type(value, label, video):
|
||||
assert appointment_type_description(value) == label
|
||||
assert can_appointment_video(value) is video
|
||||
assert appointment_type_value({"appointment_type": value, "consultation_type": "复诊"}) == value or value == ""
|
||||
|
||||
|
||||
def test_nested_type_uses_current_appointment_id_not_another_latest():
|
||||
row = {"appointment_id": 12, "latest_appointment_type": "video", "appointments": [
|
||||
{"id": 11, "appointment_type": "video"}, {"id": 12, "appointment_type": "text"},
|
||||
]}
|
||||
assert appointment_type_value(row) == "text"
|
||||
assert "图文问诊" in _blue_appointment_text(row, row["appointments"][1])[1]
|
||||
assert "视频问诊" in _blue_appointment_text(row, row["appointments"][0])[1]
|
||||
assert appointment_type_value({"appointments": row["appointments"]}) == "unknown"
|
||||
|
||||
|
||||
def test_appointment_text_chat_carries_exact_ids_and_blocks_video_qr(application, monkeypatch):
|
||||
monkeypatch.setattr(appointments, "run_async", lambda *_a, **_kw: None)
|
||||
notices = []
|
||||
monkeypatch.setattr(appointments, "show_toast", lambda _parent, message, *_a: notices.append(message))
|
||||
page = appointments.AppointmentsPage(DemoDoctorRepository(), PermissionSet(["*"]))
|
||||
rows = [{"id": 71, "patient_id": 501, "diagnosis_id": 501, "source_patient_id": 901,
|
||||
"patient_name": "图文患者", "doctor_id": 7, "status": 1, "appointment_type": "text"},
|
||||
{"id": 72, "patient_id": 502, "diagnosis_id": 502, "source_patient_id": 902,
|
||||
"patient_name": "视频患者", "doctor_id": 8, "status": 1, "appointment_type": "video"}]
|
||||
try:
|
||||
page._loaded({"lists": rows, "count": 2}, page._generation, False)
|
||||
emitted = []
|
||||
page.video_requested.connect(emitted.append)
|
||||
page.table.sortItems(1, Qt.SortOrder.DescendingOrder)
|
||||
text_row = next(i for i in range(2) if page.table.item(i, 0).data(Qt.ItemDataRole.UserRole)["id"] == 71)
|
||||
button = page.table.cellWidget(text_row, 10).findChild(QPushButton, "AppointmentImConsultButton")
|
||||
assert button.text() == "图文沟通" and button.isEnabled()
|
||||
assert page.table.cellWidget(text_row, 4).findChild(QLabel, "AppointmentModeLabel").text() == "图文问诊"
|
||||
button.click()
|
||||
assert emitted[-1]["appointment_id"] == 71
|
||||
assert emitted[-1]["diagnosis_id"] == 501
|
||||
assert emitted[-1]["patient_id"] == 901
|
||||
assert emitted[-1]["appointment_type"] == "text"
|
||||
assert emitted[-1]["mode"] == "im"
|
||||
assert not page.toolbar_qr_button.isEnabled()
|
||||
page._request_video_qr()
|
||||
assert notices[-1] == "本次挂号不支持视频问诊二维码。"
|
||||
finally:
|
||||
page.close()
|
||||
page.deleteLater()
|
||||
|
||||
|
||||
def test_consultation_text_entry_does_not_wait_for_live_video(application, monkeypatch):
|
||||
monkeypatch.setattr(consultations, "run_async", lambda *_a, **_kw: None)
|
||||
row = {"id": 501, "patient_id": 901, "patient_name": "图文患者", "has_appointment": 1,
|
||||
"appointment_status": 1, "latest_appointment_id": 71,
|
||||
"appointments": [{"id": 71, "status": 1, "appointment_type": "text"}],
|
||||
"video_call_hint": {"state": "none"}}
|
||||
page = consultations.ConsultationsPage(DemoDoctorRepository(), PermissionSet(["*"]))
|
||||
try:
|
||||
page.table_host.set_rows([row])
|
||||
page.table.selectRow(0)
|
||||
page._selection_changed()
|
||||
buttons = page.table_host.findChildren(QToolButton)
|
||||
text_button = next(button for button in buttons if button.text() == "图文沟通")
|
||||
assert text_button.isEnabled()
|
||||
assert page.video_button.isEnabled()
|
||||
assert not page.video_qr_toolbar_button.isEnabled()
|
||||
emitted = []
|
||||
page.video_requested.connect(emitted.append)
|
||||
page._request_video()
|
||||
assert emitted[-1]["appointment_id"] == 71
|
||||
assert emitted[-1]["appointment_type"] == "text"
|
||||
assert emitted[-1]["mode"] == "im"
|
||||
finally:
|
||||
page.close()
|
||||
page.deleteLater()
|
||||
Reference in New Issue
Block a user