From c54b0dc8b2488f98b182291821e09bef603ed223 Mon Sep 17 00:00:00 2001 From: thomasschafer Date: Mon, 2 Dec 2024 14:31:47 +0000 Subject: [PATCH] Add test for popup --- src/event.rs | 1 + tests/app.rs | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/event.rs b/src/event.rs index e15dfcb..b8d4c5d 100644 --- a/src/event.rs +++ b/src/event.rs @@ -50,6 +50,7 @@ pub struct EventHandler { pub app_event_sender: mpsc::UnboundedSender, } +#[derive(Debug)] pub struct EventHandlingResult { pub exit: bool, pub rerender: bool, diff --git a/tests/app.rs b/tests/app.rs index 8dcd516..69f5656 100644 --- a/tests/app.rs +++ b/tests/app.rs @@ -121,6 +121,42 @@ async fn test_back_from_results() { assert!(matches!(app.current_screen, Screen::SearchFields)); } +// TODO: replace this (and other tests?) with end-to-end tests +#[tokio::test] +async fn test_error_popup() { + let events = EventHandler::new(); + let mut app = App::new(None, false, events.app_event_sender.clone()); + app.current_screen = Screen::SearchFields; + app.search_fields = + SearchFields::with_values("search invalid regex(", "replacement", false, ""); + + let res = app.perform_search_if_valid(); + assert!(!res.exit); + assert!(matches!(app.current_screen, Screen::SearchFields)); + assert!(app.search_fields.show_error_popup); + + let res = app + .handle_key_events(&KeyEvent { + code: KeyCode::Esc, + modifiers: KeyModifiers::NONE, + kind: KeyEventKind::Press, + state: KeyEventState::NONE, + }) + .unwrap(); + assert!(!res.exit); + assert!(!app.search_fields.show_error_popup); + + let res = app + .handle_key_events(&KeyEvent { + code: KeyCode::Esc, + modifiers: KeyModifiers::NONE, + kind: KeyEventKind::Press, + state: KeyEventState::NONE, + }) + .unwrap(); + assert!(res.exit); +} + macro_rules! create_test_files { ($($name:expr => {$($line:expr),+ $(,)?}),+ $(,)?) => { {