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:
+8
-21
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user