From 1b255e593dddbcfa9355e08de991c24c9361c0f1 Mon Sep 17 00:00:00 2001 From: slhx agent Date: Mon, 25 May 2026 23:59:24 +0200 Subject: [PATCH] test(v0): check auth and wizard form handlers Annotate the v0 auth and wizard form models with #[slhx::form], make their templates expose checked form fields, and add handler smoke tests over the generated form resources. req: form/001 req: form/004 req: form/006 req: derive_handler/003 --- examples/v0/src/lib.rs | 30 ++++++++++++++++++++++++++++++ examples/v0/templates/auth.heml | 4 ++-- examples/v0/templates/wizard.heml | 1 + 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/examples/v0/src/lib.rs b/examples/v0/src/lib.rs index a049eaa..e172083 100644 --- a/examples/v0/src/lib.rs +++ b/examples/v0/src/lib.rs @@ -21,11 +21,13 @@ mod tests { } #[derive(Clone, Debug)] + #[slhx::form("wizard_input")] struct WizardInput { step: u8, } #[derive(Clone, Debug)] + #[slhx::form("credentials")] struct Credentials { email: String, password: String, @@ -93,6 +95,20 @@ mod tests { ) } + // 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() { + #[slhx::handler] + fn next_step(_form: slhx::Form) -> impl IntoEffect { + ui::slots::wizard_step.text("queued") + } + + let effect = inspect(next_step(ui::forms::wizard_input.typed::())); + + assert!(effect.has_slot(ui::slots::wizard_step)); + assert!(matches!(effect.ops(), [Effect::Put { payload: Payload::Text(_), .. }])); + } + // req: examples/001 req: progressive_disclosure/001 req: build/001 req: build/005 req: codegen/004 #[test] fn wizard_form_swaps_the_current_step() { @@ -134,6 +150,20 @@ mod tests { ) } + // 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() { + #[slhx::handler] + fn login(_form: slhx::Form) -> impl IntoEffect { + ui::slots::login_status.text("queued") + } + + let effect = inspect(login(ui::forms::credentials.typed::())); + + assert!(effect.has_slot(ui::slots::login_status)); + assert!(matches!(effect.ops(), [Effect::Put { payload: Payload::Text(_), .. }])); + } + // req: examples/001 req: progressive_disclosure/001 req: build/001 req: build/005 req: codegen/004 #[test] fn auth_flow_reads_typed_input_and_updates_status() { diff --git a/examples/v0/templates/auth.heml b/examples/v0/templates/auth.heml index a8861ee..f3fd9a5 100644 --- a/examples/v0/templates/auth.heml +++ b/examples/v0/templates/auth.heml @@ -1,7 +1,7 @@
- - + +

Signed out

diff --git a/examples/v0/templates/wizard.heml b/examples/v0/templates/wizard.heml index 51c6825..aff1585 100644 --- a/examples/v0/templates/wizard.heml +++ b/examples/v0/templates/wizard.heml @@ -1,5 +1,6 @@
+
Step 1