use aranet_types::Status;
use ratatui::style::Color;
use super::super::app::ConnectionStatus;
use super::theme::AppTheme;
#[must_use]
pub fn co2_color(theme: &AppTheme, ppm: u16) -> Color {
theme.co2_level_color(ppm)
}
#[must_use]
pub fn radon_color(theme: &AppTheme, bq_m3: u32) -> Color {
theme.radon_level_color(bq_m3)
}
#[allow(dead_code)]
#[must_use]
pub fn status_color(theme: &AppTheme, status: &Status) -> Color {
theme.sensor_status_color(status)
}
#[must_use]
pub fn battery_color(theme: &AppTheme, percent: u8) -> Color {
theme.battery_level_color(percent)
}
#[allow(dead_code)]
#[must_use]
pub fn connection_status_color(theme: &AppTheme, status: &ConnectionStatus) -> Color {
theme.connection_color(status)
}
#[must_use]
pub fn signal_strength_display(theme: &AppTheme, rssi: i16) -> (&'static str, Color) {
theme.signal_strength_display(rssi)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_co2_color_good() {
let theme = AppTheme::dark();
assert_eq!(co2_color(&theme, 0), theme.success);
assert_eq!(co2_color(&theme, 400), theme.success);
assert_eq!(co2_color(&theme, 800), theme.success);
}
#[test]
fn test_co2_color_moderate() {
let theme = AppTheme::dark();
assert_eq!(co2_color(&theme, 801), theme.warning);
assert_eq!(co2_color(&theme, 900), theme.warning);
assert_eq!(co2_color(&theme, 1000), theme.warning);
}
#[test]
fn test_co2_color_elevated() {
let theme = AppTheme::dark();
assert_eq!(co2_color(&theme, 1001), theme.caution);
assert_eq!(co2_color(&theme, 1250), theme.caution);
assert_eq!(co2_color(&theme, 1500), theme.caution);
}
#[test]
fn test_co2_color_high() {
let theme = AppTheme::dark();
assert_eq!(co2_color(&theme, 1501), theme.danger);
assert_eq!(co2_color(&theme, 2000), theme.danger);
assert_eq!(co2_color(&theme, 5000), theme.danger);
}
#[test]
fn test_battery_color() {
let theme = AppTheme::dark();
assert_eq!(battery_color(&theme, 0), theme.danger);
assert_eq!(battery_color(&theme, 20), theme.danger);
assert_eq!(battery_color(&theme, 21), theme.warning);
assert_eq!(battery_color(&theme, 50), theme.warning);
assert_eq!(battery_color(&theme, 51), theme.success);
assert_eq!(battery_color(&theme, 100), theme.success);
}
#[test]
fn test_status_color() {
let theme = AppTheme::dark();
assert_eq!(status_color(&theme, &Status::Green), theme.success);
assert_eq!(status_color(&theme, &Status::Yellow), theme.warning);
assert_eq!(status_color(&theme, &Status::Red), theme.danger);
assert_eq!(status_color(&theme, &Status::Error), theme.signal_offline);
}
#[test]
fn test_connection_status_color() {
let theme = AppTheme::dark();
assert_eq!(
connection_status_color(&theme, &ConnectionStatus::Disconnected),
theme.signal_offline
);
assert_eq!(
connection_status_color(&theme, &ConnectionStatus::Connecting),
theme.warning
);
assert_eq!(
connection_status_color(&theme, &ConnectionStatus::Connected),
theme.success
);
assert_eq!(
connection_status_color(&theme, &ConnectionStatus::Error("test".to_string())),
theme.danger
);
}
#[test]
fn test_radon_color_good() {
let theme = AppTheme::dark();
assert_eq!(radon_color(&theme, 0), theme.success);
assert_eq!(radon_color(&theme, 50), theme.success);
assert_eq!(radon_color(&theme, 100), theme.success);
}
#[test]
fn test_radon_color_moderate() {
let theme = AppTheme::dark();
assert_eq!(radon_color(&theme, 101), theme.warning);
assert_eq!(radon_color(&theme, 125), theme.warning);
assert_eq!(radon_color(&theme, 150), theme.warning);
}
#[test]
fn test_radon_color_elevated() {
let theme = AppTheme::dark();
assert_eq!(radon_color(&theme, 151), theme.caution);
assert_eq!(radon_color(&theme, 200), theme.caution);
assert_eq!(radon_color(&theme, 300), theme.caution);
}
#[test]
fn test_radon_color_high() {
let theme = AppTheme::dark();
assert_eq!(radon_color(&theme, 301), theme.danger);
assert_eq!(radon_color(&theme, 500), theme.danger);
assert_eq!(radon_color(&theme, 1000), theme.danger);
}
}