diff --git a/src/config.rs b/src/config.rs index a8cda6a..797f27a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -740,4 +740,153 @@ mod tests { assert_eq!(config.hotkeys.react, vec!["e", "у"]); assert_eq!(config.hotkeys.profile, vec!["i", "ш"]); } + + #[test] + fn test_config_validate_valid() { + let config = Config::default(); + assert!(config.validate().is_ok()); + } + + #[test] + fn test_config_validate_invalid_timezone_no_sign() { + let mut config = Config::default(); + config.general.timezone = "03:00".to_string(); + + let result = config.validate(); + assert!(result.is_err()); + assert!(result.unwrap_err().contains("timezone")); + } + + #[test] + fn test_config_validate_valid_negative_timezone() { + let mut config = Config::default(); + config.general.timezone = "-05:00".to_string(); + + assert!(config.validate().is_ok()); + } + + #[test] + fn test_config_validate_valid_positive_timezone() { + let mut config = Config::default(); + config.general.timezone = "+09:00".to_string(); + + assert!(config.validate().is_ok()); + } + + #[test] + fn test_config_validate_invalid_color_incoming() { + let mut config = Config::default(); + config.colors.incoming_message = "rainbow".to_string(); + + let result = config.validate(); + assert!(result.is_err()); + assert!(result.unwrap_err().contains("Invalid color")); + } + + #[test] + fn test_config_validate_invalid_color_outgoing() { + let mut config = Config::default(); + config.colors.outgoing_message = "purple".to_string(); + + let result = config.validate(); + assert!(result.is_err()); + assert!(result.unwrap_err().contains("Invalid color")); + } + + #[test] + fn test_config_validate_invalid_color_selected() { + let mut config = Config::default(); + config.colors.selected_message = "pink".to_string(); + + let result = config.validate(); + assert!(result.is_err()); + assert!(result.unwrap_err().contains("Invalid color")); + } + + #[test] + fn test_config_validate_valid_all_standard_colors() { + let colors = [ + "black", "red", "green", "yellow", "blue", "magenta", + "cyan", "gray", "grey", "white", "darkgray", "darkgrey", + "lightred", "lightgreen", "lightyellow", "lightblue", + "lightmagenta", "lightcyan" + ]; + + for color in colors { + let mut config = Config::default(); + config.colors.incoming_message = color.to_string(); + config.colors.outgoing_message = color.to_string(); + config.colors.selected_message = color.to_string(); + config.colors.reaction_chosen = color.to_string(); + config.colors.reaction_other = color.to_string(); + + assert!( + config.validate().is_ok(), + "Color '{}' should be valid", + color + ); + } + } + + #[test] + fn test_config_validate_case_insensitive_colors() { + let mut config = Config::default(); + config.colors.incoming_message = "RED".to_string(); + config.colors.outgoing_message = "Green".to_string(); + config.colors.selected_message = "YELLOW".to_string(); + + assert!(config.validate().is_ok()); + } + + #[test] + fn test_parse_color_standard() { + let config = Config::default(); + + use ratatui::style::Color; + assert_eq!(config.parse_color("red"), Color::Red); + assert_eq!(config.parse_color("green"), Color::Green); + assert_eq!(config.parse_color("blue"), Color::Blue); + } + + #[test] + fn test_parse_color_light_variants() { + let config = Config::default(); + + use ratatui::style::Color; + assert_eq!(config.parse_color("lightred"), Color::LightRed); + assert_eq!(config.parse_color("lightgreen"), Color::LightGreen); + assert_eq!(config.parse_color("lightblue"), Color::LightBlue); + } + + #[test] + fn test_parse_color_gray_variants() { + let config = Config::default(); + + use ratatui::style::Color; + assert_eq!(config.parse_color("gray"), Color::Gray); + assert_eq!(config.parse_color("grey"), Color::Gray); + assert_eq!(config.parse_color("darkgray"), Color::DarkGray); + assert_eq!(config.parse_color("darkgrey"), Color::DarkGray); + } + + #[test] + fn test_parse_color_case_insensitive() { + let config = Config::default(); + + use ratatui::style::Color; + assert_eq!(config.parse_color("RED"), Color::Red); + assert_eq!(config.parse_color("Green"), Color::Green); + assert_eq!(config.parse_color("LIGHTBLUE"), Color::LightBlue); + } + + #[test] + fn test_parse_color_invalid_fallback() { + let config = Config::default(); + + use ratatui::style::Color; + // Invalid colors should fallback to White + assert_eq!(config.parse_color("rainbow"), Color::White); + assert_eq!(config.parse_color("purple"), Color::White); + assert_eq!(config.parse_color("unknown"), Color::White); + } }