fix: make BOQ sticky header actually stick during scroll

This commit is contained in:
Арсентьев Александр
2026-09-27 18:57:27 +03:00
parent 9992a435b2
commit 79d802d536
4 changed files with 309 additions and 2 deletions
+140
View File
@@ -0,0 +1,140 @@
"""Regression tests for task 015: sticky header in BOQ document table."""
import shutil
from fastapi.testclient import TestClient
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from app.database.database import Base, DATABASE_PATH
from app.main import app
from app.models.project import Project
from app.models.boq import BoqDocument, Section, System, WorkItem
from app.routers import boq as boq_router
def _make_session(tmp_path):
db_path = tmp_path / "t015-copy.db"
shutil.copy2(DATABASE_PATH, db_path)
engine = create_engine(f"sqlite:///{db_path.as_posix()}", connect_args={"check_same_thread": False})
Base.metadata.create_all(bind=engine)
return engine, sessionmaker(bind=engine, autoflush=False, autocommit=False)
def _override(Session):
def override_db():
s = Session()
try:
yield s
finally:
s.close()
app.dependency_overrides[boq_router.get_db] = override_db
def _clear():
app.dependency_overrides.pop(boq_router.get_db, None)
def _create_long_boq(Session, item_count=30):
with Session() as s:
p = Project(name="Sticky BOQ")
s.add(p)
s.flush()
doc = BoqDocument(project_id=p.id, name="BOQ sticky")
s.add(doc)
s.flush()
system = System(project_id=p.id, name="Система 1", sort_order=1)
s.add(system)
s.flush()
section = Section(system_id=system.id, name="Раздел 1", sort_order=1)
s.add(section)
s.flush()
for i in range(item_count):
s.add(WorkItem(
project_id=p.id, boq_document_id=doc.id,
system_id=system.id, section_id=section.id,
source_number=str(i + 1), name=f"Позиция {i + 1}",
unit="шт", quantity=1,
))
s.commit()
return p.id, doc.id
def test_boq_page_uses_scrollable_sticky_wrapper(tmp_path):
engine, Session = _make_session(tmp_path)
_override(Session)
try:
pid, did = _create_long_boq(Session)
with TestClient(app) as client:
resp = client.get(f"/boq/{pid}/documents/{did}")
assert resp.status_code == 200
html = resp.text
# Wrapper is the scrollport for sticky thead
assert "boq-table-wrap" in html
assert "overflow: auto" in html
assert "max-height: calc(100vh" in html
# Sticky rule present on thead th
assert "position: sticky" in html
assert "top: 0" in html
assert "z-index: 10" in html
# Opaque background + border restore for collapsed tables
assert "background-color: #f8f9fa" in html
assert "box-shadow: inset 0 -1px 0" in html
# Table structure preserved
assert "<thead" in html
assert "boq-table" in html
assert "table-layout: fixed" in html
finally:
_clear()
engine.dispose()
def test_boq_page_keeps_colgroup_widths(tmp_path):
engine, Session = _make_session(tmp_path)
_override(Session)
try:
pid, did = _create_long_boq(Session, item_count=3)
with TestClient(app) as client:
resp = client.get(f"/boq/{pid}/documents/{did}")
html = resp.text
assert "width: 3.5rem" in html
assert "width: 9rem" in html
assert "width: 11rem" in html
assert "<colgroup>" in html
finally:
_clear()
engine.dispose()
def test_boq_page_keeps_collapse_controls(tmp_path):
engine, Session = _make_session(tmp_path)
_override(Session)
try:
pid, did = _create_long_boq(Session, item_count=5)
with TestClient(app) as client:
resp = client.get(f"/boq/{pid}/documents/{did}")
html = resp.text
assert "expandAll" in html
assert "collapseAll" in html
assert "toggle-row" in html
assert "data-toggle=\"system-" in html
assert "data-parent=\"section-" in html
finally:
_clear()
engine.dispose()
def test_boq_sticky_not_nested_in_table_responsive(tmp_path):
"""table-responsive would break sticky; wrapper must be used instead."""
engine, Session = _make_session(tmp_path)
_override(Session)
try:
pid, did = _create_long_boq(Session, item_count=2)
with TestClient(app) as client:
resp = client.get(f"/boq/{pid}/documents/{did}")
html = resp.text
# The table itself must not sit inside Bootstrap table-responsive
assert 'class="table-responsive"' not in html
assert "boq-table-wrap" in html
finally:
_clear()
engine.dispose()