Skip to content

Commit

Permalink
Add test for popup
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasschafer committed Dec 2, 2024
1 parent 94cb8e6 commit c54b0dc
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub struct EventHandler {
pub app_event_sender: mpsc::UnboundedSender<AppEvent>,
}

#[derive(Debug)]
pub struct EventHandlingResult {
pub exit: bool,
pub rerender: bool,
Expand Down
36 changes: 36 additions & 0 deletions tests/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),+ $(,)?}),+ $(,)?) => {
{
Expand Down

0 comments on commit c54b0dc

Please sign in to comment.