更新
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
"""Regressions for the blank strip between query results and pinned actions."""
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
|
||||
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
|
||||
|
||||
import pytest
|
||||
from PySide6.QtCore import QPoint
|
||||
from PySide6.QtTest import QTest
|
||||
from PySide6.QtWidgets import QApplication
|
||||
|
||||
from doctor_workstation.ui.diagnosis_index_widgets import DiagnosisTableHost
|
||||
from doctor_workstation.ui.theme import apply_theme
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def application():
|
||||
app = QApplication.instance() or QApplication([])
|
||||
apply_theme(app)
|
||||
return app
|
||||
|
||||
|
||||
def settle(app):
|
||||
for _ in range(4):
|
||||
app.processEvents()
|
||||
QTest.qWait(15)
|
||||
|
||||
|
||||
def rows(count):
|
||||
return [{"id": i + 1, "patient_name": f"演示患者{i + 1}", "age": 55,
|
||||
"gender": 1, "has_appointment": 0, "diagnosis_confirmed": 1}
|
||||
for i in range(count)]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("blue", [True, False])
|
||||
def test_filter_results_fill_viewport_through_scrollbar_and_window_changes(application, blue):
|
||||
host = DiagnosisTableHost(tech_blue=blue, action_policy={"view": True, "edit": True})
|
||||
host.resize(1650, 680)
|
||||
host.show()
|
||||
for width, count in ((1650, 70), (1650, 2), (1900, 2), (900, 2),
|
||||
(1900, 0), (1900, 2), (1366, 80), (1650, 2)):
|
||||
host.resize(width, 680)
|
||||
host.set_rows(rows(count))
|
||||
settle(application)
|
||||
main = host.main
|
||||
viewport = main.viewport()
|
||||
base_width = sum(host.LEFT_WIDTHS)
|
||||
assert main.horizontalHeader().length() == max(base_width, viewport.width())
|
||||
assert all(main.columnWidth(i) >= minimum for i, minimum in enumerate(host.LEFT_WIDTHS))
|
||||
assert main.viewport().height() == host.fixed.viewport().height()
|
||||
assert main.verticalScrollBar().maximum() == host.fixed.verticalScrollBar().maximum()
|
||||
if viewport.width() >= base_width:
|
||||
assert main.horizontalScrollBar().maximum() == 0
|
||||
if count:
|
||||
main.selectRow(1)
|
||||
settle(application)
|
||||
row = main.visualRect(host.model.index(1, 9))
|
||||
point = QPoint(viewport.width() - 4, row.bottom() - 5)
|
||||
# A real data cell, rather than the QTableView's blank background,
|
||||
# must occupy the entire strip leading into the pinned actions.
|
||||
assert main.indexAt(point).row() == 1
|
||||
assert main.indexAt(point).column() == 9
|
||||
if blue:
|
||||
capture = viewport.grab()
|
||||
scale = capture.devicePixelRatio()
|
||||
pixel = QPoint(round(point.x() * scale), round(point.y() * scale))
|
||||
assert capture.toImage().pixelColor(pixel).name() == "#eaf2ff"
|
||||
else:
|
||||
assert main.horizontalScrollBar().maximum() > 0
|
||||
main.horizontalScrollBar().setValue(main.horizontalScrollBar().maximum())
|
||||
settle(application)
|
||||
assert main.visualRect(host.model.index(0, 9)).right() < viewport.width()
|
||||
host.close()
|
||||
host.deleteLater()
|
||||
Reference in New Issue
Block a user