- React SPA: dashboard, data sources CRUD, widgets CRUD, layout builder, presets. TanStack Router + Query, shadcn/ui, Vite proxy to :3000 - wire media + rss adapters into polling loop, remove xtb source type - media adapter: read username/password from headers, proper subsonic auth - event handler: subscribe to LayoutChanged, push screen update to clients - fix clippy warnings across workspace (Default impls, collapsible ifs, redundant closures, is_none_or, unused imports)
75 lines
1.9 KiB
Rust
75 lines
1.9 KiB
Rust
use domain::{
|
|
ContainerNode, Direction, Layout, LayoutChild, LayoutNode, LayoutValidationError, Sizing,
|
|
WidgetId,
|
|
};
|
|
use std::collections::BTreeSet;
|
|
|
|
fn leaf(id: WidgetId) -> LayoutChild {
|
|
LayoutChild {
|
|
sizing: Sizing::Flex(1),
|
|
node: LayoutNode::Leaf(id),
|
|
}
|
|
}
|
|
|
|
fn row(children: Vec<LayoutChild>) -> LayoutNode {
|
|
LayoutNode::Container(ContainerNode {
|
|
direction: Direction::Row,
|
|
gap: 0,
|
|
padding: 0,
|
|
children,
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn validate_returns_empty_when_all_widgets_exist() {
|
|
let layout = Layout {
|
|
root: row(vec![leaf(1), leaf(2)]),
|
|
};
|
|
let known = BTreeSet::from([1, 2]);
|
|
assert!(layout.validate(&known).is_empty());
|
|
}
|
|
|
|
#[test]
|
|
fn validate_reports_unknown_widget_ids() {
|
|
let layout = Layout {
|
|
root: row(vec![leaf(1), leaf(99)]),
|
|
};
|
|
let known = BTreeSet::from([1]);
|
|
let errors = layout.validate(&known);
|
|
assert_eq!(errors, vec![LayoutValidationError::UnknownWidget(99)]);
|
|
}
|
|
|
|
#[test]
|
|
fn validate_reports_empty_container() {
|
|
let layout = Layout { root: row(vec![]) };
|
|
let known = BTreeSet::new();
|
|
let errors = layout.validate(&known);
|
|
assert_eq!(errors, vec![LayoutValidationError::EmptyContainer]);
|
|
}
|
|
|
|
#[test]
|
|
fn validate_checks_nested_containers() {
|
|
let inner = LayoutChild {
|
|
sizing: Sizing::Flex(1),
|
|
node: row(vec![leaf(1), leaf(42)]),
|
|
};
|
|
let layout = Layout {
|
|
root: row(vec![inner, leaf(2)]),
|
|
};
|
|
let known = BTreeSet::from([1, 2]);
|
|
let errors = layout.validate(&known);
|
|
assert_eq!(errors, vec![LayoutValidationError::UnknownWidget(42)]);
|
|
}
|
|
|
|
#[test]
|
|
fn widget_ids_collects_all_leaf_ids() {
|
|
let inner = LayoutChild {
|
|
sizing: Sizing::Flex(1),
|
|
node: row(vec![leaf(3)]),
|
|
};
|
|
let layout = Layout {
|
|
root: row(vec![leaf(1), inner, leaf(2)]),
|
|
};
|
|
assert_eq!(layout.widget_ids(), BTreeSet::from([1, 2, 3]));
|
|
}
|