feat: 首页拆分独立加载、骨架动画和手动刷新

This commit is contained in:
2026-11-15 00:48:26 +08:00
parent 9a6f134f56
commit fa6811dab7
9 changed files with 657 additions and 282 deletions
+63
View File
@@ -1,5 +1,6 @@
import json
import pytest
from fastapi.testclient import TestClient
from euniv.client import JigsawRejected, ManualJigsaw
@@ -108,6 +109,7 @@ def test_login_stores_password_and_credential_only() -> None:
"refresh_paused",
"last_refresh_at",
"credential_valid",
"month_hours",
}
home = client.get("/api/home")
@@ -390,3 +392,64 @@ def test_exam_and_training_details() -> None:
"score": "0/5.2",
"hours": "52/52",
}
def test_home_sections_are_separate() -> None:
import euniv.api as api_module
import euniv.service as service_module
api_module.login_and_store = lambda db, employee_id, password, manual=False, auto_attempts=3: service_module.login_and_store(
db, employee_id, password, FakeClient, manual=manual, auto_attempts=auto_attempts
)
api_module.fetch_home_summary = lambda db, employee_id: {"name": "分段"}
api_module.fetch_home_exams = lambda db, employee_id: {"exams": [{"name": "一门考试"}]}
api_module.fetch_home_trainings = lambda db, employee_id: {"trainings": [{"name": "一门培训"}]}
client = TestClient(api_module.app)
response = client.post("/api/login", json={"employee_id": "6650000146", "password": "secret-pass"})
assert response.status_code == 200
assert client.get("/api/home/summary").json()["name"] == "分段"
assert client.get("/api/home/exams").json()["exams"] == [{"name": "一门考试"}]
assert client.get("/api/home/trainings").json()["trainings"] == [{"name": "一门培训"}]
def test_period_page_is_not_fetched_twice() -> None:
from euniv.client import EunivClient
client = EunivClient.__new__(EunivClient)
client._profile = {"token": "t", "accountId": "a"}
client._site_ready = False
calls: list[str] = []
class Response:
text = '<span id="spAnnualPeriod" title="34分钟"></span><span id="spMonthlyPeriod" title="12分钟"></span>'
class HTTP:
def get(self, url: str, headers=None):
calls.append(url)
return Response()
client.client = HTTP()
assert client._period_minutes() == {"year": "34", "month": "12"}
assert len(calls) == 1
def test_exam_list_rejects_unrecognized_page() -> None:
from euniv.client import EunivClient
client = EunivClient.__new__(EunivClient)
client._profile = {"token": "t", "accountId": "a"}
client._site_ready = True
class Response:
text = "<html>login</html>"
class HTTP:
def get(self, url: str, headers=None):
return Response()
def post(self, url: str, data=None, headers=None):
return Response()
client.client = HTTP()
with pytest.raises(RuntimeError, match="考试列表没有获取到"):
client.my_exams()