build(test): added some more unit tests

This commit is contained in:
Frigyes Erdosi Szucs 2024-09-25 12:23:31 -07:00
commit 146a15943c
No known key found for this signature in database
GPG key ID: B0B05D8121415C57
2 changed files with 73 additions and 0 deletions

View file

@ -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")));
}
}

View file

@ -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);
}
}