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
+8 -21
View File
@@ -5,7 +5,7 @@ pub mod ui {}
mod tests {
use super::ui;
use hemplate::Hemplate;
use slhx::{push, Effect, IntoEffect, NavigateMode, Payload, SafeHtml};
use slhx::{push, Effect, IntoEffect, NavigateMode, Payload, RenderKeyedSlotExt, RenderSlotExt};
use slhx_test::inspect;
#[derive(Clone, Debug)]
@@ -77,7 +77,10 @@ mod tests {
fn todos_append_keyed_rows_from_form_input() {
fn add_todo(input: TodoInput) -> impl IntoEffect {
let todo = Todo { id: 7, title: input.title };
ui::slots::todo_row.append_html(todo.id.to_string(), render_todo_row(&todo))
ui::slots::todo_row.append_view(
todo.id.to_string(),
&TodoRow { title: todo.title },
)
}
let effect = inspect(add_todo(TodoInput { title: "Ship v0".into() }));
@@ -86,15 +89,6 @@ mod tests {
assert!(matches!(effect.ops(), [Effect::Insert { key, payload, .. }] if key == "7" && matches!(payload, Payload::Html(_))));
}
fn render_todo_row(todo: &Todo) -> SafeHtml {
// req: html_safety/002 req: view/001
let mut html = String::new();
TodoRow { title: todo.title.clone() }
.render_into(&mut html)
.expect("v0 todo row renders");
SafeHtml::trusted(html)
}
// req: examples/001 req: form/001 req: form/004 req: form/006 req: derive_handler/003
#[test]
fn wizard_form_handler_is_checked_against_hemplate_form() {
@@ -127,7 +121,9 @@ mod tests {
fn page_swap_updates_content_and_history() {
fn load_docs() -> impl IntoEffect {
(
ui::slots::content.html(render_docs_content("This page was swapped.")),
ui::slots::content.render_view(&DocsContent {
message: "This page was swapped.",
}),
ui::slots::title.text("Docs"),
push("/docs"),
)
@@ -141,15 +137,6 @@ mod tests {
assert!(matches!(effect.ops().last(), Some(Effect::Navigate { url, mode: NavigateMode::Push, .. }) if url == "/docs"));
}
fn render_docs_content(message: &'static str) -> SafeHtml {
// req: html_safety/002 req: view/001
let mut html = String::new();
DocsContent { message }
.render_into(&mut html)
.expect("v0 docs content renders");
SafeHtml::trusted(html)
}
// req: examples/001 req: form/001 req: form/004 req: form/006 req: derive_handler/003
#[test]
fn auth_form_handler_is_checked_against_hemplate_form() {
+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);