diff --git a/src/core/config.rs b/src/core/config.rs index b23b765..f296440 100644 --- a/src/core/config.rs +++ b/src/core/config.rs @@ -99,3 +99,56 @@ impl Config { Self::default() } } + +//write unit tests: +#[cfg(test)] +mod tests { + use super::*; + use std::path::Path; + + // create a clean default config file for testing + fn create_default_config_file() { + let toml = toml::to_string(&Config::default()).unwrap(); + fs::write(&*CONFIG_FILE, toml).expect("Could not write config file to disk!"); + } + + #[test] + fn test_create_default_config_file() { + create_default_config_file(); + assert!(CONFIG_FILE.exists()); + } + + #[test] + fn test_load_configuration_file(){ + create_default_config_file(); + let config = Config::load_configuration_file(); + assert_eq!(config.devices.len(), 0); + assert_eq!(config.general.theme, Theme::default().to_string()); + assert_eq!(config.general.expert_mode, false); + assert_eq!(config.general.backup_folder, CACHE_DIR.join("backups")); + } + + #[test] + fn test_save_changes() { + let mut settings = Settings::default(); + let device_id = "test_device".to_string(); + settings.device.device_id = device_id.clone(); + Config::save_changes(&settings, &device_id); + let config = Config::load_configuration_file(); + assert_eq!(config.devices[0].device_id, device_id); + } + + #[test] + fn test_default_config() { + let config = Config::default(); + assert_eq!(config.devices.len(), 0); + assert_eq!(config.general.theme, Theme::default().to_string()); + assert_eq!(config.general.expert_mode, false); + assert_eq!(config.general.backup_folder, CACHE_DIR.join("backups")); + } + + #[test] + fn test_config_file_path() { + assert_eq!(&*CONFIG_FILE, Path::new(&*CONFIG_DIR.join("config.toml"))); + } +} \ No newline at end of file diff --git a/src/gui/style.rs b/src/gui/style.rs index ac32942..09a59e9 100644 --- a/src/gui/style.rs +++ b/src/gui/style.rs @@ -573,3 +573,23 @@ impl rule::StyleSheet for Theme { } } } + +// Unit tests +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_palette() { + let palette = Theme::default().palette(); + + assert_ne!(palette.base.background, Color::BLACK); + assert_ne!(palette.base.foreground, Color::BLACK); + assert_ne!(palette.normal.primary, Color::BLACK); + assert_ne!(palette.normal.surface, Color::BLACK); + assert_ne!(palette.bright.primary, Color::BLACK); + assert_ne!(palette.bright.surface, Color::BLACK); + assert_ne!(palette.normal.error, Color::BLACK); + assert_ne!(palette.bright.error, Color::BLACK); + } +} \ No newline at end of file