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
This commit is contained in:
@@ -21,11 +21,13 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
#[slhx::form("wizard_input")]
|
||||||
struct WizardInput {
|
struct WizardInput {
|
||||||
step: u8,
|
step: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
#[slhx::form("credentials")]
|
||||||
struct Credentials {
|
struct Credentials {
|
||||||
email: String,
|
email: String,
|
||||||
password: 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<WizardInput>) -> impl IntoEffect {
|
||||||
|
ui::slots::wizard_step.text("queued")
|
||||||
|
}
|
||||||
|
|
||||||
|
let effect = inspect(next_step(ui::forms::wizard_input.typed::<WizardInput>()));
|
||||||
|
|
||||||
|
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
|
// req: examples/001 req: progressive_disclosure/001 req: build/001 req: build/005 req: codegen/004
|
||||||
#[test]
|
#[test]
|
||||||
fn wizard_form_swaps_the_current_step() {
|
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<Credentials>) -> impl IntoEffect {
|
||||||
|
ui::slots::login_status.text("queued")
|
||||||
|
}
|
||||||
|
|
||||||
|
let effect = inspect(login(ui::forms::credentials.typed::<Credentials>()));
|
||||||
|
|
||||||
|
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
|
// req: examples/001 req: progressive_disclosure/001 req: build/001 req: build/005 req: codegen/004
|
||||||
#[test]
|
#[test]
|
||||||
fn auth_flow_reads_typed_input_and_updates_status() {
|
fn auth_flow_reads_typed_input_and_updates_status() {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<section data-slhx-root="auth">
|
<section data-slhx-root="auth">
|
||||||
<form data-slhx-handle="login" data-slhx-form="credentials">
|
<form data-slhx-handle="login" data-slhx-form="credentials">
|
||||||
<input name="email" type="email" autocomplete="username">
|
<input name="email" type="email" autocomplete="username" required>
|
||||||
<input name="password" type="password" autocomplete="current-password">
|
<input name="password" type="password" autocomplete="current-password" required>
|
||||||
<button type="submit">Sign in</button>
|
<button type="submit">Sign in</button>
|
||||||
</form>
|
</form>
|
||||||
<p data-slhx-slot="login_status">Signed out</p>
|
<p data-slhx-slot="login_status">Signed out</p>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<section data-slhx-root="wizard">
|
<section data-slhx-root="wizard">
|
||||||
<form data-slhx-handle="next_step" data-slhx-form="wizard_input">
|
<form data-slhx-handle="next_step" data-slhx-form="wizard_input">
|
||||||
|
<input type="hidden" name="step" value="1" required>
|
||||||
<div data-slhx-slot="wizard_step">Step 1</div>
|
<div data-slhx-slot="wizard_step">Step 1</div>
|
||||||
<button type="submit">Next</button>
|
<button type="submit">Next</button>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
Reference in New Issue
Block a user