♻️ (pagetop): Props::unpack() exige &mut Context

This commit is contained in:
Manuel Cillero 2026-09-08 07:28:50 +02:00
parent ee1b48ff3f
commit 8577ca8a59
14 changed files with 280 additions and 190 deletions

View file

@ -17,7 +17,7 @@ async fn is_not_rendered_when_empty() {
#[pagetop::test]
async fn nav_root_class_is_unaffected_by_content_flex() {
let mut navbar = Navbar::simple()
.with_flex(Flex::row().with_justify(flex::ContentJustify::End))
.with_flex(Flex::new().with_justify(flex::ContentJustify::End))
.with_item(navbar::Item::nav(one_link_nav()));
let html = navbar.render(&mut Context::default()).await.into_string();
@ -37,32 +37,42 @@ async fn without_flex_content_area_has_no_style_attribute() {
#[pagetop::test]
async fn flex_adds_its_styles_to_the_content_area() {
let mut cx = Context::default();
let mut navbar = Navbar::simple()
.with_flex(Flex::row().with_justify(flex::ContentJustify::End))
.with_flex(Flex::new().with_justify(flex::ContentJustify::End))
.with_item(navbar::Item::nav(one_link_nav()));
let html = navbar.render(&mut Context::default()).await.into_string();
let html = navbar.render(&mut cx).await.into_string();
let assets = cx.render_assets().into_string();
assert!(html.contains(r#"class="navbar-content""#));
assert!(html.contains("display: flex"));
assert!(html.contains("justify-content: flex-end"));
assert!(html.contains("navbar-content"));
assert!(html.contains("_flex_"));
assert!(html.contains("_flex-justify_flex-end_"));
assert!(assets.contains("_flex_{display:flex}"));
assert!(assets.contains("_flex-justify_flex-end_{justify-content:flex-end}"));
}
#[pagetop::test]
async fn flex_gap_adds_a_style_to_the_content_area() {
let mut cx = Context::default();
let mut navbar = Navbar::simple()
.with_flex(Flex::row().with_gap(flex::Gap::Both(UnitValue::RelRem(0.5))))
.with_flex(Flex::new().with_gap(flex::Gap::Both(UnitValue::RelRem(0.5))))
.with_item(navbar::Item::nav(one_link_nav()));
let html = navbar.render(&mut Context::default()).await.into_string();
let html = navbar.render(&mut cx).await.into_string();
let assets = cx.render_assets().into_string();
assert!(html.contains("gap: 0.5rem"));
assert!(html.contains("_flex-gap_0_5rem_"));
assert!(assets.contains("_flex-gap_0_5rem_{gap:0.5rem}"));
}
// **< Navbar + FlexItem::push_end >****************************************************************
#[pagetop::test]
async fn push_end_adds_an_automatic_start_margin() {
let mut nav = one_link_nav().with_prop(FlexItem::push_end());
let html = nav.render(&mut Context::default()).await.into_string();
let mut cx = Context::default();
let mut nav = one_link_nav().with_prop(FlexItem::push_end().into());
let html = nav.render(&mut cx).await.into_string();
let assets = cx.render_assets().into_string();
assert!(html.contains(r#"style="margin-inline-start: auto""#));
assert!(html.contains("_flex-item-offset_auto_"));
assert!(assets.contains("_flex-item-offset_auto_{margin-inline-start:auto}"));
}