#[cfg(test)]
mod hotkey_tests {
use crate::model::app::App;
use crate::model::choice::Choice;
use crate::model::common::{Anchor, InputBounds};
use crate::model::layout::Layout;
use crate::model::muxbox::MuxBox;
use crate::thread_manager::Message;
use std::collections::HashMap;
#[test]
fn test_app_hotkeys_field_creation() {
let mut app = App::new();
let mut hotkeys = HashMap::new();
hotkeys.insert("F1".to_string(), "deploy".to_string());
hotkeys.insert("Ctrl+r".to_string(), "restart".to_string());
app.hot_keys = Some(hotkeys);
assert!(app.hot_keys.is_some());
let hotkeys = app.hot_keys.unwrap();
assert_eq!(hotkeys.get("F1"), Some(&"deploy".to_string()));
assert_eq!(hotkeys.get("Ctrl+r"), Some(&"restart".to_string()));
}
#[test]
fn test_execute_hotkey_choice_message() {
let choice_id = "deploy".to_string();
let message = Message::ExecuteHotKeyChoice(choice_id.clone());
match message {
Message::ExecuteHotKeyChoice(id) => {
assert_eq!(id, choice_id);
}
_ => panic!("Expected ExecuteHotKeyChoice message"),
}
}
#[test]
fn test_find_muxbox_with_choice() {
use crate::tests::test_utils::TestDataFactory;
let choice = Choice {
id: "test_choice".to_string(),
content: Some("Test Choice".to_string()),
script: Some(vec!["echo test".to_string()]),
redirect_output: None,
append_output: None,
execution_mode: crate::model::common::ExecutionMode::default(),
selected: false,
hovered: false,
waiting: false,
};
let mut muxbox = TestDataFactory::create_test_muxbox("test_muxbox");
muxbox.choices = Some(vec![choice]);
muxbox.initialize_streams();
let mut layout = TestDataFactory::create_test_layout("test_layout", Some(vec![muxbox]));
layout.root = Some(true);
let found_muxbox = layout.find_muxbox_with_choice("test_choice");
assert!(found_muxbox.is_some());
assert_eq!(found_muxbox.unwrap().id, "test_muxbox");
let not_found = layout.find_muxbox_with_choice("non_existent");
assert!(not_found.is_none());
}
#[test]
fn test_hotkey_configuration() {
let mut app = App::new();
assert!(app.hot_keys.is_none());
let mut hotkeys = HashMap::new();
hotkeys.insert("F1".to_string(), "build".to_string());
hotkeys.insert("F2".to_string(), "test".to_string());
hotkeys.insert("Ctrl+d".to_string(), "deploy".to_string());
app.hot_keys = Some(hotkeys);
assert!(app.hot_keys.is_some());
let hotkeys = app.hot_keys.as_ref().unwrap();
assert_eq!(hotkeys.len(), 3);
assert_eq!(hotkeys.get("F1"), Some(&"build".to_string()));
assert_eq!(hotkeys.get("F2"), Some(&"test".to_string()));
assert_eq!(hotkeys.get("Ctrl+d"), Some(&"deploy".to_string()));
}
#[test]
fn test_app_clone_includes_hotkeys() {
let mut app = App::new();
let mut hotkeys = HashMap::new();
hotkeys.insert("F5".to_string(), "refresh".to_string());
app.hot_keys = Some(hotkeys);
let cloned_app = app.clone();
assert!(cloned_app.hot_keys.is_some());
assert_eq!(
cloned_app.hot_keys.as_ref().unwrap().get("F5"),
Some(&"refresh".to_string())
);
}
#[test]
fn test_app_equality_includes_hotkeys() {
let mut app1 = App::new();
let mut app2 = App::new();
assert_eq!(app1, app2);
let mut hotkeys = HashMap::new();
hotkeys.insert("F1".to_string(), "test".to_string());
app1.hot_keys = Some(hotkeys);
assert_ne!(app1, app2);
let mut hotkeys2 = HashMap::new();
hotkeys2.insert("F1".to_string(), "test".to_string());
app2.hot_keys = Some(hotkeys2);
assert_eq!(app1, app2);
}
}