⚡️ (pagetop): Mejora uso de Props, Grid y HttpRequest
This commit is contained in:
parent
58b4b4e036
commit
5b2ddeb6cc
5 changed files with 228 additions and 38 deletions
57
tests/component_grid_layout.rs
Normal file
57
tests/component_grid_layout.rs
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
use pagetop::prelude::*;
|
||||
|
||||
// Las pistas de columna y de fila se guardan aparte para que `Grid` sea pequeño; esta prueba
|
||||
// avisa si algo vuelve a inflarlo.
|
||||
#[pagetop::test]
|
||||
async fn grid_stays_small() {
|
||||
assert!(
|
||||
std::mem::size_of::<Grid>() <= 1024,
|
||||
"Grid ocupa {} bytes",
|
||||
std::mem::size_of::<Grid>()
|
||||
);
|
||||
}
|
||||
|
||||
#[pagetop::test]
|
||||
async fn getters_return_the_default_until_tracks_are_set() {
|
||||
let grid = Grid::new();
|
||||
assert_eq!(grid.columns(), Responsive::default());
|
||||
assert_eq!(grid.rows(), Responsive::default());
|
||||
|
||||
let tracks = grid::Tracks::repeat(3, grid::AxisTrack::Fraction(1.0));
|
||||
let grid = grid.with_columns(tracks);
|
||||
assert_eq!(grid.columns(), Responsive::default().set(tracks));
|
||||
// Las filas siguen sin definir.
|
||||
assert_eq!(grid.rows(), Responsive::default());
|
||||
}
|
||||
|
||||
// Un clon comparte las pistas hasta que se modifica; entonces cada uno tiene las suyas.
|
||||
#[pagetop::test]
|
||||
async fn a_clone_does_not_share_later_changes() {
|
||||
let three = grid::Tracks::repeat(3, grid::AxisTrack::Fraction(1.0));
|
||||
let two = grid::Tracks::repeat(2, grid::AxisTrack::Fraction(1.0));
|
||||
let original = Grid::new().with_columns(three);
|
||||
let copy = original.clone().with_columns(two).with_rows(two);
|
||||
|
||||
assert_eq!(original.columns(), Responsive::default().set(three));
|
||||
assert_eq!(original.rows(), Responsive::default());
|
||||
assert_eq!(copy.columns(), Responsive::default().set(two));
|
||||
assert_eq!(copy.rows(), Responsive::default().set(two));
|
||||
}
|
||||
|
||||
#[pagetop::test]
|
||||
async fn columns_and_rows_by_breakpoint_are_kept() {
|
||||
let one = grid::Tracks::repeat(1, grid::AxisTrack::Fraction(1.0));
|
||||
let four = grid::Tracks::repeat(4, grid::AxisTrack::Fraction(1.0));
|
||||
let grid = Grid::new()
|
||||
.with_columns(one)
|
||||
.with_columns_at(Breakpoint::Lg, four)
|
||||
.with_rows_at(Breakpoint::Md, one);
|
||||
assert_eq!(
|
||||
grid.columns(),
|
||||
Responsive::default().set(one).set_at(Breakpoint::Lg, four)
|
||||
);
|
||||
assert_eq!(
|
||||
grid.rows(),
|
||||
Responsive::default().set_at(Breakpoint::Md, one)
|
||||
);
|
||||
}
|
||||
63
tests/html_props_layout.rs
Normal file
63
tests/html_props_layout.rs
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
use pagetop::prelude::*;
|
||||
|
||||
// El posicionamiento y el espaciado se guardan aparte para que `Props` (y con él cada componente)
|
||||
// sea pequeño; esta prueba avisa si algo vuelve a inflarlo.
|
||||
#[pagetop::test]
|
||||
async fn props_stays_small() {
|
||||
assert!(
|
||||
std::mem::size_of::<Props>() <= 192,
|
||||
"Props ocupa {} bytes",
|
||||
std::mem::size_of::<Props>()
|
||||
);
|
||||
}
|
||||
|
||||
#[pagetop::test]
|
||||
async fn is_empty_tracks_layout_values() {
|
||||
let props = Props::default();
|
||||
assert!(props.is_empty());
|
||||
|
||||
let with_margin = props
|
||||
.clone()
|
||||
.with_prop(Margin::new().with_top(UnitValue::Zero));
|
||||
assert!(!with_margin.is_empty());
|
||||
let with_padding = Props::default().with_prop(Padding::new().with_x(UnitValue::Px(4)));
|
||||
assert!(!with_padding.is_empty());
|
||||
|
||||
// Un valor por defecto no cuenta como definido.
|
||||
assert!(Props::default().with_prop(Margin::new()).is_empty());
|
||||
assert!(Props::default().with_prop(Padding::new()).is_empty());
|
||||
}
|
||||
|
||||
// Un clon comparte el posicionamiento hasta que se modifica; entonces cada uno tiene el suyo.
|
||||
#[pagetop::test]
|
||||
async fn a_clone_does_not_share_later_changes() {
|
||||
let original = Props::default().with_prop(Margin::new().with_top(UnitValue::RelRem(1.0)));
|
||||
let mut copy = original.clone();
|
||||
copy.alter_prop(Margin::new().with_top(UnitValue::RelRem(2.0)));
|
||||
copy.alter_prop(Padding::new().with_start(UnitValue::Px(3)));
|
||||
|
||||
let mut cx = Context::default();
|
||||
let html_original = html! { span (original.unpack(&mut cx)) {} }.into_string();
|
||||
let html_copy = html! { span (copy.unpack(&mut cx)) {} }.into_string();
|
||||
|
||||
assert!(
|
||||
html_original.contains("_margin-top_1rem_"),
|
||||
"{html_original}"
|
||||
);
|
||||
assert!(!html_original.contains("padding"), "{html_original}");
|
||||
assert!(html_copy.contains("_margin-top_2rem_"), "{html_copy}");
|
||||
assert!(html_copy.contains("_padding-start_3px_"), "{html_copy}");
|
||||
}
|
||||
|
||||
// Todos los tipos de posicionamiento conviven y se emiten en el mismo orden de siempre.
|
||||
#[pagetop::test]
|
||||
async fn layout_kinds_combine_in_the_usual_order() {
|
||||
let props = Props::default()
|
||||
.with_prop(Padding::new().with_top(UnitValue::Zero))
|
||||
.with_prop(Margin::new().with_top(UnitValue::Zero));
|
||||
let mut cx = Context::default();
|
||||
let html = html! { span (props.unpack(&mut cx)) {} }.into_string();
|
||||
let margin = html.find("_margin-top_").expect("margin");
|
||||
let padding = html.find("_padding-top_").expect("padding");
|
||||
assert!(margin < padding, "{html}");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue