#[cfg(test)] mod advanced_form_workflow_tests { use leptos::prelude::*; use wasm_bindgen_test::*; use web_sys; use crate::default::{Button, Input, Card, CardHeader, CardTitle, CardContent, Badge, Checkbox, RadioGroup, Select, Textarea, Progress}; wasm_bindgen_test_configure!(run_in_browser); #[derive(Debug, Clone, PartialEq)] enum FormStep { PersonalInfo, Preferences, Review, Confirmation, } #[derive(Debug, Clone)] struct PersonalInfo { first_name: String, last_name: String, email: String, phone: String, } #[derive(Debug, Clone)] struct Preferences { newsletter: bool, notifications: bool, theme: String, language: String, } #[wasm_bindgen_test] fn test_multi_step_form_workflow() { let current_step = RwSignal::new(FormStep::PersonalInfo); let personal_info = RwSignal::new(PersonalInfo { first_name: String::new(), last_name: String::new(), email: String::new(), phone: String::new(), }); let preferences = RwSignal::new(Preferences { newsletter: false, notifications: true, theme: "light".to_string(), language: "en".to_string(), }); let form_errors = RwSignal::new(Vec::::new()); let is_submitting = RwSignal::new(false); let steps = vec![ ("Personal Info", FormStep::PersonalInfo), ("Preferences", FormStep::Preferences), ("Review", FormStep::Review), ("Confirmation", FormStep::Confirmation), ]; mount_to_body(move || { let step_index = steps.iter().position(|(_, step)| *step == current_step.get()).unwrap_or(0); let progress = (step_index as f64 / (steps.len() - 1) as f64) * 100.0; view! {

"User Registration"

{for steps.iter().enumerate().map(|(index, (name, step))| { let step = step.clone(); let current_step = current_step.clone(); let is_active = *step == current_step.get(); let is_completed = index < step_index; view! {
{index + 1} {name}
} })}
{match current_step.get() { FormStep::PersonalInfo => view! { "Personal Information"
}, FormStep::Preferences => view! { "Preferences"
}, FormStep::Review => view! { "Review Information"

"Personal Information"

{format!("Name: {} {}", personal_info.get().first_name, personal_info.get().last_name)}

{format!("Email: {}", personal_info.get().email)}

{format!("Phone: {}", personal_info.get().phone)}

"Preferences"

{format!("Newsletter: {}", if preferences.get().newsletter { "Yes" } else { "No" })}

{format!("Notifications: {}", if preferences.get().notifications { "Yes" } else { "No" })}

{format!("Theme: {}", preferences.get().theme)}

}, FormStep::Confirmation => view! { "Registration Complete!"

"Welcome, {}!"

"Your account has been created successfully."

"You will receive a confirmation email shortly."

}, }}
{if matches!(current_step.get(), FormStep::PersonalInfo) { view! {
} } else { view! { } }} {if matches!(current_step.get(), FormStep::Confirmation) { view! {
} } else { view! { } }}
{if !form_errors.get().is_empty() { view! {
{for form_errors.get().iter().map(|error| { view! {
{error.clone()}
} })}
} } else { view! {
} }}
} }); let document = web_sys::window().unwrap().document().unwrap(); // Test form progression let next_button = document.query_selector("button").unwrap().unwrap() .unchecked_into::(); if next_button.text_content().unwrap().contains("Next") { next_button.click(); } // Verify step progression let step_indicators = document.query_selector_all(".step").unwrap(); assert!(step_indicators.length() > 0, "Step indicators should be displayed"); // Test form completion let next_buttons = document.query_selector_all("button").unwrap(); for i in 0..next_buttons.length() { let button = next_buttons.item(i).unwrap().unchecked_into::(); if button.text_content().unwrap().contains("Next") { button.click(); break; } } // Verify final confirmation let confirmation = document.query_selector(".confirmation-message").unwrap(); assert!(confirmation.is_some(), "Confirmation message should appear after form completion"); } }