diff --git a/tests/plugin_exact_match.rs b/tests/plugin_exact_match.rs index 0f912160..c2d2a26d 100644 --- a/tests/plugin_exact_match.rs +++ b/tests/plugin_exact_match.rs @@ -3,6 +3,7 @@ use multi_launcher::actions::Action; use multi_launcher::gui::LauncherApp; use multi_launcher::plugin::PluginManager; use multi_launcher::plugins::bookmarks::{save_bookmarks, BookmarkEntry, BOOKMARKS_FILE}; +use multi_launcher::plugins::note::{append_note, save_notes}; use multi_launcher::plugins::snippets::{save_snippets, SnippetEntry, SNIPPETS_FILE}; use multi_launcher::settings::Settings; use once_cell::sync::Lazy; @@ -42,6 +43,14 @@ fn new_app(ctx: &egui::Context, settings: Settings) -> LauncherApp { ) } +fn setup_notes_env(dir: &tempfile::TempDir) { + let notes_dir = dir.path().join("notes"); + std::fs::create_dir_all(¬es_dir).unwrap(); + std::env::set_var("ML_NOTES_DIR", ¬es_dir); + std::env::set_var("HOME", dir.path()); + save_notes(&[]).unwrap(); +} + #[test] fn plugin_query_is_exact_when_fuzzy_disabled() { let _lock = TEST_MUTEX.lock().unwrap(); @@ -105,3 +114,89 @@ fn snippet_edit_command_unfiltered() { app.search(); assert_eq!(app.results.len(), 1); } + +#[test] +fn note_today_returns_resolved_note_action_when_exact_match_enabled() { + let _lock = TEST_MUTEX.lock().unwrap(); + let dir = tempdir().unwrap(); + std::env::set_current_dir(dir.path()).unwrap(); + setup_notes_env(&dir); + + let mut settings = Settings::default(); + settings.match_exact = true; + let ctx = egui::Context::default(); + let mut app = new_app(&ctx, settings); + + app.query = "note today".into(); + app.search(); + + assert!(!app.results.is_empty()); + assert!( + app.results + .iter() + .any(|result| result.action.starts_with("note:new:")) + ); + assert!( + app.results + .iter() + .all(|result| !result.action.starts_with("query:")) + ); +} + +#[test] +fn note_search_matches_note_content_when_exact_match_enabled() { + let _lock = TEST_MUTEX.lock().unwrap(); + let dir = tempdir().unwrap(); + std::env::set_current_dir(dir.path()).unwrap(); + setup_notes_env(&dir); + append_note("alpha", "ordinary body").unwrap(); + append_note("beta", "contains unique needle in content").unwrap(); + + let mut settings = Settings::default(); + settings.match_exact = true; + let ctx = egui::Context::default(); + let mut app = new_app(&ctx, settings); + + app.query = "note search needle".into(); + app.search(); + + assert!(!app.results.is_empty()); + assert!( + app.results + .iter() + .any(|result| result.action == "note:open:beta") + ); + assert!( + app.results + .iter() + .all(|result| !result.action.starts_with("query:")) + ); +} + +#[test] +fn note_new_generates_slugged_action_when_exact_match_enabled() { + let _lock = TEST_MUTEX.lock().unwrap(); + let dir = tempdir().unwrap(); + std::env::set_current_dir(dir.path()).unwrap(); + setup_notes_env(&dir); + + let mut settings = Settings::default(); + settings.match_exact = true; + let ctx = egui::Context::default(); + let mut app = new_app(&ctx, settings); + + app.query = "note new Hello World".into(); + app.search(); + + assert!(!app.results.is_empty()); + assert!( + app.results + .iter() + .any(|result| result.action == "note:new:hello-world") + ); + assert!( + app.results + .iter() + .all(|result| !result.action.starts_with("query:")) + ); +}