#![allow(dead_code)]
use crate::config::Config;
pub enum Action {
SelectNext,
SelectPrevious,
PageDown,
PageUp,
SelectFirst,
SelectLast,
RefreshNow,
ConfigReloaded(Config),
Resize {
width: u16,
height: u16,
},
Quit,
}
#[cfg(test)]
mod tests {
use super::*;
use crate::config::{Config, SystemEntry};
#[test]
fn action_variants_exist() {
let actions = [
Action::SelectNext,
Action::SelectPrevious,
Action::PageDown,
Action::PageUp,
Action::SelectFirst,
Action::SelectLast,
Action::RefreshNow,
Action::ConfigReloaded(Config::default()),
Action::Resize {
width: 80,
height: 24,
},
Action::Quit,
];
assert!(matches!(actions[0], Action::SelectNext));
assert!(matches!(actions[1], Action::SelectPrevious));
assert!(matches!(actions[2], Action::PageDown));
assert!(matches!(actions[3], Action::PageUp));
assert!(matches!(actions[4], Action::SelectFirst));
assert!(matches!(actions[5], Action::SelectLast));
assert!(matches!(actions[6], Action::RefreshNow));
assert!(matches!(actions[7], Action::ConfigReloaded(_)));
assert!(matches!(
actions[8],
Action::Resize {
width: 80,
height: 24
}
));
assert!(matches!(actions[9], Action::Quit));
}
#[test]
fn resize_carries_dimensions() {
let action = Action::Resize {
width: 120,
height: 40,
};
match action {
Action::Resize { width, height } => {
assert_eq!(width, 120);
assert_eq!(height, 40);
}
_ => panic!("expected Resize"),
}
}
#[test]
fn config_reloaded_carry_config() {
let mut config = Config::default();
config.systems.push(SystemEntry {
id: "test-id".into(),
host: "192.168.1.1".into(),
port: 11310,
name: None,
});
let action = Action::ConfigReloaded(config);
match action {
Action::ConfigReloaded(c) => {
assert_eq!(c.systems.len(), 1);
assert_eq!(c.systems[0].host, "192.168.1.1");
}
_ => panic!("expected ConfigReloaded"),
}
}
}