118 lines
3.1 KiB
Python
118 lines
3.1 KiB
Python
from datetime import date
|
|
|
|
import pytest
|
|
from PySide6.QtCore import QCoreApplication
|
|
|
|
from study_dashboard.view_models import MainViewModel
|
|
from study_dashboard.services.models import (
|
|
AppointmentRecord,
|
|
ExamRecord,
|
|
ModuleRecord,
|
|
)
|
|
from study_dashboard.services.repository import StudyRepository
|
|
|
|
|
|
class FakeRepository(StudyRepository):
|
|
def __init__(self):
|
|
self.modules = [
|
|
ModuleRecord(
|
|
module_id="DEMO-1",
|
|
title="Demo Modul",
|
|
credit_points=5,
|
|
status="In Bearbeitung",
|
|
progress_percent=60,
|
|
)
|
|
]
|
|
self.exams = [
|
|
ExamRecord(
|
|
exam_id="EXAM-1",
|
|
module_id="DEMO-1",
|
|
title="Demo Klausur",
|
|
exam_date=date(2025, 12, 31),
|
|
status="Geplant",
|
|
)
|
|
]
|
|
self.appointments = [
|
|
AppointmentRecord(
|
|
appointment_id="APPT-1",
|
|
title="Mentoring",
|
|
start_date=date(2025, 11, 30),
|
|
description="Mock Termin",
|
|
)
|
|
]
|
|
|
|
def list_modules(self):
|
|
return list(self.modules)
|
|
|
|
def list_upcoming_exams(self, limit: int = 5):
|
|
return list(self.exams)[:limit]
|
|
|
|
def list_upcoming_appointments(self, limit: int = 5):
|
|
return list(self.appointments)[:limit]
|
|
|
|
|
|
@pytest.fixture(scope="module", autouse=True)
|
|
def qt_core_app():
|
|
app = QCoreApplication.instance()
|
|
if app is None:
|
|
app = QCoreApplication([])
|
|
yield app
|
|
|
|
|
|
def _connect_collectors(view_model):
|
|
payloads = {"modules": [], "exams": [], "appointments": []}
|
|
|
|
view_model.modules_changed.connect(
|
|
lambda payload, key="modules": payloads[key].append(payload)
|
|
)
|
|
view_model.exams_changed.connect(
|
|
lambda payload, key="exams": payloads[key].append(payload)
|
|
)
|
|
view_model.appointments_changed.connect(
|
|
lambda payload, key="appointments": payloads[key].append(payload)
|
|
)
|
|
|
|
return payloads
|
|
|
|
|
|
def test_view_model_emits_structured_lists():
|
|
repo = FakeRepository()
|
|
view_model = MainViewModel(repo)
|
|
captured = _connect_collectors(view_model)
|
|
|
|
view_model.load()
|
|
|
|
modules_payload = captured["modules"][-1]
|
|
exams_payload = captured["exams"][-1]
|
|
appointments_payload = captured["appointments"][-1]
|
|
|
|
assert modules_payload[0]["module_id"] == "DEMO-1"
|
|
assert modules_payload[0]["progress"] == 60
|
|
assert exams_payload[0]["date"] == "31.12.2025"
|
|
assert appointments_payload[0]["title"] == "Mentoring"
|
|
|
|
|
|
def test_refresh_emits_latest_snapshot():
|
|
repo = FakeRepository()
|
|
view_model = MainViewModel(repo)
|
|
modules_payloads = []
|
|
view_model.modules_changed.connect(modules_payloads.append)
|
|
|
|
view_model.load()
|
|
|
|
repo.modules = [
|
|
ModuleRecord(
|
|
module_id="DEMO-2",
|
|
title="Neues Modul",
|
|
credit_points=10,
|
|
status="Fast fertig",
|
|
progress_percent=90,
|
|
)
|
|
]
|
|
|
|
view_model.refresh()
|
|
|
|
latest_snapshot = modules_payloads[-1]
|
|
assert latest_snapshot[0]["module_id"] == "DEMO-2"
|
|
assert latest_snapshot[0]["progress"] == 90
|