♻️ (locale): Sustituye Attr<Lc> por Lc::none()

This commit is contained in:
Manuel Cillero 2026-08-17 03:16:49 +02:00
parent c3ff8a6ff8
commit 213aa18b12
17 changed files with 275 additions and 146 deletions

45
tests/component_button.rs Normal file
View file

@ -0,0 +1,45 @@
use pagetop::prelude::*;
#[pagetop::test]
async fn label_is_rendered_when_set() {
let mut button = Button::submit(Lc::n("Save"));
let html = button.render(&mut Context::default()).await.into_string();
assert!(html.contains("Save"));
}
#[pagetop::test]
async fn label_can_be_cleared_with_lc_none() {
let mut button = Button::submit(Lc::n("Save")).with_label(Lc::none());
let html = button.render(&mut Context::default()).await.into_string();
assert!(!html.contains("Save"));
// The button itself must still render.
assert!(html.contains("<button"));
}
#[pagetop::test]
async fn title_attribute_is_absent_by_default() {
let mut button = Button::submit(Lc::n("Save"));
let html = button.render(&mut Context::default()).await.into_string();
assert!(!html.contains("title="));
}
#[pagetop::test]
async fn title_attribute_is_present_when_set() {
let mut button = Button::submit(Lc::n("Save")).with_title(Lc::n("Save changes"));
let html = button.render(&mut Context::default()).await.into_string();
assert!(html.contains(r#"title="Save changes""#));
}
#[pagetop::test]
async fn title_attribute_can_be_cleared_with_lc_none() {
let mut button = Button::submit(Lc::n("Save"))
.with_title(Lc::n("Save changes"))
.with_title(Lc::none());
let html = button.render(&mut Context::default()).await.into_string();
assert!(!html.contains("title="));
}

View file

@ -0,0 +1,72 @@
use pagetop::prelude::*;
#[pagetop::test]
async fn label_is_absent_by_default() {
let mut field = form::input::Field::text();
let html = field.render(&mut Context::default()).await.into_string();
assert!(!html.contains(r#"class="form-label""#));
}
#[pagetop::test]
async fn label_is_rendered_when_set() {
let mut field = form::input::Field::text().with_label(Lc::n("Full name"));
let html = field.render(&mut Context::default()).await.into_string();
assert!(html.contains(r#"class="form-label""#));
assert!(html.contains("Full name"));
}
#[pagetop::test]
async fn label_can_be_cleared_with_lc_none() {
let mut field = form::input::Field::text()
.with_label(Lc::n("Full name"))
.with_label(Lc::none());
let html = field.render(&mut Context::default()).await.into_string();
assert!(!html.contains(r#"class="form-label""#));
assert!(!html.contains("Full name"));
}
#[pagetop::test]
async fn help_text_is_absent_by_default() {
let mut field = form::input::Field::text();
let html = field.render(&mut Context::default()).await.into_string();
assert!(!html.contains(r#"class="form-text""#));
}
#[pagetop::test]
async fn help_text_is_rendered_when_set() {
let mut field = form::input::Field::text().with_help_text(Lc::n("We never share your data."));
let html = field.render(&mut Context::default()).await.into_string();
assert!(html.contains(r#"class="form-text""#));
assert!(html.contains("We never share your data."));
}
#[pagetop::test]
async fn placeholder_attribute_is_absent_by_default() {
let mut field = form::input::Field::text();
let html = field.render(&mut Context::default()).await.into_string();
assert!(!html.contains("placeholder="));
}
#[pagetop::test]
async fn placeholder_attribute_is_present_when_set() {
let mut field = form::input::Field::text().with_placeholder(Lc::n("Enter your name"));
let html = field.render(&mut Context::default()).await.into_string();
assert!(html.contains(r#"placeholder="Enter your name""#));
}
#[pagetop::test]
async fn placeholder_attribute_can_be_cleared_with_lc_none() {
let mut field = form::input::Field::text()
.with_placeholder(Lc::n("Enter your name"))
.with_placeholder(Lc::none());
let html = field.render(&mut Context::default()).await.into_string();
assert!(!html.contains("placeholder="));
}

38
tests/response_page.rs Normal file
View file

@ -0,0 +1,38 @@
use pagetop::prelude::*;
fn request() -> HttpRequest {
web::test::TestRequest::get().to_http_request()
}
#[pagetop::test]
async fn title_and_description_are_absent_by_default() {
let page = Page::new(request());
assert_eq!(page.title(), None);
assert_eq!(page.description(), None);
}
#[pagetop::test]
async fn title_and_description_reflect_the_values_set() {
let page = Page::new(request())
.with_title(Lc::n("Dashboard"))
.with_description(Lc::n("Overview of recent activity"));
assert_eq!(page.title(), Some("Dashboard".to_string()));
assert_eq!(
page.description(),
Some("Overview of recent activity".to_string())
);
}
#[pagetop::test]
async fn lc_none_clears_a_previously_set_title_and_description() {
let page = Page::new(request())
.with_title(Lc::n("Dashboard"))
.with_description(Lc::n("Overview of recent activity"))
.with_title(Lc::none())
.with_description(Lc::none());
assert_eq!(page.title(), None);
assert_eq!(page.description(), None);
}