use frentui::app::App;
use frentui::section::{SectionId, SectionTrait};
#[test]
fn test_app_new() {
let app = App::new();
assert_eq!(app.current_section, SectionId::WorkingDirectory); assert!(!app.should_quit);
assert_eq!(app.action_selection, Some(0));
assert!(app.input_dialog.is_none());
assert!(app.template_registry.is_none());
assert_eq!(app.screen_scroll, 0);
assert!(app.rename_history.is_none());
}
#[test]
fn test_app_default() {
let app = App::default();
assert_eq!(app.current_section, SectionId::WorkingDirectory); }
#[test]
fn test_app_current_section_idx() {
let app = App::new();
let idx = app.current_section_idx();
assert_eq!(app.sections[idx].id(), SectionId::WorkingDirectory); }
#[test]
fn test_app_go_next_section() {
let mut app = App::new();
assert_eq!(app.current_section, SectionId::WorkingDirectory);
app.go_next_section();
assert_ne!(app.current_section, SectionId::WorkingDirectory);
assert_eq!(app.action_selection, Some(0));
}
#[test]
fn test_app_go_previous_section() {
let mut app = App::new();
app.go_next_section(); let first_focusable = app.current_section;
app.go_next_section();
let second_focusable = app.current_section;
assert_ne!(first_focusable, second_focusable);
app.go_previous_section();
assert_eq!(app.current_section, first_focusable);
assert_eq!(app.action_selection, Some(0));
}
#[test]
fn test_app_quit() {
let mut app = App::new();
assert!(!app.should_quit);
app.quit();
assert!(app.should_quit);
}
#[test]
fn test_app_get_template_registry() {
let mut app = App::new();
assert!(app.template_registry.is_none());
{
let registry = app.get_template_registry();
assert!(registry.list_for_field(frentui::ui::dialog::TemplateField::RenamingRule).len() > 0);
}
let registry2 = app.get_template_registry();
let len = registry2.list_for_field(frentui::ui::dialog::TemplateField::RenamingRule).len();
assert!(len > 0);
assert!(app.template_registry.is_some());
}
#[test]
fn test_app_current_actions() {
let app = App::new();
let actions = app.current_actions();
assert!(actions.len() > 0);
}
#[test]
fn test_app_sections_created() {
let app = App::new();
assert!(!app.sections.is_empty());
let section_ids: Vec<SectionId> = app.sections.iter().map(|s| s.id()).collect();
assert!(section_ids.contains(&SectionId::Header));
assert!(section_ids.contains(&SectionId::WorkingDirectory));
assert!(section_ids.contains(&SectionId::MatchFiles));
assert!(section_ids.contains(&SectionId::Exclusions));
assert!(section_ids.contains(&SectionId::RenamingRule));
assert!(section_ids.contains(&SectionId::PreviewPane));
assert!(section_ids.contains(&SectionId::Validation));
assert!(section_ids.contains(&SectionId::ApplyRenaming));
assert!(section_ids.contains(&SectionId::Undo));
assert!(section_ids.contains(&SectionId::Footer));
}
#[test]
fn test_app_section_can_focus() {
let app = App::new();
assert!(!app.section_can_focus(SectionId::Header));
assert!(!app.section_can_focus(SectionId::Footer));
assert!(app.section_can_focus(SectionId::WorkingDirectory));
assert!(app.section_can_focus(SectionId::MatchFiles));
}
#[test]
fn test_app_section_can_focus_with_content() {
let mut app = App::new();
assert!(!app.section_can_focus(SectionId::PreviewPane));
app.state.list.push(std::path::PathBuf::from("test1.txt"));
app.state.new_names.push("test1_new.txt".to_string());
assert!(app.section_can_focus(SectionId::PreviewPane));
}
#[test]
fn test_app_initialize() {
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
let mut app = App::new();
let result = app.initialize().await;
assert!(result.is_ok() || result.is_err());
});
}
#[test]
fn test_app_update_temp_preview_no_pattern() {
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
let mut app = App::new();
app.update_temp_preview().await;
assert!(app.temp_list.is_empty());
assert!(app.temp_new_names.is_empty());
});
}
#[test]
fn test_app_update_temp_preview_invalid_pattern() {
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
let mut app = App::new();
app.temp_match_pattern = Some("[invalid[pattern".to_string());
app.state.list.push(std::path::PathBuf::from("test.txt"));
app.update_temp_preview().await;
assert!(!app.temp_new_names.is_empty());
assert!(app.temp_new_names.iter().any(|n| n == "invalid pattern"));
});
}
#[test]
fn test_app_update_temp_preview_exclusion_no_pattern() {
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
let mut app = App::new();
app.update_temp_preview_exclusion().await;
assert!(app.temp_list.is_empty());
assert!(app.temp_new_names.is_empty());
});
}
#[test]
fn test_app_update_temp_preview_exclusion_invalid_pattern() {
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
let mut app = App::new();
app.temp_exclusion_pattern = Some("[invalid[pattern".to_string());
app.state.raw_list.push(std::path::PathBuf::from("test.txt"));
app.update_temp_preview_exclusion().await;
assert!(!app.temp_new_names.is_empty());
assert!(app.temp_new_names.iter().any(|n| n == "invalid pattern"));
});
}
#[test]
fn test_app_update_temp_preview_rename_no_pattern() {
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
let mut app = App::new();
app.update_temp_preview_rename().await;
assert!(app.temp_list.is_empty());
assert!(app.temp_new_names.is_empty());
});
}
#[test]
fn test_app_update_temp_preview_rename_invalid_pattern() {
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
let mut app = App::new();
app.temp_rename_pattern = Some("%INVALID%PATTERN%".to_string());
app.state.list.push(std::path::PathBuf::from("test.txt"));
app.state.new_names.push("test.txt".to_string());
app.update_temp_preview_rename().await;
if !app.state.list.is_empty() {
assert!(!app.temp_new_names.is_empty() || app.temp_list.is_empty());
}
});
}