✨ Detecta errores de programación en desarrollo
Añade comprobaciones sin coste en producción:
- Falla con `debug_assert!` si `param_or*`/`extra_or*` piden otro tipo,
si `form:📅:Field` recibe un valor de otro tipo, si `grid::Tracks`
supera MAX_TRACKS o si `TestRequest::header()` recibe una cabecera
no válida.
- Avisa en desarrollo de las traducciones ausentes y, al arrancar, de
las claves de permiso repetidas.
- Corrige en Bootsier el título por defecto de los desplegables y los
botones de confirmación, que salían siempre en inglés. Evita también
el aviso de import sin usar en release de `core/extension/all.rs`.
This commit is contained in:
parent
c7888c85ac
commit
f9ab1f55a3
18 changed files with 203 additions and 49 deletions
|
|
@ -70,9 +70,17 @@ async fn text_is_shown_as_written_and_empty_fields_have_no_value() {
|
|||
}
|
||||
|
||||
#[pagetop::test]
|
||||
async fn a_value_of_another_kind_is_ignored() {
|
||||
#[should_panic(expected = "needs a field created with")]
|
||||
async fn a_value_of_another_kind_is_an_error() {
|
||||
let date = NaiveDate::from_ymd_opt(2026, 10, 6).unwrap();
|
||||
let mut field = form::date::Field::time().with_name("at").with_date(date);
|
||||
let _ = form::date::Field::time().with_date(date);
|
||||
}
|
||||
|
||||
#[pagetop::test]
|
||||
async fn no_value_is_valid_for_any_kind() {
|
||||
let mut field = form::date::Field::time()
|
||||
.with_name("at")
|
||||
.with_date(None::<NaiveDate>);
|
||||
let html = field.render(&mut cx("es-ES", "UTC")).await.into_string();
|
||||
assert!(!html.contains("value="));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -221,3 +221,16 @@ async fn grid_breakpoints_add_their_suffix_and_wrap_rules_in_media_queries() {
|
|||
assert!(assets.contains("@media(min-width:768px){._grid_md_{display:grid}}"));
|
||||
assert!(assets.contains("@media(min-width:992px){._grid-columns_1fr-1fr-1fr_lg_"));
|
||||
}
|
||||
|
||||
#[pagetop::test]
|
||||
#[should_panic(expected = "up to 12 tracks")]
|
||||
async fn repeating_more_tracks_than_allowed_is_an_error() {
|
||||
let _ = grid::Tracks::repeat(grid::MAX_TRACKS + 1, grid::AxisTrack::Fraction(1.0));
|
||||
}
|
||||
|
||||
#[pagetop::test]
|
||||
#[should_panic(expected = "up to 12 tracks")]
|
||||
async fn adding_more_tracks_than_allowed_is_an_error() {
|
||||
let track = grid::AxisTrack::Fraction(1.0);
|
||||
let _ = grid::Tracks::repeat(grid::MAX_TRACKS, track).with_track(track);
|
||||
}
|
||||
|
|
|
|||
14
tests/context_params.rs
Normal file
14
tests/context_params.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
use pagetop::prelude::*;
|
||||
|
||||
#[pagetop::test]
|
||||
#[should_panic(expected = "type mismatch")]
|
||||
async fn a_param_of_another_type_is_an_error() {
|
||||
let cx = Context::default().with_param("count", 7_i32);
|
||||
let _ = cx.param_or("count", 0_u32);
|
||||
}
|
||||
|
||||
#[pagetop::test]
|
||||
async fn a_missing_param_gets_the_default() {
|
||||
let cx = Context::default();
|
||||
assert_eq!(cx.param_or("count", 3_u32), 3);
|
||||
}
|
||||
|
|
@ -62,9 +62,10 @@ async fn extra_or_returns_default_on_missing() {
|
|||
}
|
||||
|
||||
#[pagetop::test]
|
||||
async fn extra_or_returns_default_on_type_mismatch() {
|
||||
#[should_panic(expected = "type mismatch")]
|
||||
async fn extra_or_fails_on_type_mismatch() {
|
||||
let props = Props::default().with_prop(PropsOp::set_extra("ext.flag", true));
|
||||
assert_eq!(props.extra_or("ext.flag", 0_u32), 0_u32);
|
||||
let _ = props.extra_or("ext.flag", 0_u32);
|
||||
}
|
||||
|
||||
// **< Props::extra_or_default >********************************************************************
|
||||
|
|
|
|||
|
|
@ -77,3 +77,9 @@ async fn http_request_exposes_the_method() {
|
|||
assert_eq!(request.method(), web::http::Method::POST);
|
||||
assert!(!request.method().is_safe());
|
||||
}
|
||||
|
||||
#[pagetop::test]
|
||||
#[should_panic(expected = "invalid header")]
|
||||
async fn an_invalid_header_is_an_error() {
|
||||
let _ = web::test::TestRequest::get().header("bad name", "value");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue