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 '2' in response.text assert "1 enabled" in response.text assert '3' in response.text assert '100%' in response.text assert '1' 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 '' in response.text