use par_term::config::Config;
#[test]
fn test_session_ended_notification_config_defaults() {
let config = Config::default();
assert!(!config.notifications.notification_session_ended);
}
#[test]
fn test_suppress_notifications_when_focused_config_defaults() {
let config = Config::default();
assert!(config.notifications.suppress_notifications_when_focused);
}
#[test]
fn test_session_ended_notification_yaml_deserialization() {
let yaml = r#"
notification_session_ended: true
"#;
let config: Config = serde_yaml_ng::from_str(yaml).unwrap();
assert!(config.notifications.notification_session_ended);
let yaml = r#"
notification_session_ended: false
"#;
let config: Config = serde_yaml_ng::from_str(yaml).unwrap();
assert!(!config.notifications.notification_session_ended);
}
#[test]
fn test_suppress_notifications_when_focused_yaml_deserialization() {
let yaml = r#"
suppress_notifications_when_focused: true
"#;
let config: Config = serde_yaml_ng::from_str(yaml).unwrap();
assert!(config.notifications.suppress_notifications_when_focused);
let yaml = r#"
suppress_notifications_when_focused: false
"#;
let config: Config = serde_yaml_ng::from_str(yaml).unwrap();
assert!(!config.notifications.suppress_notifications_when_focused);
}
#[test]
fn test_session_ended_config_alias() {
let yaml = r#"
session_ended: true
"#;
let config: Config = serde_yaml_ng::from_str(yaml).unwrap();
assert!(config.notifications.notification_session_ended);
let yaml = r#"
session_ended: false
"#;
let config: Config = serde_yaml_ng::from_str(yaml).unwrap();
assert!(!config.notifications.notification_session_ended);
}
#[test]
fn test_session_notification_config_yaml_serialization() {
let config = Config::default();
let yaml = serde_yaml_ng::to_string(&config).unwrap();
assert!(yaml.contains("notification_session_ended: false"));
assert!(yaml.contains("suppress_notifications_when_focused: true"));
}
#[test]
fn test_all_notification_settings_together() {
let yaml = r#"
notification_bell_desktop: true
notification_activity_enabled: true
notification_silence_enabled: true
notification_session_ended: true
suppress_notifications_when_focused: false
"#;
let config: Config = serde_yaml_ng::from_str(yaml).unwrap();
assert!(config.notifications.notification_bell_desktop);
assert!(config.notifications.notification_activity_enabled);
assert!(config.notifications.notification_silence_enabled);
assert!(config.notifications.notification_session_ended);
assert!(!config.notifications.suppress_notifications_when_focused);
}
#[test]
fn test_session_ended_with_suppress_disabled() {
let yaml = r#"
notification_session_ended: true
suppress_notifications_when_focused: false
"#;
let config: Config = serde_yaml_ng::from_str(yaml).unwrap();
assert!(config.notifications.notification_session_ended);
assert!(!config.notifications.suppress_notifications_when_focused);
}
#[test]
fn test_exit_notification_deduplication() {
let mut exit_notified = false;
let shell_exited = true;
if !exit_notified && shell_exited {
exit_notified = true;
}
assert!(exit_notified, "First check should set flag");
let should_notify = !exit_notified && shell_exited;
assert!(
!should_notify,
"Second check should not trigger duplicate notification"
);
}
#[test]
fn test_suppress_when_focused_logic() {
let suppress_enabled = true;
let is_focused = true;
let should_send_desktop = !(suppress_enabled && is_focused);
assert!(
!should_send_desktop,
"Desktop notification should be suppressed when focused"
);
let is_focused = false;
let should_send_desktop = !(suppress_enabled && is_focused);
assert!(
should_send_desktop,
"Desktop notification should be sent when not focused"
);
let suppress_enabled = false;
let is_focused = true;
let should_send_desktop = !(suppress_enabled && is_focused);
assert!(
should_send_desktop,
"Desktop notification should be sent when suppression disabled"
);
}
#[test]
fn test_bells_independent_of_suppress() {
let yaml = r#"
notification_bell_visual: true
notification_bell_sound: 50
suppress_notifications_when_focused: true
"#;
let config: Config = serde_yaml_ng::from_str(yaml).unwrap();
assert!(config.notifications.notification_bell_visual);
assert_eq!(config.notifications.notification_bell_sound, 50);
assert!(config.notifications.suppress_notifications_when_focused);
}
#[test]
fn test_empty_yaml_uses_defaults() {
let yaml = "";
let config: Config = serde_yaml_ng::from_str(yaml).unwrap();
assert!(!config.notifications.notification_session_ended);
assert!(config.notifications.suppress_notifications_when_focused);
}