- Sustituye `service::test::*` por `web::test::*` (migración de actix-web a
axum).
- Extrae `setup()` en los módulos que sólo renderizan componentes,
evitando levantar un router completo en cada test.
- Elimina los `env::set_var("PAGETOP_RUN_MODE", "test")` manuales, ya
cubiertos por la *feature* `testing`.
99 lines
2.9 KiB
Rust
99 lines
2.9 KiB
Rust
use pagetop::prelude::*;
|
|
|
|
/// Inicializa PageTop (locale, extensiones…) una sola vez para toda la suite.
|
|
///
|
|
/// Los tests de este módulo renderizan componentes directamente con `Context::default()`, por lo
|
|
/// que sólo necesitan el subsistema de localización y las extensiones registradas, no un router.
|
|
fn setup() {
|
|
let _ = Application::new();
|
|
}
|
|
|
|
#[pagetop::test]
|
|
async fn poweredby_default_shows_only_pagetop_recognition() {
|
|
setup();
|
|
|
|
let mut p = PoweredBy::default();
|
|
let html = p.render(&mut Context::default());
|
|
|
|
// Debe mostrar el bloque de reconocimiento a PageTop.
|
|
assert!(html.as_str().contains("poweredby__pagetop"));
|
|
|
|
// Y NO debe mostrar el bloque de copyright.
|
|
assert!(!html.as_str().contains("poweredby__copyright"));
|
|
}
|
|
|
|
#[pagetop::test]
|
|
async fn poweredby_new_includes_current_year_and_app_name() {
|
|
setup();
|
|
|
|
let mut p = PoweredBy::new();
|
|
let html = p.render(&mut Context::default());
|
|
|
|
let year = Utc::now().format("%Y").to_string();
|
|
assert!(
|
|
html.as_str().contains(&year),
|
|
"HTML should include the current year"
|
|
);
|
|
|
|
// El nombre de la app proviene de `global::SETTINGS.app.name`.
|
|
let app_name = &global::SETTINGS.app.name;
|
|
assert!(
|
|
html.as_str().contains(app_name),
|
|
"HTML should include the application name"
|
|
);
|
|
|
|
// Debe existir el span de copyright.
|
|
assert!(html.as_str().contains("poweredby__copyright"));
|
|
}
|
|
|
|
#[pagetop::test]
|
|
async fn poweredby_with_copyright_overrides_text() {
|
|
setup();
|
|
|
|
let custom = "2001 © FooBar Inc.";
|
|
let mut p = PoweredBy::default().with_copyright(Some(custom));
|
|
let html = p.render(&mut Context::default());
|
|
|
|
assert!(html.as_str().contains(custom));
|
|
assert!(html.as_str().contains("poweredby__copyright"));
|
|
}
|
|
|
|
#[pagetop::test]
|
|
async fn poweredby_with_copyright_none_hides_text() {
|
|
setup();
|
|
|
|
let mut p = PoweredBy::new().with_copyright(None::<String>);
|
|
let html = p.render(&mut Context::default());
|
|
|
|
assert!(!html.as_str().contains("poweredby__copyright"));
|
|
// El reconocimiento a PageTop siempre debe aparecer.
|
|
assert!(html.as_str().contains("poweredby__pagetop"));
|
|
}
|
|
|
|
#[pagetop::test]
|
|
async fn poweredby_link_points_to_crates_io() {
|
|
setup();
|
|
|
|
let mut p = PoweredBy::default();
|
|
let html = p.render(&mut Context::default());
|
|
|
|
assert!(
|
|
html.as_str().contains("https://pagetop.cillero.es"),
|
|
"Link should point to pagetop.cillero.es"
|
|
);
|
|
}
|
|
|
|
#[pagetop::test]
|
|
async fn poweredby_getter_reflects_internal_state() {
|
|
setup();
|
|
|
|
// Por defecto no hay copyright.
|
|
let p0 = PoweredBy::default();
|
|
assert_eq!(p0.copyright(), None);
|
|
|
|
// Y `new()` lo inicializa con año + nombre de app.
|
|
let p1 = PoweredBy::new();
|
|
let c1 = p1.copyright().expect("Expected copyright to exist");
|
|
assert!(c1.contains(&Utc::now().format("%Y").to_string()));
|
|
assert!(c1.contains(&global::SETTINGS.app.name));
|
|
}
|