Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(ci): add new unit tests #654

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions src/core/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(!config.general.expert_mode);
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!(!config.general.expert_mode);
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")));
}
}
19 changes: 19 additions & 0 deletions src/gui/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,3 +573,22 @@ 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, palette.base.foreground);
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);
}
}
Loading