use azul_core::{
dom::{Dom, NodeId},
styled_dom::StyledDom,
};
#[test]
fn inline_css_scopes_to_subtree_no_leak() {
let dom = Dom::create_body()
.with_child(Dom::create_div().with_css("background: red"))
.with_child(Dom::create_div().with_css("background: blue"));
let styled_dom = StyledDom::create_from_dom(dom);
let cache = styled_dom.get_css_property_cache();
let nd = styled_dom.node_data.as_container();
let sn = styled_dom.styled_nodes.as_container();
let bg = |i: usize| {
let id = NodeId::new(i);
cache
.get_background_content(&nd[id], &id, &sn[id].styled_node_state)
.cloned()
};
let div_a = bg(1);
let div_b = bg(2);
let body = bg(0);
assert!(div_a.is_some(), "div A should have its own background (red)");
assert!(div_b.is_some(), "div B should have its own background (blue)");
assert_ne!(
div_a, div_b,
"div A (red) and div B (blue) must differ — inline css must not cross-leak between siblings"
);
assert!(
body.is_none(),
"body must have NO background — inline css must not leak to the root (#47)"
);
}
#[test]
fn parent_non_inherited_prop_does_not_leak_to_child() {
let child = Dom::create_div();
let parent = Dom::create_div().with_css("background: red").with_child(child);
let dom = Dom::create_body().with_child(parent);
let styled_dom = StyledDom::create_from_dom(dom);
let cache = styled_dom.get_css_property_cache();
let nd = styled_dom.node_data.as_container();
let sn = styled_dom.styled_nodes.as_container();
let bg = |i: usize| {
let id = NodeId::new(i);
cache
.get_background_content(&nd[id], &id, &sn[id].styled_node_state)
.cloned()
};
assert!(bg(1).is_some(), "parent div should have its own background (red)");
assert!(
bg(2).is_none(),
"child div must NOT receive the parent's background — set_css is node-only, not subtree"
);
}