From a65ad974cefba7a81422529571da301bc5aac7b2 Mon Sep 17 00:00:00 2001 From: Jeremy Wall Date: Sun, 29 Dec 2024 20:01:35 -0500 Subject: [PATCH] wip: test coverage for handle_dialog_input --- src/ui/test.rs | 48 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/src/ui/test.rs b/src/ui/test.rs index ae4792b..d240fcd 100644 --- a/src/ui/test.rs +++ b/src/ui/test.rs @@ -307,19 +307,43 @@ fn test_input_navitation_shift_tab_key() { assert_eq!(col, ws.book.location.col); } +macro_rules! assert_help_dialog { + ($exit : expr) => {{ + let mut ws = + Workspace::new_empty("en", "America/New_York").expect("Failed to get empty workbook"); + assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last()); + InputScript::default().char('i').run(&mut ws) + .expect("Failed to handle 'i' key"); + assert_eq!(Some(&Modality::CellEdit), ws.state.modality_stack.last()); + let edit_help = ws.render_help_text(); + InputScript::default().alt('h').run(&mut ws) + .expect("Failed to handle 'alt-h' key event"); + assert_eq!(Some(&Modality::Dialog), ws.state.modality_stack.last()); + assert_eq!(edit_help, ws.state.popup); + $exit.run(&mut ws) + .expect("Failed to handle key event"); + assert_eq!(Some(&Modality::CellEdit), ws.state.modality_stack.last()); + }}; +} + #[test] -fn test_edit_mode_help_keycode() { - let mut ws = - Workspace::new_empty("en", "America/New_York").expect("Failed to get empty workbook"); - assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last()); - InputScript::default().char('i').run(&mut ws) - .expect("Failed to handle 'i' key"); - assert_eq!(Some(&Modality::CellEdit), ws.state.modality_stack.last()); - let edit_help = ws.render_help_text(); - InputScript::default().alt('h').run(&mut ws) - .expect("Failed to handle 'alt-h' key event"); - assert_eq!(Some(&Modality::Dialog), ws.state.modality_stack.last()); - assert_eq!(edit_help, ws.state.popup); +fn test_edit_mode_help_keycode_esc() { + assert_help_dialog!(InputScript::default().esc()); +} + +#[test] +fn test_edit_mode_help_keycode_enter() { + assert_help_dialog!(InputScript::default().enter()); +} + +#[test] +fn test_edit_mode_help_keycode_q() { + assert_help_dialog!(InputScript::default().char('q')); +} + +#[test] +fn test_edit_mode_help_keycode_alt_h() { + assert_help_dialog!(InputScript::default().alt('h')); } #[test]