Did a lot of things in this one: Cleaned up a bit of leftover unused code from yesterday; deprecated the use of drain() on HorizontallyScrollableText; Refactored the uses of search and filter to be wrapped in Options; Fixed a race condition when closing the Add Movie modals in rapid succession; upgraded to ratatui 0.22.0; Fixed a bug in attempting to close an empty root folder; fixed a bug in attempting to close an empty filter; fixed a bug in attempting to close an empty search; fixed a bug in attempting to close an empty filter without resetting the view; fixed a bug in attempting to delete a movie after dynamically added one and updating the main library table

This commit is contained in:
2023-08-08 10:50:07 -06:00
parent 2d624e2648
commit 77fd9e621f
28 changed files with 1151 additions and 352 deletions
@@ -48,9 +48,7 @@ mod tests {
mod test_handle_home_end {
use pretty_assertions::assert_eq;
use crate::{
extended_stateful_iterable_vec, test_iterable_home_and_end, test_text_box_home_end_keys,
};
use crate::{extended_stateful_iterable_vec, test_iterable_home_and_end};
use super::*;
@@ -78,12 +76,94 @@ mod tests {
#[test]
fn test_movie_search_box_home_end_keys() {
test_text_box_home_end_keys!(LibraryHandler, ActiveRadarrBlock::SearchMovie, search);
let mut app = App::default();
app.data.radarr_data.search = Some("Test".into());
LibraryHandler::with(
&DEFAULT_KEYBINDINGS.home.key,
&mut app,
&ActiveRadarrBlock::SearchMovie,
&None,
)
.handle();
assert_eq!(
*app
.data
.radarr_data
.search
.as_ref()
.unwrap()
.offset
.borrow(),
4
);
LibraryHandler::with(
&DEFAULT_KEYBINDINGS.end.key,
&mut app,
&ActiveRadarrBlock::SearchMovie,
&None,
)
.handle();
assert_eq!(
*app
.data
.radarr_data
.search
.as_ref()
.unwrap()
.offset
.borrow(),
0
);
}
#[test]
fn test_movie_filter_box_home_end_keys() {
test_text_box_home_end_keys!(LibraryHandler, ActiveRadarrBlock::FilterMovies, filter);
let mut app = App::default();
app.data.radarr_data.filter = Some("Test".into());
LibraryHandler::with(
&DEFAULT_KEYBINDINGS.home.key,
&mut app,
&ActiveRadarrBlock::FilterMovies,
&None,
)
.handle();
assert_eq!(
*app
.data
.radarr_data
.filter
.as_ref()
.unwrap()
.offset
.borrow(),
4
);
LibraryHandler::with(
&DEFAULT_KEYBINDINGS.end.key,
&mut app,
&ActiveRadarrBlock::FilterMovies,
&None,
)
.handle();
assert_eq!(
*app
.data
.radarr_data
.filter
.as_ref()
.unwrap()
.offset
.borrow(),
0
);
}
}
@@ -118,8 +198,6 @@ mod tests {
use pretty_assertions::assert_eq;
use rstest::rstest;
use crate::test_text_box_left_right_keys;
use super::*;
#[test]
@@ -194,12 +272,94 @@ mod tests {
#[test]
fn test_movie_search_box_left_right_keys() {
test_text_box_left_right_keys!(LibraryHandler, ActiveRadarrBlock::SearchMovie, search);
let mut app = App::default();
app.data.radarr_data.search = Some("Test".into());
LibraryHandler::with(
&DEFAULT_KEYBINDINGS.left.key,
&mut app,
&ActiveRadarrBlock::SearchMovie,
&None,
)
.handle();
assert_eq!(
*app
.data
.radarr_data
.search
.as_ref()
.unwrap()
.offset
.borrow(),
1
);
LibraryHandler::with(
&DEFAULT_KEYBINDINGS.right.key,
&mut app,
&ActiveRadarrBlock::SearchMovie,
&None,
)
.handle();
assert_eq!(
*app
.data
.radarr_data
.search
.as_ref()
.unwrap()
.offset
.borrow(),
0
);
}
#[test]
fn test_movie_filter_box_left_right_keys() {
test_text_box_left_right_keys!(LibraryHandler, ActiveRadarrBlock::FilterMovies, filter);
let mut app = App::default();
app.data.radarr_data.filter = Some("Test".into());
LibraryHandler::with(
&DEFAULT_KEYBINDINGS.left.key,
&mut app,
&ActiveRadarrBlock::FilterMovies,
&None,
)
.handle();
assert_eq!(
*app
.data
.radarr_data
.filter
.as_ref()
.unwrap()
.offset
.borrow(),
1
);
LibraryHandler::with(
&DEFAULT_KEYBINDINGS.right.key,
&mut app,
&ActiveRadarrBlock::FilterMovies,
&None,
)
.handle();
assert_eq!(
*app
.data
.radarr_data
.filter
.as_ref()
.unwrap()
.offset
.borrow(),
0
);
}
}
@@ -236,7 +396,7 @@ mod tests {
Movie,
HorizontallyScrollableText
));
app.data.radarr_data.search = "Test 2".to_owned().into();
app.data.radarr_data.search = Some("Test 2".into());
LibraryHandler::with(
&SUBMIT_KEY,
@@ -263,7 +423,7 @@ mod tests {
Movie,
HorizontallyScrollableText
));
app.data.radarr_data.search = "Test 2".to_owned().into();
app.data.radarr_data.search = Some("Test 2".into());
LibraryHandler::with(
&SUBMIT_KEY,
@@ -296,7 +456,7 @@ mod tests {
Movie,
HorizontallyScrollableText
));
app.data.radarr_data.filter = "Test".to_owned().into();
app.data.radarr_data.filter = Some("Test".into());
LibraryHandler::with(
&SUBMIT_KEY,
@@ -473,6 +633,7 @@ mod tests {
);
assert!(app.data.radarr_data.is_searching);
assert!(app.should_ignore_quit_key);
assert!(app.data.radarr_data.search.is_some());
}
#[test]
@@ -493,10 +654,11 @@ mod tests {
);
assert!(app.data.radarr_data.is_filtering);
assert!(app.should_ignore_quit_key);
assert!(app.data.radarr_data.filter.is_some());
}
#[test]
fn test_movie_add() {
fn test_movie_add_key() {
let mut app = App::default();
LibraryHandler::with(
@@ -512,6 +674,7 @@ mod tests {
&ActiveRadarrBlock::AddMovieSearchInput.into()
);
assert!(app.should_ignore_quit_key);
assert!(app.data.radarr_data.search.is_some());
}
#[test]
@@ -549,7 +712,7 @@ mod tests {
#[test]
fn test_search_movies_box_backspace_key() {
let mut app = App::default();
app.data.radarr_data.search = "Test".to_owned().into();
app.data.radarr_data.search = Some("Test".into());
LibraryHandler::with(
&DEFAULT_KEYBINDINGS.backspace.key,
@@ -559,13 +722,13 @@ mod tests {
)
.handle();
assert_str_eq!(app.data.radarr_data.search.text, "Tes");
assert_str_eq!(app.data.radarr_data.search.as_ref().unwrap().text, "Tes");
}
#[test]
fn test_filter_movies_box_backspace_key() {
let mut app = App::default();
app.data.radarr_data.filter = "Test".to_owned().into();
app.data.radarr_data.filter = Some("Test".into());
LibraryHandler::with(
&DEFAULT_KEYBINDINGS.backspace.key,
@@ -575,12 +738,13 @@ mod tests {
)
.handle();
assert_str_eq!(app.data.radarr_data.filter.text, "Tes");
assert_str_eq!(app.data.radarr_data.filter.as_ref().unwrap().text, "Tes");
}
#[test]
fn test_search_movies_box_char_key() {
let mut app = App::default();
app.data.radarr_data.search = Some(HorizontallyScrollableText::default());
LibraryHandler::with(
&Key::Char('h'),
@@ -590,12 +754,13 @@ mod tests {
)
.handle();
assert_str_eq!(app.data.radarr_data.search.text, "h");
assert_str_eq!(app.data.radarr_data.search.as_ref().unwrap().text, "h");
}
#[test]
fn test_filter_movies_box_char_key() {
let mut app = App::default();
app.data.radarr_data.filter = Some(HorizontallyScrollableText::default());
LibraryHandler::with(
&Key::Char('h'),
@@ -605,7 +770,7 @@ mod tests {
)
.handle();
assert_str_eq!(app.data.radarr_data.filter.text, "h");
assert_str_eq!(app.data.radarr_data.filter.as_ref().unwrap().text, "h");
}
}