test(v0): render slots from hemplate views

Migrate v0 handlers and tests from explicit SafeHtml/html payload plumbing to RenderSlotExt and RenderKeyedSlotExt view helpers.

req: view/001

req: html_safety/002
This commit is contained in:
slhx agent
2026-05-26 00:58:29 +02:00
parent b6ecb9513c
commit 852053fd04
2 changed files with 18 additions and 31 deletions
+10 -10
View File
@@ -4,7 +4,7 @@ use axum::routing::get;
use axum::Router;
use futures_util::{stream, StreamExt};
use hemplate::Hemplate;
use slhx::{push, IntoEffect, SafeHtml};
use slhx::{push, IntoEffect, RenderSlotExt, SafeHtml};
use slhx_axum::{runtime_js, sse, EffectResponse, HandlerRegistry, InteractionForm, PageRequest};
use slhx_v0_examples::ui;
use std::collections::BTreeMap;
@@ -136,7 +136,7 @@ fn registry(state: Arc<ExampleState>) -> HandlerRegistry {
todos.push(Todo { id, title: title.into() });
}
(
ui::todos::slots::todo_list.html(render_todos(&todos)),
ui::todos::slots::todo_list.render_view(&todos_view(&todos)),
ui::todos::forms::new_todo.clear("title"),
)
}
@@ -163,9 +163,9 @@ fn registry(state: Arc<ExampleState>) -> HandlerRegistry {
.register_handle(ui::page_swap::handles::load_docs, |_| {
// req: page_swap/002, req: examples/001
(
ui::page_swap::slots::content.html(render_docs_content(
"This content came from an EffectBatch.",
)),
ui::page_swap::slots::content.render_view(&DocsContent {
message: "This content came from an EffectBatch.",
}),
ui::page_swap::slots::title.text("Docs"),
push("/docs"),
)
@@ -191,9 +191,9 @@ fn shell(body: String) -> String {
})
}
fn render_todos(todos: &[Todo]) -> SafeHtml {
fn todos_view(todos: &[Todo]) -> TodoItems {
// req: html_safety/002 req: view/001
render_html(&TodoItems {
TodoItems {
items: todos
.iter()
.map(|todo| TodoItem {
@@ -201,7 +201,7 @@ fn render_todos(todos: &[Todo]) -> SafeHtml {
title: todo.title.clone(),
})
.collect(),
})
}
}
fn render_page_swap(title: &'static str, message: &'static str) -> String {
@@ -300,7 +300,7 @@ mod tests {
fn todos_payload_is_rendered_by_a_hemplate_view() {
let todos = vec![Todo { id: 7, title: "<b>Ship v0</b>".to_owned() }];
let html = render_todos(&todos);
let html = slhx::render_html(&todos_view(&todos));
let document = Html::parse_fragment(html.as_str());
let rows = document.select(&selector("li[data-key]")).collect::<Vec<_>>();
assert_eq!(rows.len(), 1);
@@ -312,7 +312,7 @@ mod tests {
// req: html_safety/002 req: view/001 req: test/005
#[test]
fn empty_todos_payload_is_rendered_by_a_hemplate_view() {
let html = render_todos(&[]);
let html = slhx::render_html(&todos_view(&[]));
let document = Html::parse_fragment(html.as_str());
let rows = document.select(&selector("li")).collect::<Vec<_>>();
assert_eq!(rows.len(), 1);