use ricecoder_cli::commands::Command;
use ricecoder_cli::commands::{SessionsAction, SessionsCommand, TuiCommand};
use std::fs;
use std::path::PathBuf;
fn get_test_sessions_dir() -> PathBuf {
let home = dirs::home_dir().expect("Could not determine home directory");
home.join(".ricecoder").join("sessions")
}
fn cleanup_test_sessions() {
let sessions_dir = get_test_sessions_dir();
if sessions_dir.exists() {
let _ = fs::remove_dir_all(&sessions_dir);
}
let _ = fs::create_dir_all(&sessions_dir);
}
#[test]
fn test_tui_command_creation() {
let cmd = TuiCommand::new(
Some("dark".to_string()),
true,
None,
Some("openai".to_string()),
Some("gpt-4".to_string()),
);
let config = cmd.get_config();
assert_eq!(config.theme, Some("dark".to_string()));
assert!(config.vim_mode);
assert_eq!(config.provider, Some("openai".to_string()));
assert_eq!(config.model, Some("gpt-4".to_string()));
}
#[test]
fn test_tui_command_defaults() {
let cmd = TuiCommand::new(None, false, None, None, None);
let config = cmd.get_config();
assert_eq!(config.theme, None);
assert!(!config.vim_mode);
assert_eq!(config.provider, None);
assert_eq!(config.model, None);
}
#[test]
fn test_tui_command_with_all_options() {
let cmd = TuiCommand::new(
Some("monokai".to_string()),
true,
Some(PathBuf::from("/tmp/config.yaml")),
Some("anthropic".to_string()),
Some("claude-3-opus".to_string()),
);
let config = cmd.get_config();
assert_eq!(config.theme, Some("monokai".to_string()));
assert!(config.vim_mode);
assert_eq!(config.config_file, Some(PathBuf::from("/tmp/config.yaml")));
assert_eq!(config.provider, Some("anthropic".to_string()));
assert_eq!(config.model, Some("claude-3-opus".to_string()));
}
#[test]
fn test_sessions_command_list() {
cleanup_test_sessions();
let cmd = SessionsCommand::new(SessionsAction::List);
let result = cmd.execute();
assert!(result.is_ok());
}
#[test]
fn test_sessions_command_create() {
cleanup_test_sessions();
let cmd = SessionsCommand::new(SessionsAction::Create {
name: "test-session".to_string(),
});
let result = cmd.execute();
assert!(result.is_ok());
}
#[test]
fn test_sessions_command_delete() {
cleanup_test_sessions();
let create_cmd = SessionsCommand::new(SessionsAction::Create {
name: "session-to-delete".to_string(),
});
assert!(create_cmd.execute().is_ok());
let cmd = SessionsCommand::new(SessionsAction::Delete {
id: "session-1".to_string(),
});
let _ = cmd.execute();
}
#[test]
fn test_sessions_command_rename() {
cleanup_test_sessions();
let create_cmd = SessionsCommand::new(SessionsAction::Create {
name: "original-name".to_string(),
});
assert!(create_cmd.execute().is_ok());
let cmd = SessionsCommand::new(SessionsAction::Rename {
id: "session-1".to_string(),
name: "new-name".to_string(),
});
let _ = cmd.execute();
}
#[test]
fn test_sessions_command_switch() {
cleanup_test_sessions();
let create_cmd = SessionsCommand::new(SessionsAction::Create {
name: "session-to-switch".to_string(),
});
assert!(create_cmd.execute().is_ok());
let cmd = SessionsCommand::new(SessionsAction::Switch {
id: "session-1".to_string(),
});
let _ = cmd.execute();
}
#[test]
fn test_sessions_command_info() {
cleanup_test_sessions();
let create_cmd = SessionsCommand::new(SessionsAction::Create {
name: "session-for-info".to_string(),
});
assert!(create_cmd.execute().is_ok());
let cmd = SessionsCommand::new(SessionsAction::Info {
id: "session-1".to_string(),
});
let _ = cmd.execute();
}
#[test]
fn test_tui_with_provider_configuration() {
let providers = vec!["openai", "anthropic", "ollama"];
for provider in providers {
let cmd = TuiCommand::new(
None,
false,
None,
Some(provider.to_string()),
Some("test-model".to_string()),
);
let config = cmd.get_config();
assert_eq!(config.provider, Some(provider.to_string()));
assert_eq!(config.model, Some("test-model".to_string()));
}
}
#[test]
fn test_tui_with_theme_configuration() {
let themes = vec!["dark", "light", "monokai", "dracula", "nord"];
for theme in themes {
let cmd = TuiCommand::new(Some(theme.to_string()), false, None, None, None);
let config = cmd.get_config();
assert_eq!(config.theme, Some(theme.to_string()));
}
}