feat: Enhance Dashboard widget configuration and layout management
- Added validation for widget configuration in the DashboardWidgetEntry model to ensure proper data structure. - Updated the DashboardLayoutPayload to include widget configuration in the serialized output. - Improved the PilotBodySection and DashboardLabPage components to support dynamic chart days configuration for the body overview widget. - Refactored layout editor functions to normalize widget configurations for better handling. - Bumped app_dashboard version to 1.2.0 to reflect the new features and improvements.
This commit is contained in:
1 parent
f6c5f96768
commit
87c4cbc4b4
11 files changed
+298
-62
No files matched your search
@@ -0,0 +1,54 @@
|
||||
import pytest
|
||||
|
||||
from dashboard_layout_schema import DashboardLayoutPayload, coalesce_effective_layout, default_layout_dict
|
||||
from dashboard_widget_config import validate_widget_entry_config
|
||||
|
||||
|
||||
def test_body_chart_days_bounds():
|
||||
assert validate_widget_entry_config("body_overview", {"chart_days": 7}) == {"chart_days": 7}
|
||||
assert validate_widget_entry_config("body_overview", {"chart_days": 90}) == {"chart_days": 90}
|
||||
assert validate_widget_entry_config("body_overview", {"chart_days": 42.0}) == {"chart_days": 42}
|
||||
with pytest.raises(ValueError):
|
||||
validate_widget_entry_config("body_overview", {"chart_days": 6})
|
||||
with pytest.raises(ValueError):
|
||||
validate_widget_entry_config("body_overview", {"chart_days": 91})
|
||||
|
||||
|
||||
def test_welcome_config_rejected():
|
||||
with pytest.raises(ValueError):
|
||||
validate_widget_entry_config("welcome", {"x": 1})
|
||||
|
||||
|
||||
def test_body_unknown_key():
|
||||
with pytest.raises(ValueError):
|
||||
validate_widget_entry_config("body_overview", {"chart_days": 30, "extra": 1})
|
||||
|
||||
|
||||
def test_layout_payload_with_chart_days_roundtrip():
|
||||
p = DashboardLayoutPayload.model_validate(
|
||||
{
|
||||
"version": 1,
|
||||
"widgets": [
|
||||
{"id": "welcome", "enabled": True},
|
||||
{
|
||||
"id": "body_overview",
|
||||
"enabled": True,
|
||||
"config": {"chart_days": 42},
|
||||
},
|
||||
],
|
||||
}
|
||||
)
|
||||
d = p.to_stored_dict()
|
||||
assert d["widgets"][1]["config"]["chart_days"] == 42
|
||||
|
||||
|
||||
def test_coalesce_rejects_invalid_widget_config():
|
||||
raw = {
|
||||
"version": 1,
|
||||
"widgets": [
|
||||
{"id": "welcome", "enabled": True, "config": {"evil": True}},
|
||||
],
|
||||
}
|
||||
custom, eff = coalesce_effective_layout(raw)
|
||||
assert custom is False
|
||||
assert eff == default_layout_dict()
|
||||
Reference in new issue
Block a user