test(html-examples): make lazy load visibly update

Show a server-update count in the lazy panel so manual clicks have an observable change, and strengthen the browser smoke to assert the panel text changes.

req: examples/001

req: htmx_equivalents/005

req: test/006
This commit is contained in:
slhx agent
2026-06-25 14:51:01 +02:00
parent a667113dc0
commit ad7eea6f67
2 changed files with 17 additions and 12 deletions
+16 -11
View File
@@ -20,7 +20,7 @@ struct GalleryState {
rows: Mutex<Vec<RowRecord>>,
loaded_count: Mutex<usize>,
infinite_count: Mutex<usize>,
lazy_loaded: Mutex<bool>,
lazy_loads: Mutex<usize>,
progress: Mutex<u8>,
email: Mutex<String>,
email_status: Mutex<String>,
@@ -263,7 +263,7 @@ impl GalleryState {
]),
loaded_count: Mutex::new(2),
infinite_count: Mutex::new(3),
lazy_loaded: Mutex::new(false),
lazy_loads: Mutex::new(0),
progress: Mutex::new(0),
email: Mutex::new(String::new()),
email_status: Mutex::new("Waiting for an email".into()),
@@ -331,7 +331,7 @@ fn gallery_view(state: &GalleryState) -> Gallery {
.collect();
let loaded_count = *state.loaded_count.lock().unwrap();
let infinite_count = *state.infinite_count.lock().unwrap();
let lazy_loaded = *state.lazy_loaded.lock().unwrap();
let lazy_loads = *state.lazy_loads.lock().unwrap();
let progress = *state.progress.lock().unwrap();
let email = state.email.lock().unwrap().clone();
let email_status = state.email_status.lock().unwrap().clone();
@@ -343,11 +343,7 @@ fn gallery_view(state: &GalleryState) -> Gallery {
Gallery {
contacts,
rows,
lazy_panel: if lazy_loaded {
"Lazy content loaded".into()
} else {
"Waiting to be revealed".into()
},
lazy_panel: lazy_panel_text(lazy_loads),
loaded_rows: loaded_rows(loaded_count),
load_status: format!("Showing {loaded_count} rows"),
infinite_rows: loaded_rows(infinite_count),
@@ -368,6 +364,14 @@ fn gallery_view(state: &GalleryState) -> Gallery {
}
}
fn lazy_panel_text(loads: usize) -> String {
if loads == 0 {
"Waiting to be revealed".into()
} else {
format!("Lazy content loaded by server update #{loads}")
}
}
fn contact_card_view(record: ContactRecord) -> ContactCard {
ContactCard {
id: Id(record.id),
@@ -434,8 +438,9 @@ mod gallery_handlers {
Form(input): Form<LazyLoad>,
) -> impl IntoEffect {
let _ = input.request;
*state.lazy_loaded.lock().unwrap() = true;
gallery::lazy_panel.set("Lazy content loaded")
let mut lazy_loads = state.lazy_loads.lock().unwrap();
*lazy_loads += 1;
gallery::lazy_panel.set(lazy_panel_text(*lazy_loads))
}
#[hemx::handler]
@@ -805,7 +810,7 @@ mod tests {
.batch,
);
assert!(lazy.updates_text(gallery::lazy_panel));
assert!(lazy.payload_contains("Lazy content loaded"));
assert!(lazy.payload_contains("Lazy content loaded by server update #1"));
let more = inspect_batch(
InteractionRequest::from(form(gallery::load_more, &[("request", "more")]))