From d2c816f1650be367a06ab9fdd34ec1c3a6bc8531 Mon Sep 17 00:00:00 2001 From: Tatsuya Kyushima <49891479+kyu08@users.noreply.github.com> Date: Thu, 4 Jan 2024 15:04:39 +0900 Subject: [PATCH] Add unit test for #188 (#191) --- src/usecase/fzf_make/app.rs | 54 +++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/usecase/fzf_make/app.rs b/src/usecase/fzf_make/app.rs index 3e673eb4..fb903cb1 100644 --- a/src/usecase/fzf_make/app.rs +++ b/src/usecase/fzf_make/app.rs @@ -472,6 +472,60 @@ mod test { ..init_model() }, }, + Case { + title: "Next when there is no targets to select, panic should not occur", + model: { + let mut m = Model { + targets_list_state: ListState::with_selected(ListState::default(), None), + ..init_model() + }; + update( + // There should not be targets because init_model has ["target0", "target1", "target2"] as target. + &mut m, + Some(Message::SearchTextAreaKeyInput(KeyEvent::from( + KeyCode::Char('w'), + ))), + ); + m + }, + message: Some(Message::Next), + expect_model: Model { + targets_list_state: ListState::with_selected(ListState::default(), None), + search_text_area: { + let mut text_area = TextArea::default(); + text_area.input(KeyEvent::from(KeyCode::Char('w'))); + TextArea_(text_area) + }, + ..init_model() + }, + }, + Case { + title: "Previous when there is no targets to select, panic should not occur", + model: { + let mut m = Model { + targets_list_state: ListState::with_selected(ListState::default(), None), + ..init_model() + }; + update( + // There should not be targets because init_model has ["target0", "target1", "target2"] as target. + &mut m, + Some(Message::SearchTextAreaKeyInput(KeyEvent::from( + KeyCode::Char('w'), + ))), + ); + m + }, + message: Some(Message::Previous), + expect_model: Model { + targets_list_state: ListState::with_selected(ListState::default(), None), + search_text_area: { + let mut text_area = TextArea::default(); + text_area.input(KeyEvent::from(KeyCode::Char('w'))); + TextArea_(text_area) + }, + ..init_model() + }, + }, ]; for mut case in cases {