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:
2024-07-17 19:55:10 -06:00
parent 9104b7c356
commit d84e7dfcab
49 changed files with 5143 additions and 265 deletions
@@ -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());
}
}