tailwind_rs_testing/
lib.rs

1//! # tailwind-rs-testing
2//!
3//! Testing utilities for the tailwind-rs library.
4//! This crate provides tools for testing Tailwind CSS integration in Rust applications.
5
6pub mod class_testing;
7pub mod component_testing;
8pub mod mock_components;
9pub mod responsive_testing;
10pub mod theme_testing;
11
12#[cfg(test)]
13mod property_tests;
14
15#[cfg(test)]
16mod framework_integration_tests;
17
18#[cfg(test)]
19mod api_stability_tests;
20
21// Re-export commonly used testing utilities
22pub use class_testing::{
23    ClassTestResult, assert_classes_contain, assert_classes_not_contain, test_classes,
24};
25pub use component_testing::{TestApp, create_test_app, extract_classes, render_to_string};
26pub use mock_components::{MockComponent, create_mock_component};
27pub use responsive_testing::{ResponsiveTestResult, assert_responsive_value};
28pub use theme_testing::{ThemeTestResult, assert_theme_value};
29
30/// Initialize the testing environment
31pub fn init_test_env() {
32    #[cfg(target_arch = "wasm32")]
33    {
34        console_error_panic_hook::set_once();
35        console_log::init_with_level(log::Level::Info).expect("Failed to initialize console_log");
36    }
37}
38
39/// Test configuration for tailwind-rs testing
40#[derive(Debug, Clone, Default)]
41pub struct TestConfig {
42    pub theme: Option<String>,
43    pub breakpoint: Option<String>,
44    pub dark_mode: bool,
45    pub custom_css: Vec<String>,
46}
47
48/// Test result for tailwind-rs operations
49#[derive(Debug, Clone)]
50pub struct TestResult {
51    pub success: bool,
52    pub message: String,
53    pub details: Option<String>,
54}
55
56impl TestResult {
57    pub fn success(message: impl Into<String>) -> Self {
58        Self {
59            success: true,
60            message: message.into(),
61            details: None,
62        }
63    }
64
65    pub fn failure(message: impl Into<String>) -> Self {
66        Self {
67            success: false,
68            message: message.into(),
69            details: None,
70        }
71    }
72
73    pub fn with_details(mut self, details: impl Into<String>) -> Self {
74        self.details = Some(details.into());
75        self
76    }
77}
78
79#[cfg(test)]
80mod tests {
81    use super::*;
82
83    #[test]
84    fn test_init_test_env() {
85        // This test ensures the function can be called without panicking
86        init_test_env();
87    }
88
89    #[test]
90    fn test_test_config_default() {
91        let config = TestConfig::default();
92        assert!(config.theme.is_none());
93        assert!(config.breakpoint.is_none());
94        assert!(!config.dark_mode);
95        assert!(config.custom_css.is_empty());
96    }
97
98    #[test]
99    fn test_test_result() {
100        let success_result = TestResult::success("Test passed");
101        assert!(success_result.success);
102        assert_eq!(success_result.message, "Test passed");
103        assert!(success_result.details.is_none());
104
105        let failure_result = TestResult::failure("Test failed");
106        assert!(!failure_result.success);
107        assert_eq!(failure_result.message, "Test failed");
108        assert!(failure_result.details.is_none());
109
110        let detailed_result = TestResult::success("Test passed").with_details("Additional info");
111        assert!(detailed_result.success);
112        assert_eq!(detailed_result.message, "Test passed");
113        assert_eq!(detailed_result.details, Some("Additional info".to_string()));
114    }
115}