mitai-jinkendo/backend/tests/test_dashboard_layout_schema.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

59 lines
1.5 KiB
Python

import pytest
from dashboard_layout_schema import (
ALLOWED_WIDGET_IDS,
DashboardLayoutPayload,
coalesce_effective_layout,
default_layout_dict,
)
from widget_catalog import DEFAULT_PRODUCT_DASHBOARD_WIDGET_IDS
def test_default_has_all_allowed_ids():
d = default_layout_dict()
got = {w["id"] for w in d["widgets"]}
assert got == ALLOWED_WIDGET_IDS
assert {w["id"] for w in d["widgets"] if w["enabled"]} == DEFAULT_PRODUCT_DASHBOARD_WIDGET_IDS
def test_payload_rejects_duplicate_ids():
with pytest.raises(Exception):
DashboardLayoutPayload.model_validate(
{
"version": 1,
"widgets": [
{"id": "welcome", "enabled": True},
{"id": "welcome", "enabled": False},
],
}
)
def test_payload_requires_one_enabled():
with pytest.raises(Exception):
DashboardLayoutPayload.model_validate(
{
"version": 1,
"widgets": [{"id": "dashboard_greeting", "enabled": False}],
}
)
def test_coalesce_none():
custom, eff = coalesce_effective_layout(None)
assert custom is False
assert eff == default_layout_dict()
def test_coalesce_valid_raw():
raw = {
"version": 1,
"widgets": [
{"id": "welcome", "enabled": True},
{"id": "kpi_board", "enabled": True},
],
}
custom, eff = coalesce_effective_layout(raw)
assert custom is True
assert eff == raw