Refactored to require handlers to specify the components they rely on and to specify when they are ready. This fixes a lot of bugs with the UI when users try to press buttons while the application is still loading.
This commit is contained in:
@@ -43,6 +43,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for CollectionDetailsHan
|
||||
self.key
|
||||
}
|
||||
|
||||
fn is_ready(&self) -> bool {
|
||||
!self.app.is_loading && !self.app.data.radarr_data.collection_movies.is_empty()
|
||||
}
|
||||
|
||||
fn handle_scroll_up(&mut self) {
|
||||
if ActiveRadarrBlock::CollectionDetails == *self.active_radarr_block {
|
||||
self.app.data.radarr_data.collection_movies.scroll_up()
|
||||
|
||||
@@ -31,6 +31,53 @@ mod tests {
|
||||
title,
|
||||
to_string
|
||||
);
|
||||
|
||||
#[rstest]
|
||||
fn test_collection_details_scroll_no_op_when_not_ready(
|
||||
#[values(
|
||||
DEFAULT_KEYBINDINGS.up.key, DEFAULT_KEYBINDINGS.down.key
|
||||
)]
|
||||
key: Key,
|
||||
) {
|
||||
let mut app = App::default();
|
||||
app.is_loading = true;
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collection_movies
|
||||
.set_items(simple_stateful_iterable_vec!(
|
||||
CollectionMovie,
|
||||
HorizontallyScrollableText
|
||||
));
|
||||
|
||||
CollectionDetailsHandler::with(&key, &mut app, &ActiveRadarrBlock::CollectionDetails, &None)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collection_movies
|
||||
.current_selection()
|
||||
.title
|
||||
.to_string(),
|
||||
"Test 1"
|
||||
);
|
||||
|
||||
CollectionDetailsHandler::with(&key, &mut app, &ActiveRadarrBlock::CollectionDetails, &None)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collection_movies
|
||||
.current_selection()
|
||||
.title
|
||||
.to_string(),
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_home_end {
|
||||
@@ -48,6 +95,58 @@ mod tests {
|
||||
title,
|
||||
to_string
|
||||
);
|
||||
|
||||
#[test]
|
||||
fn test_collection_details_home_end_no_op_when_not_ready() {
|
||||
let mut app = App::default();
|
||||
app.is_loading = true;
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collection_movies
|
||||
.set_items(extended_stateful_iterable_vec!(
|
||||
CollectionMovie,
|
||||
HorizontallyScrollableText
|
||||
));
|
||||
|
||||
CollectionDetailsHandler::with(
|
||||
&DEFAULT_KEYBINDINGS.end.key,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::CollectionDetails,
|
||||
&None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collection_movies
|
||||
.current_selection()
|
||||
.title
|
||||
.to_string(),
|
||||
"Test 1"
|
||||
);
|
||||
|
||||
CollectionDetailsHandler::with(
|
||||
&DEFAULT_KEYBINDINGS.home.key,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::CollectionDetails,
|
||||
&None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collection_movies
|
||||
.current_selection()
|
||||
.title
|
||||
.to_string(),
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_submit {
|
||||
@@ -139,6 +238,32 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_collection_details_submit_no_op_when_not_ready() {
|
||||
let mut app = App::default();
|
||||
app.is_loading = true;
|
||||
app.push_navigation_stack(ActiveRadarrBlock::CollectionDetails.into());
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collection_movies
|
||||
.set_items(vec![CollectionMovie::default()]);
|
||||
|
||||
CollectionDetailsHandler::with(
|
||||
&SUBMIT_KEY,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::CollectionDetails,
|
||||
&None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
&ActiveRadarrBlock::CollectionDetails.into()
|
||||
);
|
||||
assert!(app.data.radarr_data.add_movie_modal.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_collection_details_submit_movie_already_in_library() {
|
||||
let mut app = App::default();
|
||||
@@ -169,15 +294,16 @@ mod tests {
|
||||
}
|
||||
|
||||
mod test_handle_esc {
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
use super::*;
|
||||
use pretty_assertions::assert_eq;
|
||||
use rstest::rstest;
|
||||
|
||||
const ESC_KEY: Key = DEFAULT_KEYBINDINGS.esc.key;
|
||||
|
||||
#[test]
|
||||
fn test_esc_collection_details() {
|
||||
#[rstest]
|
||||
fn test_esc_collection_details(#[values(true, false)] is_ready: bool) {
|
||||
let mut app = App::default();
|
||||
app.is_loading = is_ready;
|
||||
app.push_navigation_stack(ActiveRadarrBlock::Collections.into());
|
||||
app.push_navigation_stack(ActiveRadarrBlock::CollectionDetails.into());
|
||||
app
|
||||
@@ -225,7 +351,6 @@ mod tests {
|
||||
mod test_handle_key_char {
|
||||
use bimap::BiMap;
|
||||
use pretty_assertions::{assert_eq, assert_str_eq};
|
||||
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
use crate::models::radarr_models::{Collection, MinimumAvailability};
|
||||
@@ -233,7 +358,6 @@ mod tests {
|
||||
use crate::models::servarr_data::radarr::radarr_data::{
|
||||
RadarrData, EDIT_COLLECTION_SELECTION_BLOCKS,
|
||||
};
|
||||
|
||||
use crate::test_edit_collection_key;
|
||||
|
||||
use super::*;
|
||||
@@ -246,6 +370,37 @@ mod tests {
|
||||
ActiveRadarrBlock::CollectionDetails
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_edit_key_no_op_when_not_ready() {
|
||||
let mut app = App::default();
|
||||
app.is_loading = true;
|
||||
app.push_navigation_stack(ActiveRadarrBlock::CollectionDetails.into());
|
||||
let mut radarr_data = create_test_radarr_data();
|
||||
radarr_data.collections.set_items(vec![Collection {
|
||||
root_folder_path: "/nfs/movies/Test".to_owned().into(),
|
||||
monitored: true,
|
||||
search_on_add: true,
|
||||
quality_profile_id: 2222,
|
||||
minimum_availability: MinimumAvailability::Released,
|
||||
..Collection::default()
|
||||
}]);
|
||||
app.data.radarr_data = radarr_data;
|
||||
|
||||
CollectionDetailsHandler::with(
|
||||
&DEFAULT_KEYBINDINGS.edit.key,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::CollectionDetails,
|
||||
&None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
&ActiveRadarrBlock::CollectionDetails.into()
|
||||
);
|
||||
assert!(app.data.radarr_data.edit_collection_modal.is_none());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -258,4 +413,54 @@ mod tests {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_collection_details_handler_not_ready_when_loading() {
|
||||
let mut app = App::default();
|
||||
app.is_loading = true;
|
||||
|
||||
let handler = CollectionDetailsHandler::with(
|
||||
&DEFAULT_KEYBINDINGS.esc.key,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::CollectionDetails,
|
||||
&None,
|
||||
);
|
||||
|
||||
assert!(!handler.is_ready());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_collection_details_handler_not_ready_when_collection_movies_is_empty() {
|
||||
let mut app = App::default();
|
||||
app.is_loading = false;
|
||||
|
||||
let handler = CollectionDetailsHandler::with(
|
||||
&DEFAULT_KEYBINDINGS.esc.key,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::CollectionDetails,
|
||||
&None,
|
||||
);
|
||||
|
||||
assert!(!handler.is_ready());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_collection_details_handler_ready_when_not_loading_and_collection_movies_is_not_empty() {
|
||||
let mut app = App::default();
|
||||
app.is_loading = false;
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collection_movies
|
||||
.set_items(vec![CollectionMovie::default()]);
|
||||
|
||||
let handler = CollectionDetailsHandler::with(
|
||||
&DEFAULT_KEYBINDINGS.esc.key,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::CollectionDetails,
|
||||
&None,
|
||||
);
|
||||
|
||||
assert!(handler.is_ready());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use pretty_assertions::{assert_eq, assert_str_eq};
|
||||
use rstest::rstest;
|
||||
use std::cmp::Ordering;
|
||||
use std::iter;
|
||||
|
||||
use pretty_assertions::{assert_eq, assert_str_eq};
|
||||
use rstest::rstest;
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
use crate::app::key_binding::DEFAULT_KEYBINDINGS;
|
||||
@@ -22,10 +23,10 @@ mod tests {
|
||||
use crate::{extended_stateful_iterable_vec, test_handler_delegation};
|
||||
|
||||
mod test_handle_scroll_up_and_down {
|
||||
use pretty_assertions::assert_eq;
|
||||
use rstest::rstest;
|
||||
|
||||
use crate::{simple_stateful_iterable_vec, test_iterable_scroll};
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
use super::*;
|
||||
|
||||
@@ -40,6 +41,51 @@ mod tests {
|
||||
to_string
|
||||
);
|
||||
|
||||
#[rstest]
|
||||
fn test_collections_scroll_no_op_when_not_ready(
|
||||
#[values(
|
||||
DEFAULT_KEYBINDINGS.up.key, DEFAULT_KEYBINDINGS.down.key
|
||||
)]
|
||||
key: Key,
|
||||
) {
|
||||
let mut app = App::default();
|
||||
app.is_loading = true;
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.set_items(simple_stateful_iterable_vec!(
|
||||
Collection,
|
||||
HorizontallyScrollableText
|
||||
));
|
||||
|
||||
CollectionsHandler::with(&key, &mut app, &ActiveRadarrBlock::Collections, &None).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.current_selection()
|
||||
.title
|
||||
.to_string(),
|
||||
"Test 1"
|
||||
);
|
||||
|
||||
CollectionsHandler::with(&key, &mut app, &ActiveRadarrBlock::Collections, &None).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.current_selection()
|
||||
.title
|
||||
.to_string(),
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_collections_sort_scroll(
|
||||
#[values(DEFAULT_KEYBINDINGS.up.key, DEFAULT_KEYBINDINGS.down.key)] key: Key,
|
||||
@@ -114,9 +160,66 @@ mod tests {
|
||||
to_string
|
||||
);
|
||||
|
||||
#[test]
|
||||
fn test_collections_home_end_no_op_when_not_ready() {
|
||||
let mut app = App::default();
|
||||
app.is_loading = true;
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.set_items(extended_stateful_iterable_vec!(
|
||||
Collection,
|
||||
HorizontallyScrollableText
|
||||
));
|
||||
|
||||
CollectionsHandler::with(
|
||||
&DEFAULT_KEYBINDINGS.end.key,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::Collections,
|
||||
&None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.current_selection()
|
||||
.title
|
||||
.to_string(),
|
||||
"Test 1"
|
||||
);
|
||||
|
||||
CollectionsHandler::with(
|
||||
&DEFAULT_KEYBINDINGS.home.key,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::Collections,
|
||||
&None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.current_selection()
|
||||
.title
|
||||
.to_string(),
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_collection_search_box_home_end_keys() {
|
||||
let mut app = App::default();
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.set_items(vec![Collection::default()]);
|
||||
app.data.radarr_data.collections.search = Some("Test".into());
|
||||
|
||||
CollectionsHandler::with(
|
||||
@@ -165,6 +268,11 @@ mod tests {
|
||||
#[test]
|
||||
fn test_collection_filter_box_home_end_keys() {
|
||||
let mut app = App::default();
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.set_items(vec![Collection::default()]);
|
||||
app.data.radarr_data.collections.filter = Some("Test".into());
|
||||
|
||||
CollectionsHandler::with(
|
||||
@@ -264,9 +372,10 @@ mod tests {
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_collections_tab_left() {
|
||||
#[rstest]
|
||||
fn test_collections_tab_left(#[values(true, false)] is_ready: bool) {
|
||||
let mut app = App::default();
|
||||
app.is_loading = is_ready;
|
||||
app.data.radarr_data.main_tabs.set_index(1);
|
||||
|
||||
CollectionsHandler::with(
|
||||
@@ -284,9 +393,10 @@ mod tests {
|
||||
assert_eq!(app.get_current_route(), &ActiveRadarrBlock::Movies.into());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_collections_tab_right() {
|
||||
#[rstest]
|
||||
fn test_collections_tab_right(#[values(true, false)] is_ready: bool) {
|
||||
let mut app = App::default();
|
||||
app.is_loading = is_ready;
|
||||
app.data.radarr_data.main_tabs.set_index(1);
|
||||
|
||||
CollectionsHandler::with(
|
||||
@@ -443,6 +553,11 @@ mod tests {
|
||||
#[test]
|
||||
fn test_collections_submit() {
|
||||
let mut app = App::default();
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.set_items(vec![Collection::default()]);
|
||||
|
||||
CollectionsHandler::with(
|
||||
&SUBMIT_KEY,
|
||||
@@ -458,6 +573,31 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_collections_submit_no_op_when_not_ready() {
|
||||
let mut app = App::default();
|
||||
app.is_loading = true;
|
||||
app.push_navigation_stack(ActiveRadarrBlock::Collections.into());
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.set_items(vec![Collection::default()]);
|
||||
|
||||
CollectionsHandler::with(
|
||||
&SUBMIT_KEY,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::Collections,
|
||||
&None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
&ActiveRadarrBlock::Collections.into()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_search_collections_submit() {
|
||||
let mut app = App::default();
|
||||
@@ -661,6 +801,11 @@ mod tests {
|
||||
#[test]
|
||||
fn test_update_all_collections_prompt_confirm_submit() {
|
||||
let mut app = App::default();
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.set_items(vec![Collection::default()]);
|
||||
app.data.radarr_data.prompt_confirm = true;
|
||||
app.push_navigation_stack(ActiveRadarrBlock::Collections.into());
|
||||
app.push_navigation_stack(ActiveRadarrBlock::UpdateAllCollectionsPrompt.into());
|
||||
@@ -687,6 +832,11 @@ mod tests {
|
||||
#[test]
|
||||
fn test_update_all_collections_prompt_decline_submit() {
|
||||
let mut app = App::default();
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.set_items(vec![Collection::default()]);
|
||||
app.push_navigation_stack(ActiveRadarrBlock::Collections.into());
|
||||
app.push_navigation_stack(ActiveRadarrBlock::UpdateAllCollectionsPrompt.into());
|
||||
|
||||
@@ -849,9 +999,10 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_default_esc() {
|
||||
#[rstest]
|
||||
fn test_default_esc(#[values(true, false)] is_ready: bool) {
|
||||
let mut app = App::default();
|
||||
app.is_loading = is_ready;
|
||||
app.error = "test error".to_owned().into();
|
||||
app.push_navigation_stack(ActiveRadarrBlock::Collections.into());
|
||||
app.push_navigation_stack(ActiveRadarrBlock::Collections.into());
|
||||
@@ -881,7 +1032,6 @@ mod tests {
|
||||
mod test_handle_key_char {
|
||||
use bimap::BiMap;
|
||||
use pretty_assertions::{assert_eq, assert_str_eq};
|
||||
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
use crate::models::radarr_models::MinimumAvailability;
|
||||
@@ -889,15 +1039,18 @@ mod tests {
|
||||
use crate::models::servarr_data::radarr::radarr_data::{
|
||||
RadarrData, EDIT_COLLECTION_SELECTION_BLOCKS,
|
||||
};
|
||||
|
||||
use crate::models::stateful_table::StatefulTable;
|
||||
use crate::{assert_refresh_key, test_edit_collection_key};
|
||||
use crate::test_edit_collection_key;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_search_collections_key() {
|
||||
let mut app = App::default();
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.set_items(vec![Collection::default()]);
|
||||
|
||||
CollectionsHandler::with(
|
||||
&DEFAULT_KEYBINDINGS.search.key,
|
||||
@@ -918,9 +1071,41 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_search_collections_key_no_op_when_not_ready() {
|
||||
let mut app = App::default();
|
||||
app.is_loading = true;
|
||||
app.push_navigation_stack(ActiveRadarrBlock::Collections.into());
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.set_items(vec![Collection::default()]);
|
||||
|
||||
CollectionsHandler::with(
|
||||
&DEFAULT_KEYBINDINGS.search.key,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::Collections,
|
||||
&None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
&ActiveRadarrBlock::Collections.into()
|
||||
);
|
||||
assert!(!app.should_ignore_quit_key);
|
||||
assert_eq!(app.data.radarr_data.collections.search, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_filter_collections_key() {
|
||||
let mut app = App::default();
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.set_items(vec![Collection::default()]);
|
||||
|
||||
CollectionsHandler::with(
|
||||
&DEFAULT_KEYBINDINGS.filter.key,
|
||||
@@ -938,13 +1123,44 @@ mod tests {
|
||||
assert!(app.data.radarr_data.collections.filter.is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_filter_collections_key_no_op_when_not_ready() {
|
||||
let mut app = App::default();
|
||||
app.is_loading = true;
|
||||
app.push_navigation_stack(ActiveRadarrBlock::Collections.into());
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.set_items(vec![Collection::default()]);
|
||||
|
||||
CollectionsHandler::with(
|
||||
&DEFAULT_KEYBINDINGS.filter.key,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::Collections,
|
||||
&None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
&ActiveRadarrBlock::Collections.into()
|
||||
);
|
||||
assert!(!app.should_ignore_quit_key);
|
||||
assert!(app.data.radarr_data.collections.filter.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_filter_collections_key_resets_previous_filter() {
|
||||
let mut app = App::default();
|
||||
app.data.radarr_data = create_test_radarr_data();
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.set_items(vec![Collection::default()]);
|
||||
app.should_ignore_quit_key = true;
|
||||
app.push_navigation_stack(ActiveRadarrBlock::Collections.into());
|
||||
app.data.radarr_data = create_test_radarr_data();
|
||||
app.data.radarr_data.collections = StatefulTable::default();
|
||||
app.data.radarr_data.collections.filter = Some("Test".into());
|
||||
|
||||
CollectionsHandler::with(
|
||||
@@ -977,9 +1193,45 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_collection_edit_key_no_op_when_not_ready() {
|
||||
let mut app = App::default();
|
||||
app.is_loading = true;
|
||||
app.push_navigation_stack(ActiveRadarrBlock::Collections.into());
|
||||
let mut radarr_data = create_test_radarr_data();
|
||||
radarr_data.collections.set_items(vec![Collection {
|
||||
root_folder_path: "/nfs/movies/Test".to_owned().into(),
|
||||
monitored: true,
|
||||
search_on_add: true,
|
||||
quality_profile_id: 2222,
|
||||
minimum_availability: MinimumAvailability::Released,
|
||||
..Collection::default()
|
||||
}]);
|
||||
app.data.radarr_data = radarr_data;
|
||||
|
||||
CollectionsHandler::with(
|
||||
&DEFAULT_KEYBINDINGS.edit.key,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::Collections,
|
||||
&None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
&ActiveRadarrBlock::Collections.into()
|
||||
);
|
||||
assert!(app.data.radarr_data.edit_collection_modal.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_update_key() {
|
||||
let mut app = App::default();
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.set_items(vec![Collection::default()]);
|
||||
|
||||
CollectionsHandler::with(
|
||||
&DEFAULT_KEYBINDINGS.update.key,
|
||||
@@ -995,14 +1247,90 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_update_key_no_op_when_not_ready() {
|
||||
let mut app = App::default();
|
||||
app.is_loading = true;
|
||||
app.push_navigation_stack(ActiveRadarrBlock::Collections.into());
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.set_items(vec![Collection::default()]);
|
||||
|
||||
CollectionsHandler::with(
|
||||
&DEFAULT_KEYBINDINGS.update.key,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::Collections,
|
||||
&None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
&ActiveRadarrBlock::Collections.into()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_refresh_collections_key() {
|
||||
assert_refresh_key!(CollectionsHandler, ActiveRadarrBlock::Collections);
|
||||
let mut app = App::default();
|
||||
app.push_navigation_stack(ActiveRadarrBlock::Collections.into());
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.set_items(vec![Collection::default()]);
|
||||
|
||||
CollectionsHandler::with(
|
||||
&DEFAULT_KEYBINDINGS.refresh.key,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::Collections,
|
||||
&None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
&ActiveRadarrBlock::Collections.into()
|
||||
);
|
||||
assert!(app.should_refresh);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_refresh_collections_key_no_op_when_not_ready() {
|
||||
let mut app = App::default();
|
||||
app.is_loading = true;
|
||||
app.push_navigation_stack(ActiveRadarrBlock::Collections.into());
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.set_items(vec![Collection::default()]);
|
||||
|
||||
CollectionsHandler::with(
|
||||
&DEFAULT_KEYBINDINGS.refresh.key,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::Collections,
|
||||
&None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
&ActiveRadarrBlock::Collections.into()
|
||||
);
|
||||
assert!(!app.should_refresh);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_search_collections_box_backspace_key() {
|
||||
let mut app = App::default();
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.set_items(vec![Collection::default()]);
|
||||
app.data.radarr_data.collections.search = Some("Test".into());
|
||||
|
||||
CollectionsHandler::with(
|
||||
@@ -1029,7 +1357,11 @@ mod tests {
|
||||
#[test]
|
||||
fn test_filter_collections_box_backspace_key() {
|
||||
let mut app = App::default();
|
||||
app.data.radarr_data.collections = StatefulTable::default();
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.set_items(vec![Collection::default()]);
|
||||
app.data.radarr_data.collections.filter = Some("Test".into());
|
||||
|
||||
CollectionsHandler::with(
|
||||
@@ -1056,6 +1388,11 @@ mod tests {
|
||||
#[test]
|
||||
fn test_search_collections_box_char_key() {
|
||||
let mut app = App::default();
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.set_items(vec![Collection::default()]);
|
||||
app.data.radarr_data.collections.search = Some(HorizontallyScrollableText::default());
|
||||
|
||||
CollectionsHandler::with(
|
||||
@@ -1082,7 +1419,11 @@ mod tests {
|
||||
#[test]
|
||||
fn test_filter_collections_box_char_key() {
|
||||
let mut app = App::default();
|
||||
app.data.radarr_data.collections = StatefulTable::default();
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.set_items(vec![Collection::default()]);
|
||||
app.data.radarr_data.collections.filter = Some(HorizontallyScrollableText::default());
|
||||
|
||||
CollectionsHandler::with(
|
||||
@@ -1109,6 +1450,11 @@ mod tests {
|
||||
#[test]
|
||||
fn test_sort_key() {
|
||||
let mut app = App::default();
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.set_items(vec![Collection::default()]);
|
||||
|
||||
CollectionsHandler::with(
|
||||
&DEFAULT_KEYBINDINGS.sort.key,
|
||||
@@ -1135,6 +1481,33 @@ mod tests {
|
||||
);
|
||||
assert!(!app.data.radarr_data.collections.sort_asc);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sort_key_no_op_when_not_ready() {
|
||||
let mut app = App::default();
|
||||
app.is_loading = true;
|
||||
app.push_navigation_stack(ActiveRadarrBlock::Collections.into());
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.set_items(vec![Collection::default()]);
|
||||
|
||||
CollectionsHandler::with(
|
||||
&DEFAULT_KEYBINDINGS.sort.key,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::Collections,
|
||||
&None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
&ActiveRadarrBlock::Collections.into()
|
||||
);
|
||||
assert!(app.data.radarr_data.collections.sort.is_none());
|
||||
assert!(!app.data.radarr_data.collections.sort_asc);
|
||||
}
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
@@ -1279,6 +1652,72 @@ mod tests {
|
||||
assert_str_eq!(sort_option.name, "Monitored");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_collections_handler_accepts() {
|
||||
let mut collections_handler_blocks = Vec::new();
|
||||
collections_handler_blocks.extend(COLLECTIONS_BLOCKS);
|
||||
collections_handler_blocks.extend(COLLECTION_DETAILS_BLOCKS);
|
||||
collections_handler_blocks.extend(EDIT_COLLECTION_BLOCKS);
|
||||
|
||||
ActiveRadarrBlock::iter().for_each(|active_radarr_block| {
|
||||
if collections_handler_blocks.contains(&active_radarr_block) {
|
||||
assert!(CollectionsHandler::accepts(&active_radarr_block));
|
||||
} else {
|
||||
assert!(!CollectionsHandler::accepts(&active_radarr_block));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_collections_handler_not_ready_when_loading() {
|
||||
let mut app = App::default();
|
||||
app.is_loading = true;
|
||||
|
||||
let handler = CollectionsHandler::with(
|
||||
&DEFAULT_KEYBINDINGS.esc.key,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::Collections,
|
||||
&None,
|
||||
);
|
||||
|
||||
assert!(!handler.is_ready());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_collections_handler_not_ready_when_collections_is_empty() {
|
||||
let mut app = App::default();
|
||||
app.is_loading = false;
|
||||
|
||||
let handler = CollectionsHandler::with(
|
||||
&DEFAULT_KEYBINDINGS.esc.key,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::Collections,
|
||||
&None,
|
||||
);
|
||||
|
||||
assert!(!handler.is_ready());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_collections_handler_ready_when_not_loading_and_collections_is_not_empty() {
|
||||
let mut app = App::default();
|
||||
app.is_loading = false;
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.set_items(vec![Collection::default()]);
|
||||
|
||||
let handler = CollectionsHandler::with(
|
||||
&DEFAULT_KEYBINDINGS.esc.key,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::Collections,
|
||||
&None,
|
||||
);
|
||||
|
||||
assert!(handler.is_ready());
|
||||
}
|
||||
|
||||
fn collections_vec() -> Vec<Collection> {
|
||||
vec![
|
||||
Collection {
|
||||
@@ -1325,20 +1764,4 @@ mod tests {
|
||||
}),
|
||||
}]
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_collections_handler_accepts() {
|
||||
let mut collections_handler_blocks = Vec::new();
|
||||
collections_handler_blocks.extend(COLLECTIONS_BLOCKS);
|
||||
collections_handler_blocks.extend(COLLECTION_DETAILS_BLOCKS);
|
||||
collections_handler_blocks.extend(EDIT_COLLECTION_BLOCKS);
|
||||
|
||||
ActiveRadarrBlock::iter().for_each(|active_radarr_block| {
|
||||
if collections_handler_blocks.contains(&active_radarr_block) {
|
||||
assert!(CollectionsHandler::accepts(&active_radarr_block));
|
||||
} else {
|
||||
assert!(!CollectionsHandler::accepts(&active_radarr_block));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for EditCollectionHandle
|
||||
self.key
|
||||
}
|
||||
|
||||
fn is_ready(&self) -> bool {
|
||||
!self.app.is_loading && self.app.data.radarr_data.edit_collection_modal.is_some()
|
||||
}
|
||||
|
||||
fn handle_scroll_up(&mut self) {
|
||||
match self.active_radarr_block {
|
||||
ActiveRadarrBlock::EditCollectionSelectMinimumAvailability => self
|
||||
|
||||
@@ -9,6 +9,7 @@ mod tests {
|
||||
use crate::handlers::radarr_handlers::collections::edit_collection_handler::EditCollectionHandler;
|
||||
use crate::handlers::KeyEventHandler;
|
||||
use crate::models::radarr_models::MinimumAvailability;
|
||||
use crate::models::servarr_data::radarr::modals::EditCollectionModal;
|
||||
use crate::models::servarr_data::radarr::radarr_data::{
|
||||
ActiveRadarrBlock, EDIT_COLLECTION_BLOCKS,
|
||||
};
|
||||
@@ -146,6 +147,7 @@ mod tests {
|
||||
#[rstest]
|
||||
fn test_edit_collection_prompt_scroll(#[values(Key::Up, Key::Down)] key: Key) {
|
||||
let mut app = App::default();
|
||||
app.data.radarr_data.edit_collection_modal = Some(EditCollectionModal::default());
|
||||
app.data.radarr_data.selected_block =
|
||||
BlockSelectionState::new(&EDIT_COLLECTION_SELECTION_BLOCKS);
|
||||
app.data.radarr_data.selected_block.next();
|
||||
@@ -170,6 +172,31 @@ mod tests {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_edit_collection_prompt_scroll_no_op_when_not_ready(
|
||||
#[values(Key::Up, Key::Down)] key: Key,
|
||||
) {
|
||||
let mut app = App::default();
|
||||
app.is_loading = true;
|
||||
app.data.radarr_data.edit_collection_modal = Some(EditCollectionModal::default());
|
||||
app.data.radarr_data.selected_block =
|
||||
BlockSelectionState::new(&EDIT_COLLECTION_SELECTION_BLOCKS);
|
||||
app.data.radarr_data.selected_block.next();
|
||||
|
||||
EditCollectionHandler::with(
|
||||
&key,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::EditCollectionPrompt,
|
||||
&None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app.data.radarr_data.selected_block.get_active_block(),
|
||||
&ActiveRadarrBlock::EditCollectionSelectMinimumAvailability
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_home_end {
|
||||
@@ -479,6 +506,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_edit_collection_prompt_prompt_decline_submit() {
|
||||
let mut app = App::default();
|
||||
app.data.radarr_data.edit_collection_modal = Some(EditCollectionModal::default());
|
||||
app.push_navigation_stack(ActiveRadarrBlock::Collections.into());
|
||||
app.push_navigation_stack(ActiveRadarrBlock::EditCollectionPrompt.into());
|
||||
app.data.radarr_data.selected_block =
|
||||
@@ -507,6 +535,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_edit_collection_confirm_prompt_prompt_confirmation_submit() {
|
||||
let mut app = App::default();
|
||||
app.data.radarr_data.edit_collection_modal = Some(EditCollectionModal::default());
|
||||
app.push_navigation_stack(ActiveRadarrBlock::Collections.into());
|
||||
app.push_navigation_stack(ActiveRadarrBlock::EditCollectionPrompt.into());
|
||||
app.data.radarr_data.prompt_confirm = true;
|
||||
@@ -537,6 +566,38 @@ mod tests {
|
||||
assert!(app.should_refresh);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_edit_collection_confirm_prompt_prompt_confirmation_submit_no_op_when_not_ready() {
|
||||
let mut app = App::default();
|
||||
app.is_loading = true;
|
||||
app.data.radarr_data.edit_collection_modal = Some(EditCollectionModal::default());
|
||||
app.push_navigation_stack(ActiveRadarrBlock::Collections.into());
|
||||
app.push_navigation_stack(ActiveRadarrBlock::EditCollectionPrompt.into());
|
||||
app.data.radarr_data.prompt_confirm = true;
|
||||
app.data.radarr_data.selected_block =
|
||||
BlockSelectionState::new(&EDIT_COLLECTION_SELECTION_BLOCKS);
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.selected_block
|
||||
.set_index(EDIT_COLLECTION_SELECTION_BLOCKS.len() - 1);
|
||||
|
||||
EditCollectionHandler::with(
|
||||
&SUBMIT_KEY,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::EditCollectionPrompt,
|
||||
&None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
&ActiveRadarrBlock::EditCollectionPrompt.into()
|
||||
);
|
||||
assert_eq!(app.data.radarr_data.prompt_confirm_action, None);
|
||||
assert!(!app.should_refresh);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_edit_collection_toggle_monitored_submit() {
|
||||
let current_route = Route::from((
|
||||
@@ -657,6 +718,7 @@ mod tests {
|
||||
#[case] index: usize,
|
||||
) {
|
||||
let mut app = App::default();
|
||||
app.data.radarr_data.edit_collection_modal = Some(EditCollectionModal::default());
|
||||
app.push_navigation_stack(
|
||||
(
|
||||
ActiveRadarrBlock::EditCollectionPrompt,
|
||||
@@ -697,6 +759,7 @@ mod tests {
|
||||
active_radarr_block: ActiveRadarrBlock,
|
||||
) {
|
||||
let mut app = App::default();
|
||||
app.data.radarr_data.edit_collection_modal = Some(EditCollectionModal::default());
|
||||
app.push_navigation_stack(ActiveRadarrBlock::EditCollectionPrompt.into());
|
||||
app.push_navigation_stack(active_radarr_block.into());
|
||||
|
||||
@@ -733,6 +796,7 @@ mod tests {
|
||||
fn test_edit_collection_root_folder_path_input_esc() {
|
||||
let mut app = App::default();
|
||||
app.data.radarr_data = create_test_radarr_data();
|
||||
app.data.radarr_data.edit_collection_modal = Some(EditCollectionModal::default());
|
||||
app.should_ignore_quit_key = true;
|
||||
app.push_navigation_stack(ActiveRadarrBlock::EditCollectionPrompt.into());
|
||||
app.push_navigation_stack(ActiveRadarrBlock::EditCollectionRootFolderPathInput.into());
|
||||
@@ -784,8 +848,10 @@ mod tests {
|
||||
ActiveRadarrBlock::EditCollectionSelectQualityProfile
|
||||
)]
|
||||
active_radarr_block: ActiveRadarrBlock,
|
||||
#[values(true, false)] is_ready: bool,
|
||||
) {
|
||||
let mut app = App::default();
|
||||
app.is_loading = is_ready;
|
||||
app.data.radarr_data = create_test_radarr_data();
|
||||
app.push_navigation_stack(ActiveRadarrBlock::Collections.into());
|
||||
app.push_navigation_stack(active_radarr_block.into());
|
||||
@@ -869,4 +935,50 @@ mod tests {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_edit_collection_handler_is_not_ready_when_loading() {
|
||||
let mut app = App::default();
|
||||
app.is_loading = true;
|
||||
|
||||
let handler = EditCollectionHandler::with(
|
||||
&DEFAULT_KEYBINDINGS.esc.key,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::EditCollectionPrompt,
|
||||
&None,
|
||||
);
|
||||
|
||||
assert!(!handler.is_ready());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_edit_collection_handler_is_not_ready_when_edit_collection_modal_is_none() {
|
||||
let mut app = App::default();
|
||||
app.is_loading = false;
|
||||
|
||||
let handler = EditCollectionHandler::with(
|
||||
&DEFAULT_KEYBINDINGS.esc.key,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::EditCollectionPrompt,
|
||||
&None,
|
||||
);
|
||||
|
||||
assert!(!handler.is_ready());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_edit_collection_handler_is_ready_when_edit_collection_modal_is_some() {
|
||||
let mut app = App::default();
|
||||
app.is_loading = false;
|
||||
app.data.radarr_data.edit_collection_modal = Some(EditCollectionModal::default());
|
||||
|
||||
let handler = EditCollectionHandler::with(
|
||||
&DEFAULT_KEYBINDINGS.esc.key,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::EditCollectionPrompt,
|
||||
&None,
|
||||
);
|
||||
|
||||
assert!(handler.is_ready());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,6 +67,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for CollectionsHandler<'
|
||||
self.key
|
||||
}
|
||||
|
||||
fn is_ready(&self) -> bool {
|
||||
!self.app.is_loading && !self.app.data.radarr_data.collections.is_empty()
|
||||
}
|
||||
|
||||
fn handle_scroll_up(&mut self) {
|
||||
match self.active_radarr_block {
|
||||
ActiveRadarrBlock::Collections => self.app.data.radarr_data.collections.scroll_up(),
|
||||
|
||||
Reference in New Issue
Block a user