refactor: use system timezone and harden client APIs

This commit is contained in:
Mikhail Kilin
2026-05-17 13:14:59 +03:00
parent 887892f809
commit e09b83be69
50 changed files with 172 additions and 343 deletions

View File

@@ -1,8 +1,7 @@
// Integration tests for config flow
use tele_tui::config::{
AudioConfig, ColorsConfig, Config, GeneralConfig, ImagesConfig, Keybindings,
NotificationsConfig,
AudioConfig, ColorsConfig, Config, ImagesConfig, Keybindings, NotificationsConfig,
};
/// Test: Дефолтные значения конфигурации
@@ -10,9 +9,6 @@ use tele_tui::config::{
fn test_config_default_values() {
let config = Config::default();
// Проверяем дефолтный timezone
assert_eq!(config.general.timezone, "+03:00");
// Проверяем дефолтные цвета
assert_eq!(config.colors.incoming_message, "white");
assert_eq!(config.colors.outgoing_message, "green");
@@ -25,7 +21,6 @@ fn test_config_default_values() {
#[test]
fn test_config_custom_values() {
let config = Config {
general: GeneralConfig { timezone: "+05:00".to_string() },
colors: ColorsConfig {
incoming_message: "cyan".to_string(),
outgoing_message: "blue".to_string(),
@@ -39,7 +34,6 @@ fn test_config_custom_values() {
audio: AudioConfig::default(),
};
assert_eq!(config.general.timezone, "+05:00");
assert_eq!(config.colors.incoming_message, "cyan");
assert_eq!(config.colors.outgoing_message, "blue");
}
@@ -109,7 +103,6 @@ fn test_parse_color_case_insensitive() {
#[test]
fn test_config_toml_serialization() {
let original_config = Config {
general: GeneralConfig { timezone: "-05:00".to_string() },
colors: ColorsConfig {
incoming_message: "cyan".to_string(),
outgoing_message: "blue".to_string(),
@@ -130,7 +123,6 @@ fn test_config_toml_serialization() {
let deserialized: Config = toml::from_str(&toml_string).expect("Failed to deserialize config");
// Проверяем что всё совпадает
assert_eq!(deserialized.general.timezone, "-05:00");
assert_eq!(deserialized.colors.incoming_message, "cyan");
assert_eq!(deserialized.colors.outgoing_message, "blue");
assert_eq!(deserialized.colors.selected_message, "red");
@@ -139,47 +131,19 @@ fn test_config_toml_serialization() {
/// Test: Парсинг TOML с частичными данными использует дефолты
#[test]
fn test_config_partial_toml_uses_defaults() {
// TOML только с timezone, без colors
// TOML только с colors.incoming_message
let toml_str = r#"
[general]
timezone = "+02:00"
[colors]
incoming_message = "cyan"
"#;
let config: Config = toml::from_str(toml_str).expect("Failed to parse partial TOML");
// Timezone должен быть из TOML
assert_eq!(config.general.timezone, "+02:00");
// Colors должны быть дефолтными
assert_eq!(config.colors.incoming_message, "white");
// Кастомный цвет должен примениться
assert_eq!(config.colors.incoming_message, "cyan");
// Остальные colors должны быть дефолтными
assert_eq!(config.colors.outgoing_message, "green");
}
#[cfg(test)]
mod timezone_tests {
use super::*;
/// Test: Различные форматы timezone
#[test]
fn test_timezone_formats() {
let positive = Config {
general: GeneralConfig { timezone: "+03:00".to_string() },
..Default::default()
};
assert_eq!(positive.general.timezone, "+03:00");
let negative = Config {
general: GeneralConfig { timezone: "-05:00".to_string() },
..Default::default()
};
assert_eq!(negative.general.timezone, "-05:00");
let zero = Config {
general: GeneralConfig { timezone: "+00:00".to_string() },
..Default::default()
};
assert_eq!(zero.general.timezone, "+00:00");
}
assert_eq!(config.colors.selected_message, "yellow");
}
#[cfg(test)]