test(techdemo): exercise checked form handler path
Add techdemo coverage for #[slhx::form] plus #[slhx::handler] on the generated launch_work form, and ignore the internal __h hidden handle field in generated form metadata. req: form/001 req: form/004 req: form/006 req: derive_handler/003
This commit is contained in:
@@ -5,7 +5,7 @@ pub mod ui {}
|
||||
mod tests {
|
||||
use super::ui;
|
||||
use hemplate::Hemplate;
|
||||
use slhx::{IntoEffect, SafeHtml};
|
||||
use slhx::{Effect, IntoEffect, Payload, SafeHtml};
|
||||
use slhx_test::inspect;
|
||||
|
||||
#[derive(Hemplate)]
|
||||
@@ -14,6 +14,15 @@ mod tests {
|
||||
label: &'static str,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Clone, Debug)]
|
||||
#[slhx::form("launch_work")]
|
||||
struct LaunchWork {
|
||||
title: String,
|
||||
lane: String,
|
||||
impact: Option<u8>,
|
||||
}
|
||||
|
||||
// req: examples/001 req: codegen/002 req: public_api/001
|
||||
#[test]
|
||||
fn techdemo_uses_generated_slots_for_multi_target_updates() {
|
||||
@@ -38,6 +47,22 @@ mod tests {
|
||||
)
|
||||
}
|
||||
|
||||
// req: examples/001 req: form/001 req: form/004 req: form/006 req: derive_handler/003
|
||||
#[test]
|
||||
fn techdemo_form_handler_is_checked_against_hemplate_form() {
|
||||
#[slhx::handler]
|
||||
fn launch_work(_form: slhx::Form<LaunchWork>) -> impl IntoEffect {
|
||||
ui::control_center::slots::notice.text("queued")
|
||||
}
|
||||
|
||||
let batch = inspect(launch_work(
|
||||
ui::control_center::forms::launch_work.typed::<LaunchWork>(),
|
||||
));
|
||||
|
||||
assert!(batch.has_slot(ui::control_center::slots::notice));
|
||||
assert!(matches!(batch.ops(), [Effect::Put { payload: Payload::Text(_), .. }]));
|
||||
}
|
||||
|
||||
// req: examples/001 req: form/002 req: codegen/003
|
||||
#[test]
|
||||
fn techdemo_exports_form_and_interaction_handles() {
|
||||
|
||||
@@ -276,6 +276,10 @@ impl Resources {
|
||||
component: String,
|
||||
controls: Vec<GeneratedControl>,
|
||||
) -> io::Result<()> {
|
||||
let controls = controls
|
||||
.into_iter()
|
||||
.filter(|control| control.name != "__h")
|
||||
.collect();
|
||||
let resource = make_resource("form", symbol, name, component, false)?;
|
||||
match self.forms.get(&resource.ident) {
|
||||
Some(existing) if existing.resource.symbol != resource.symbol => Err(io::Error::new(
|
||||
@@ -1062,6 +1066,7 @@ mod tests {
|
||||
std::fs::write(
|
||||
templates.join("profile.heml"),
|
||||
r#"<form data-slhx-handle="save" data-slhx-form="profile">
|
||||
<input type="hidden" name="__h" value="123">
|
||||
<input name="title" required>
|
||||
<input name="count" type="number" min="1" max="10" step="1">
|
||||
<select name="labels" multiple></select>
|
||||
@@ -1090,6 +1095,7 @@ mod tests {
|
||||
|
||||
let syms = std::fs::read_to_string(out.join("slhx.syms")).unwrap();
|
||||
assert!(syms.contains("handle_form\tsave\tprofile\n"));
|
||||
assert!(!syms.contains("form_field\tprofile\t__h\t"));
|
||||
assert!(syms.contains("form_field\tprofile\ttitle\ttrue\tfalse\n"));
|
||||
assert!(syms.contains("form_field\tprofile\tlabels\tfalse\ttrue\n"));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user