✨ (base): Añade with_width() a Container

This commit is contained in:
Manuel Cillero 2026-09-19 03:14:21 +02:00
parent 9143f1eb26
commit c6cd4fcd7d
11 changed files with 325 additions and 169 deletions

View file

@ -31,3 +31,83 @@ async fn main_kind_renders_a_main_element() {
assert!(html.starts_with("<main"));
assert!(html.ends_with("</main>"));
}
// **< Container::with_width >**********************************************************************
async fn container_html(width: impl Into<Option<container::Width>>) -> String {
let mut container = Container::new().with_width(width).with_child(Lc::n("x"));
container
.render(&mut Context::default())
.await
.into_string()
}
#[pagetop::test]
async fn width_is_none_by_default_and_adds_no_class() {
assert_eq!(Container::new().width(), None);
// A neutral box: without a width, the component adds no class at all.
assert!(!container_html(None).await.contains("container"));
}
#[pagetop::test]
async fn width_can_be_set_and_reset() {
let width = container::Width::From(Breakpoint::Lg);
assert_eq!(Container::new().with_width(width).width(), Some(width));
assert_eq!(
Container::new().with_width(width).with_width(None).width(),
None
);
}
#[pagetop::test]
async fn width_responsive_adds_the_container_class() {
assert!(
container_html(container::Width::Responsive)
.await
.contains(r#"class="container""#)
);
}
#[pagetop::test]
async fn width_from_uses_the_breakpoint_name() {
assert!(
container_html(container::Width::From(Breakpoint::Lg))
.await
.contains(r#"class="container-lg""#)
);
}
#[pagetop::test]
async fn width_from_a_breakpoint_without_min_width_has_no_name() {
// `Xs` has no minimum width, so the class carries no breakpoint name.
assert!(
container_html(container::Width::From(Breakpoint::Xs))
.await
.contains(r#"class="container""#)
);
}
#[pagetop::test]
async fn width_fluid_adds_the_container_fluid_class() {
assert!(
container_html(container::Width::Fluid)
.await
.contains(r#"class="container-fluid""#)
);
}
#[pagetop::test]
async fn width_fluid_max_adds_the_class_and_a_max_width_style() {
let html = container_html(container::Width::FluidMax(UnitValue::RelRem(75.0))).await;
assert!(html.contains("container-fluid"));
assert!(html.contains("max-width: 75rem"));
}
#[pagetop::test]
async fn width_fluid_max_ignores_a_non_measurable_value() {
let html = container_html(container::Width::FluidMax(UnitValue::Auto)).await;
assert!(html.contains("container-fluid"));
assert!(!html.contains("max-width"));
}