geng
This commit is contained in:
@@ -3,13 +3,14 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from copy import deepcopy
|
||||
from types import SimpleNamespace
|
||||
from typing import Any
|
||||
|
||||
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
|
||||
|
||||
import pytest
|
||||
from PySide6.QtWidgets import QApplication, QDialog, QDialogButtonBox, QLabel
|
||||
from PySide6.QtWidgets import QAbstractItemView, QApplication, QDialog, QDialogButtonBox, QLabel
|
||||
|
||||
from doctor_workstation.core.errors import ApiProtocolError
|
||||
from doctor_workstation.core.models import Appointment, PageResult
|
||||
@@ -163,6 +164,8 @@ def test_diagnosis_and_patient_ids_stay_distinct_for_video() -> None:
|
||||
)
|
||||
assert _diagnosis_id(row) == 501
|
||||
assert _video_patient_id(row) == 301
|
||||
assert _video_patient_id({"diagnosis_id": 501, "patient_id": 301}) == 0
|
||||
assert _video_patient_id({"diagnosis_id": 501, "patient_id": 501}) == 0
|
||||
assert prescription_action_label(row) == "开方"
|
||||
|
||||
approved = Appointment.from_dict(
|
||||
@@ -354,7 +357,8 @@ def test_appointment_multiline_cells_receive_enough_row_height(
|
||||
assert appointment_text.count("\n") == 2
|
||||
assert "2026-08-11 14:30" in appointment_text
|
||||
required = 3 * max(16, page.table.fontMetrics().lineSpacing()) + 10
|
||||
assert page.table.rowHeight(0) >= required
|
||||
assert 60 <= page.table.rowHeight(0) <= 66
|
||||
assert page.table.rowHeight(0) >= min(required, 66)
|
||||
assert page.table.item(0, 4).toolTip() == appointment_text
|
||||
page.close()
|
||||
|
||||
@@ -513,6 +517,7 @@ def test_appointments_reference_split_layout_and_video_list(
|
||||
current_user={"id": 1001, "role_id": 1},
|
||||
)
|
||||
page.resize(1460, 820)
|
||||
page._apply_responsive_layout()
|
||||
page._loaded(
|
||||
{
|
||||
"lists": [
|
||||
@@ -538,8 +543,133 @@ def test_appointments_reference_split_layout_and_video_list(
|
||||
|
||||
assert page.video_list.count() == 1
|
||||
assert "赵俊霞" in page.video_list.item(0).text()
|
||||
assert page.video_list.parentWidget().width() == 420
|
||||
assert 300 <= page.video_panel.width() <= 420
|
||||
assert page.table.objectName() == "AppointmentTable"
|
||||
assert (
|
||||
page.table.verticalScrollMode()
|
||||
== QAbstractItemView.ScrollMode.ScrollPerPixel
|
||||
)
|
||||
assert (
|
||||
page.video_list.verticalScrollMode()
|
||||
== QAbstractItemView.ScrollMode.ScrollPerPixel
|
||||
)
|
||||
assert page.date_buttons["today"].isChecked()
|
||||
|
||||
page.resize(1024, 640)
|
||||
page._apply_responsive_layout()
|
||||
assert page.video_panel.isHidden()
|
||||
assert not page.video_panel_button.isHidden()
|
||||
assert not page.date_overflow_button.isHidden()
|
||||
assert page.date_buttons["yesterday"].isHidden()
|
||||
assert not page.date_buttons["today"].isHidden()
|
||||
page.video_panel_button.click()
|
||||
assert not page.video_panel.isHidden()
|
||||
assert 250 <= page.video_panel.width() <= 300
|
||||
page.video_panel_button.click()
|
||||
assert page.video_panel.isHidden()
|
||||
page.close()
|
||||
application.processEvents()
|
||||
|
||||
|
||||
def test_identical_appointment_poll_keeps_existing_cell_widgets(
|
||||
application: QApplication,
|
||||
) -> None:
|
||||
page = AppointmentsPage(
|
||||
DemoDoctorRepository(),
|
||||
permissions=PermissionSet(["doctor.appointment/lists"]),
|
||||
current_user={"id": 1001, "role_id": 1},
|
||||
)
|
||||
result = {
|
||||
"lists": [
|
||||
{
|
||||
"id": 101,
|
||||
"diagnosis_id": 501,
|
||||
"patient_id": 301,
|
||||
"patient_name": "赵俊霞",
|
||||
"gender": 2,
|
||||
"age": 53,
|
||||
"assistant_name": "周医助",
|
||||
"appointment_date": "2026-08-17",
|
||||
"appointment_time": "09:50",
|
||||
"status": 1,
|
||||
"status_desc": "已挂号",
|
||||
}
|
||||
],
|
||||
"count": 1,
|
||||
"extend": {"status_count": {"1": 1}},
|
||||
}
|
||||
page._loaded(result, page._generation, True)
|
||||
selector = page.table.cellWidget(0, 0)
|
||||
appointment_info = page.table.cellWidget(0, 4)
|
||||
video_card = page.video_list.itemWidget(page.video_list.item(0))
|
||||
|
||||
page._loaded(deepcopy(result), page._generation, True)
|
||||
|
||||
assert page.table.cellWidget(0, 0) is selector
|
||||
assert page.table.cellWidget(0, 4) is appointment_info
|
||||
assert page.video_list.itemWidget(page.video_list.item(0)) is video_card
|
||||
|
||||
changed = deepcopy(result)
|
||||
changed["lists"][0]["assistant_name"] = "新医助"
|
||||
page._loaded(changed, page._generation, True)
|
||||
assert page.table.cellWidget(0, 0) is not selector
|
||||
assert page.table.cellWidget(0, 4) is not appointment_info
|
||||
page.close()
|
||||
application.processEvents()
|
||||
|
||||
|
||||
def test_appointments_density_fits_four_rows_in_1366_shell_viewport(
|
||||
application: QApplication,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
monkeypatch.setattr(appointments_module, "run_async", lambda *_args, **_kwargs: object())
|
||||
page = AppointmentsPage(
|
||||
DemoDoctorRepository(),
|
||||
permissions=PermissionSet(["*"]),
|
||||
current_user={"id": 1001, "role_id": 1},
|
||||
)
|
||||
# 1366x768 shell minus its 179 px appointment rail, 26 px outer gutter,
|
||||
# and 62 px top bar leaves a 1161x680 page viewport.
|
||||
page.resize(1161, 680)
|
||||
page.show()
|
||||
application.processEvents()
|
||||
rows = [
|
||||
{
|
||||
"id": 100 + index,
|
||||
"diagnosis_id": 500 + index,
|
||||
"patient_id": 300 + index,
|
||||
"patient_name": f"患者{index}",
|
||||
"gender": 2,
|
||||
"age": 40 + index,
|
||||
"doctor_name": "陈医生",
|
||||
"assistant_name": "周医助",
|
||||
"appointment_date": "2026-08-17",
|
||||
"appointment_time": f"{8 + index:02d}:00",
|
||||
"status": 1,
|
||||
"status_desc": "已挂号",
|
||||
"diagnosis_confirmed": 0,
|
||||
"has_prescription": 0,
|
||||
}
|
||||
for index in range(8)
|
||||
]
|
||||
page._loaded(
|
||||
{"lists": rows, "count": len(rows), "extend": {"status_count": {"1": 8}}},
|
||||
page._generation,
|
||||
False,
|
||||
)
|
||||
application.processEvents()
|
||||
|
||||
heights = [page.table.rowHeight(index) for index in range(page.table.rowCount())]
|
||||
assert page.header.height() == 26
|
||||
assert page.filter_panel.height() <= 84
|
||||
assert all(60 <= height <= 66 for height in heights)
|
||||
assert page.table.viewport().height() // max(heights) >= 4
|
||||
assert page.pager.isVisibleTo(page)
|
||||
assert 300 <= page.video_panel.width() < 420
|
||||
|
||||
page.resize(1024, 640)
|
||||
application.processEvents()
|
||||
assert page.video_panel.isHidden()
|
||||
assert not page.video_panel_button.isHidden()
|
||||
page.close()
|
||||
application.processEvents()
|
||||
|
||||
Reference in New Issue
Block a user