//! Tests for el-platform backends. #[cfg(test)] mod tests { use crate::{ backend_for, backends::{server::ServerBackend, web::WebBackend}, config::{PlatformConfig, PlatformTarget}, node::PlatformNode, PlatformBackend, }; // ── Test 1: PlatformTarget::from_str parses all targets ────────────────── #[test] fn test_platform_target_from_str() { assert_eq!(PlatformTarget::from_str("web"), Some(PlatformTarget::Web)); assert_eq!(PlatformTarget::from_str("server"), Some(PlatformTarget::Server)); assert_eq!(PlatformTarget::from_str("ios"), Some(PlatformTarget::Ios)); assert_eq!(PlatformTarget::from_str("android"), Some(PlatformTarget::Android)); assert_eq!(PlatformTarget::from_str("macos"), Some(PlatformTarget::Macos)); assert_eq!(PlatformTarget::from_str("linux"), Some(PlatformTarget::Linux)); assert_eq!(PlatformTarget::from_str("windows"), Some(PlatformTarget::Windows)); assert_eq!(PlatformTarget::from_str("unknown"), None); } // ── Test 2: PlatformTarget::as_str round-trips ─────────────────────────── #[test] fn test_platform_target_as_str() { assert_eq!(PlatformTarget::Web.as_str(), "web"); assert_eq!(PlatformTarget::Server.as_str(), "server"); assert_eq!(PlatformTarget::Ios.as_str(), "ios"); } // ── Test 3: is_native() identifies native targets ──────────────────────── #[test] fn test_is_native() { assert!(!PlatformTarget::Web.is_native()); assert!(!PlatformTarget::Server.is_native()); assert!(PlatformTarget::Ios.is_native()); assert!(PlatformTarget::Android.is_native()); assert!(PlatformTarget::Macos.is_native()); assert!(PlatformTarget::Linux.is_native()); assert!(PlatformTarget::Windows.is_native()); } // ── Test 4: PlatformConfig defaults to web ─────────────────────────────── #[test] fn test_platform_config_default() { let cfg = PlatformConfig::default(); assert_eq!(cfg.target, PlatformTarget::Web); assert!(!cfg.ssr); } // ── Test 5: PlatformConfig with_ssr ────────────────────────────────────── #[test] fn test_platform_config_with_ssr() { let cfg = PlatformConfig::new(PlatformTarget::Server).with_ssr(true); assert_eq!(cfg.target, PlatformTarget::Server); assert!(cfg.ssr); } // ── Test 6: WebBackend renders element to HTML ─────────────────────────── #[test] fn test_web_backend_renders_element() { let backend = WebBackend::new(); let mut div = backend.create_element("div").unwrap(); backend.set_attribute(&mut div, "class", "container").unwrap(); backend.append_child(&mut div, backend.create_text("Hello").unwrap()).unwrap(); let html = backend.render_to_string(&div).unwrap(); assert!(html.contains("