Add dashboard summary tiles
Shows rider count, activities imported in the last 7 days, 7-day sync success rate, and how many riders currently need attention, right above the rider list where an admin looks first. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
43
tests/web/test_dashboard_summary.py
Normal file
43
tests/web/test_dashboard_summary.py
Normal file
@@ -0,0 +1,43 @@
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
from app.db.models import HealthState, SyncRunStatus
|
||||
from app.db.repositories import SyncRunRepository, UserRepository
|
||||
|
||||
|
||||
def _seed_user(session, name, *, enabled=True, health_state=HealthState.HEALTHY):
|
||||
return UserRepository(session).create(
|
||||
name=name,
|
||||
enabled=enabled,
|
||||
health_state=health_state,
|
||||
mywhoosh_email_enc=f"mw-{name}",
|
||||
mywhoosh_password_enc=f"mw-pw-{name}",
|
||||
garmin_email_enc=f"g-{name}",
|
||||
garmin_password_enc=f"g-pw-{name}",
|
||||
)
|
||||
|
||||
|
||||
def test_dashboard_shows_summary_tiles(app, authenticated_client) -> None:
|
||||
with app.state.session_factory() as session:
|
||||
alex = _seed_user(session, "Alex", enabled=True)
|
||||
_seed_user(session, "Jamie", enabled=False, health_state=HealthState.ACTION_REQUIRED)
|
||||
|
||||
run_repo = SyncRunRepository(session)
|
||||
run = run_repo.start(alex.id)
|
||||
run.started_at = datetime.now(timezone.utc) - timedelta(hours=2)
|
||||
run_repo.finish(run.id, status=SyncRunStatus.SUCCESS, discovered=3, imported=3, skipped=0, failed=0)
|
||||
|
||||
response = authenticated_client.get("/")
|
||||
|
||||
assert response.status_code == 200
|
||||
assert '<span class="stat-tile-value">2</span>' in response.text
|
||||
assert "1 enabled" in response.text
|
||||
assert '<span class="stat-tile-value">3</span>' in response.text
|
||||
assert '<span class="stat-tile-value">100%</span>' in response.text
|
||||
assert '<span class="stat-tile-value">1</span>' in response.text
|
||||
|
||||
|
||||
def test_dashboard_shows_dash_for_success_rate_without_recent_runs(authenticated_client) -> None:
|
||||
response = authenticated_client.get("/")
|
||||
|
||||
assert response.status_code == 200
|
||||
assert '<span class="stat-tile-value">–</span>' in response.text
|
||||
Reference in New Issue
Block a user