mitai-jinkendo/backend/tests/test_widget_catalog.py
Lars e4e2f23d7f
All checks were successful
Deploy Development / deploy (push) Successful in 48s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 17s
feat: Enhance dashboard layout and widget configuration
- Updated dashboard layout schema to introduce separate default layouts for product and lab dashboards.
- Added new functions for managing product and lab default layouts, improving user customization options.
- Updated app_dashboard version to 1.9.0 to reflect the introduction of product vs lab layout defaults and new API fields for dashboard configuration.
- Enhanced tests to validate new layout functionalities and ensure proper widget visibility based on user settings.
2026-04-08 07:41:16 +02:00

60 lines
2.1 KiB
Python

"""Widget-Katalog: Konsistenz (IDs, Default-Layout, Katalog-Response)."""
from dashboard_layout_schema import default_layout_dict
from dashboard_widget_entitlements import widgets_catalog_payload
from widget_catalog import (
ALLOWED_WIDGET_IDS,
DEFAULT_LAB_WIDGET_IDS,
DEFAULT_PRODUCT_DASHBOARD_WIDGET_IDS,
WIDGET_CATALOG,
)
def test_catalog_ids_unique_and_match_allowed():
ids = [e["id"] for e in WIDGET_CATALOG]
assert len(ids) == len(set(ids))
assert frozenset(ids) == ALLOWED_WIDGET_IDS
def test_default_layout_follows_catalog_order():
d = default_layout_dict()
assert d["version"] == 1
got = [w["id"] for w in d["widgets"]]
assert got == [e["id"] for e in WIDGET_CATALOG]
enabled_ids = {w["id"] for w in d["widgets"] if w["enabled"]}
assert enabled_ids == DEFAULT_PRODUCT_DASHBOARD_WIDGET_IDS
assert any(w["enabled"] for w in d["widgets"])
def test_lab_default_matches_lab_widget_ids():
from dashboard_layout_schema import lab_default_layout_dict
d = lab_default_layout_dict()
assert {w["id"] for w in d["widgets"] if w["enabled"]} == DEFAULT_LAB_WIDGET_IDS
def test_catalog_payload_shape(monkeypatch):
monkeypatch.setattr(
"dashboard_widget_entitlements._check_feature_access",
lambda *args, **kwargs: {"allowed": True},
)
r = widgets_catalog_payload("test-profile", None)
assert r["catalog_version"] == 1
assert len(r["widgets"]) == len(WIDGET_CATALOG)
assert {w["id"] for w in r["widgets"]} == ALLOWED_WIDGET_IDS
for w in r["widgets"]:
assert set(w.keys()) == {"id", "title", "description", "allowed"}
assert w["allowed"] is True
def test_catalog_marks_disallowed_when_feature_blocks(monkeypatch):
def _check(_pid, feature_id, conn=None):
return {"allowed": feature_id != "nutrition_entries"}
monkeypatch.setattr("dashboard_widget_entitlements._check_feature_access", _check)
r = widgets_catalog_payload("p", None)
by_id = {w["id"]: w for w in r["widgets"]}
assert by_id["welcome"]["allowed"] is True
assert by_id["nutrition_detail_charts"]["allowed"] is False
assert by_id["body_overview"]["allowed"] is True