feat(handlers): Sonarr key support for the Series table
This commit is contained in:
@@ -99,86 +99,92 @@ mod test_utils {
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! test_iterable_scroll {
|
||||
($func:ident, $handler:ident, $data_ref:ident, $block:expr, $context:expr) => {
|
||||
($func:ident, $handler:ident, $servarr_data:ident, $data_ref:ident, $block:expr, $context:expr) => {
|
||||
#[rstest]
|
||||
fn $func(#[values(DEFAULT_KEYBINDINGS.up.key, DEFAULT_KEYBINDINGS.down.key)] key: Key) {
|
||||
let mut app = App::default();
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.$servarr_data
|
||||
.$data_ref
|
||||
.set_items(vec!["Test 1".to_owned(), "Test 2".to_owned()]);
|
||||
|
||||
$handler::with(&key, &mut app, &$block, &$context).handle();
|
||||
|
||||
assert_str_eq!(app.data.radarr_data.$data_ref.current_selection(), "Test 2");
|
||||
assert_str_eq!(
|
||||
app.data.$servarr_data.$data_ref.current_selection(),
|
||||
"Test 2"
|
||||
);
|
||||
|
||||
$handler::with(&key, &mut app, &$block, &$context).handle();
|
||||
|
||||
assert_str_eq!(app.data.radarr_data.$data_ref.current_selection(), "Test 1");
|
||||
assert_str_eq!(
|
||||
app.data.$servarr_data.$data_ref.current_selection(),
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
($func:ident, $handler:ident, $data_ref:ident, $items:ident, $block:expr, $context:expr, $field:ident) => {
|
||||
($func:ident, $handler:ident, $servarr_data:ident, $data_ref:ident, $items:ident, $block:expr, $context:expr, $field:ident) => {
|
||||
#[rstest]
|
||||
fn $func(#[values(DEFAULT_KEYBINDINGS.up.key, DEFAULT_KEYBINDINGS.down.key)] key: Key) {
|
||||
let mut app = App::default();
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.$servarr_data
|
||||
.$data_ref
|
||||
.set_items(simple_stateful_iterable_vec!($items));
|
||||
|
||||
$handler::with(key, &mut app, $block, $context).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app.data.radarr_data.$data_ref.current_selection().$field,
|
||||
app.data.$servarr_data.$data_ref.current_selection().$field,
|
||||
"Test 2"
|
||||
);
|
||||
|
||||
$handler::with(key, &mut app, $block, $context).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app.data.radarr_data.$data_ref.current_selection().$field,
|
||||
app.data.$servarr_data.$data_ref.current_selection().$field,
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
($func:ident, $handler:ident, $data_ref:ident, $items:expr, $block:expr, $context:expr, $field:ident) => {
|
||||
($func:ident, $handler:ident, $servarr_data:ident, $data_ref:ident, $items:expr, $block:expr, $context:expr, $field:ident) => {
|
||||
#[rstest]
|
||||
fn $func(#[values(DEFAULT_KEYBINDINGS.up.key, DEFAULT_KEYBINDINGS.down.key)] key: Key) {
|
||||
let mut app = App::default();
|
||||
app.data.radarr_data.$data_ref.set_items($items);
|
||||
app.data.$servarr_data.$data_ref.set_items($items);
|
||||
|
||||
$handler::with(key, &mut app, $block, $context).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app.data.radarr_data.$data_ref.current_selection().$field,
|
||||
app.data.$servarr_data.$data_ref.current_selection().$field,
|
||||
"Test 2"
|
||||
);
|
||||
|
||||
$handler::with(key, &mut app, $block, $context).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app.data.radarr_data.$data_ref.current_selection().$field,
|
||||
app.data.$servarr_data.$data_ref.current_selection().$field,
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
($func:ident, $handler:ident, $data_ref:ident, $items:expr, $block:expr, $context:expr, $field:ident, $conversion_fn:ident) => {
|
||||
($func:ident, $handler:ident, $servarr_data:ident, $data_ref:ident, $items:expr, $block:expr, $context:expr, $field:ident, $conversion_fn:ident) => {
|
||||
#[rstest]
|
||||
fn $func(#[values(DEFAULT_KEYBINDINGS.up.key, DEFAULT_KEYBINDINGS.down.key)] key: Key) {
|
||||
let mut app = App::default();
|
||||
app.data.radarr_data.$data_ref.set_items($items);
|
||||
app.data.$servarr_data.$data_ref.set_items($items);
|
||||
|
||||
$handler::with(key, &mut app, $block, $context).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.$servarr_data
|
||||
.$data_ref
|
||||
.current_selection()
|
||||
.$field
|
||||
@@ -191,7 +197,7 @@ mod test_utils {
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.$servarr_data
|
||||
.$data_ref
|
||||
.current_selection()
|
||||
.$field
|
||||
@@ -204,11 +210,11 @@ mod test_utils {
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! test_iterable_home_and_end {
|
||||
($func:ident, $handler:ident, $data_ref:ident, $block:expr, $context:expr) => {
|
||||
($func:ident, $handler:ident, $servarr_data:ident, $data_ref:ident, $block:expr, $context:expr) => {
|
||||
#[test]
|
||||
fn $func() {
|
||||
let mut app = App::default();
|
||||
app.data.radarr_data.$data_ref.set_items(vec![
|
||||
app.data.$servarr_data.$data_ref.set_items(vec![
|
||||
"Test 1".to_owned(),
|
||||
"Test 2".to_owned(),
|
||||
"Test 3".to_owned(),
|
||||
@@ -216,74 +222,80 @@ mod test_utils {
|
||||
|
||||
$handler::with(DEFAULT_KEYBINDINGS.end.key, &mut app, $block, $context).handle();
|
||||
|
||||
assert_str_eq!(app.data.radarr_data.$data_ref.current_selection(), "Test 3");
|
||||
assert_str_eq!(
|
||||
app.data.$servarr_data.$data_ref.current_selection(),
|
||||
"Test 3"
|
||||
);
|
||||
|
||||
$handler::with(DEFAULT_KEYBINDINGS.home.key, &mut app, $block, $context).handle();
|
||||
|
||||
assert_str_eq!(app.data.radarr_data.$data_ref.current_selection(), "Test 1");
|
||||
assert_str_eq!(
|
||||
app.data.$servarr_data.$data_ref.current_selection(),
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
($func:ident, $handler:ident, $data_ref:ident, $items:ident, $block:expr, $context:expr, $field:ident) => {
|
||||
($func:ident, $handler:ident, $servarr_data:ident, $data_ref:ident, $items:ident, $block:expr, $context:expr, $field:ident) => {
|
||||
#[test]
|
||||
fn $func() {
|
||||
let mut app = App::default();
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.$servarr_data
|
||||
.$data_ref
|
||||
.set_items(extended_stateful_iterable_vec!($items));
|
||||
|
||||
$handler::with(DEFAULT_KEYBINDINGS.end.key, &mut app, $block, $context).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app.data.radarr_data.$data_ref.current_selection().$field,
|
||||
app.data.$servarr_data.$data_ref.current_selection().$field,
|
||||
"Test 3"
|
||||
);
|
||||
|
||||
$handler::with(DEFAULT_KEYBINDINGS.home.key, &mut app, $block, $context).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app.data.radarr_data.$data_ref.current_selection().$field,
|
||||
app.data.$servarr_data.$data_ref.current_selection().$field,
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
($func:ident, $handler:ident, $data_ref:ident, $items:expr, $block:expr, $context:expr, $field:ident) => {
|
||||
($func:ident, $handler:ident, $servarr_data:ident, $data_ref:ident, $items:expr, $block:expr, $context:expr, $field:ident) => {
|
||||
#[test]
|
||||
fn $func() {
|
||||
let mut app = App::default();
|
||||
app.data.radarr_data.$data_ref.set_items($items);
|
||||
app.data.$servarr_data.$data_ref.set_items($items);
|
||||
|
||||
$handler::with(DEFAULT_KEYBINDINGS.end.key, &mut app, $block, $context).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app.data.radarr_data.$data_ref.current_selection().$field,
|
||||
app.data.$servarr_data.$data_ref.current_selection().$field,
|
||||
"Test 3"
|
||||
);
|
||||
|
||||
$handler::with(DEFAULT_KEYBINDINGS.home.key, &mut app, $block, $context).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app.data.radarr_data.$data_ref.current_selection().$field,
|
||||
app.data.$servarr_data.$data_ref.current_selection().$field,
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
($func:ident, $handler:ident, $data_ref:ident, $items:expr, $block:expr, $context:expr, $field:ident, $conversion_fn:ident) => {
|
||||
($func:ident, $handler:ident, $servarr_data:ident, $data_ref:ident, $items:expr, $block:expr, $context:expr, $field:ident, $conversion_fn:ident) => {
|
||||
#[test]
|
||||
fn $func() {
|
||||
let mut app = App::default();
|
||||
app.data.radarr_data.$data_ref.set_items($items);
|
||||
app.data.$servarr_data.$data_ref.set_items($items);
|
||||
|
||||
$handler::with(DEFAULT_KEYBINDINGS.end.key, &mut app, $block, $context).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.$servarr_data
|
||||
.$data_ref
|
||||
.current_selection()
|
||||
.$field
|
||||
@@ -296,7 +308,7 @@ mod test_utils {
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.$servarr_data
|
||||
.$data_ref
|
||||
.current_selection()
|
||||
.$field
|
||||
@@ -319,4 +331,34 @@ mod test_utils {
|
||||
assert_eq!(app.get_current_route(), $base.into());
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! assert_delete_prompt {
|
||||
($handler:ident, $block:expr, $expected_block:expr) => {
|
||||
let mut app = App::default();
|
||||
|
||||
$handler::with(DELETE_KEY, &mut app, $block, None).handle();
|
||||
|
||||
assert_eq!(app.get_current_route(), $expected_block.into());
|
||||
};
|
||||
|
||||
($handler:ident, $app:expr, $block:expr, $expected_block:expr) => {
|
||||
$handler::with(DELETE_KEY, &mut $app, $block, None).handle();
|
||||
|
||||
assert_eq!($app.get_current_route(), $expected_block.into());
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! assert_refresh_key {
|
||||
($handler:ident, $block:expr) => {
|
||||
let mut app = App::default();
|
||||
app.push_navigation_stack($block.into());
|
||||
|
||||
$handler::with(DEFAULT_KEYBINDINGS.refresh.key, &mut app, $block, None).handle();
|
||||
|
||||
assert_eq!(app.get_current_route(), $block.into());
|
||||
assert!(app.should_refresh);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,19 @@ mod tests {
|
||||
assert!(app.error.text.is_empty());
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
#[case(ActiveRadarrBlock::Movies.into(), ActiveRadarrBlock::SearchMovie.into())]
|
||||
#[case(ActiveSonarrBlock::Series.into(), ActiveSonarrBlock::SearchSeries.into())]
|
||||
fn test_handle_events(#[case] base_block: Route, #[case] top_block: Route) {
|
||||
let mut app = App::default();
|
||||
app.push_navigation_stack(base_block);
|
||||
app.push_navigation_stack(top_block);
|
||||
|
||||
handle_events(DEFAULT_KEYBINDINGS.esc.key, &mut app);
|
||||
|
||||
assert_eq!(app.get_current_route(), base_block);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
#[case(0, ActiveSonarrBlock::Series, ActiveSonarrBlock::Series)]
|
||||
#[case(1, ActiveRadarrBlock::Movies, ActiveRadarrBlock::Movies)]
|
||||
@@ -54,8 +67,9 @@ mod tests {
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_handle_prompt_toggle_left_right(#[values(Key::Left, Key::Right)] key: Key) {
|
||||
fn test_handle_prompt_toggle_left_right_radarr(#[values(Key::Left, Key::Right)] key: Key) {
|
||||
let mut app = App::default();
|
||||
app.push_navigation_stack(ActiveRadarrBlock::Movies.into());
|
||||
|
||||
assert!(!app.data.radarr_data.prompt_confirm);
|
||||
|
||||
@@ -67,4 +81,20 @@ mod tests {
|
||||
|
||||
assert!(!app.data.radarr_data.prompt_confirm);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_handle_prompt_toggle_left_right_sonarr(#[values(Key::Left, Key::Right)] key: Key) {
|
||||
let mut app = App::default();
|
||||
app.push_navigation_stack(ActiveSonarrBlock::Series.into());
|
||||
|
||||
assert!(!app.data.sonarr_data.prompt_confirm);
|
||||
|
||||
handle_prompt_toggle(&mut app, key);
|
||||
|
||||
assert!(app.data.sonarr_data.prompt_confirm);
|
||||
|
||||
handle_prompt_toggle(&mut app, key);
|
||||
|
||||
assert!(!app.data.sonarr_data.prompt_confirm);
|
||||
}
|
||||
}
|
||||
|
||||
+20
-4
@@ -1,4 +1,5 @@
|
||||
use radarr_handlers::RadarrHandler;
|
||||
use sonarr_handlers::SonarrHandler;
|
||||
|
||||
use crate::app::key_binding::DEFAULT_KEYBINDINGS;
|
||||
use crate::app::App;
|
||||
@@ -6,6 +7,7 @@ use crate::event::Key;
|
||||
use crate::models::{HorizontallyScrollableText, Route};
|
||||
|
||||
mod radarr_handlers;
|
||||
mod sonarr_handlers;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "handlers_tests.rs"]
|
||||
@@ -89,8 +91,16 @@ pub fn handle_events(key: Key, app: &mut App<'_>) {
|
||||
app.reset();
|
||||
app.server_tabs.previous();
|
||||
app.pop_and_push_navigation_stack(app.server_tabs.get_active_route());
|
||||
} else if let Route::Radarr(active_radarr_block, context) = app.get_current_route() {
|
||||
RadarrHandler::with(key, app, active_radarr_block, context).handle()
|
||||
} else {
|
||||
match app.get_current_route() {
|
||||
Route::Radarr(active_radarr_block, context) => {
|
||||
RadarrHandler::with(key, app, active_radarr_block, context).handle()
|
||||
}
|
||||
Route::Sonarr(active_sonarr_block, context) => {
|
||||
SonarrHandler::with(key, app, active_sonarr_block, context).handle()
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,8 +113,14 @@ fn handle_clear_errors(app: &mut App<'_>) {
|
||||
fn handle_prompt_toggle(app: &mut App<'_>, key: Key) {
|
||||
match key {
|
||||
_ if key == DEFAULT_KEYBINDINGS.left.key || key == DEFAULT_KEYBINDINGS.right.key => {
|
||||
if let Route::Radarr(_, _) = app.get_current_route() {
|
||||
app.data.radarr_data.prompt_confirm = !app.data.radarr_data.prompt_confirm;
|
||||
match app.get_current_route() {
|
||||
Route::Radarr(_, _) => {
|
||||
app.data.radarr_data.prompt_confirm = !app.data.radarr_data.prompt_confirm
|
||||
}
|
||||
Route::Sonarr(_, _) => {
|
||||
app.data.sonarr_data.prompt_confirm = !app.data.sonarr_data.prompt_confirm
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
|
||||
@@ -28,6 +28,7 @@ mod tests {
|
||||
test_iterable_scroll!(
|
||||
test_blocklist_scroll,
|
||||
BlocklistHandler,
|
||||
radarr_data,
|
||||
blocklist,
|
||||
simple_stateful_iterable_vec!(BlocklistItem, String, source_title),
|
||||
ActiveRadarrBlock::Blocklist,
|
||||
@@ -136,6 +137,7 @@ mod tests {
|
||||
test_iterable_home_and_end!(
|
||||
test_blocklist_home_and_end,
|
||||
BlocklistHandler,
|
||||
radarr_data,
|
||||
blocklist,
|
||||
extended_stateful_iterable_vec!(BlocklistItem, String, source_title),
|
||||
ActiveRadarrBlock::Blocklist,
|
||||
|
||||
@@ -24,6 +24,7 @@ mod tests {
|
||||
test_iterable_scroll!(
|
||||
test_collection_details_scroll,
|
||||
CollectionDetailsHandler,
|
||||
radarr_data,
|
||||
collection_movies,
|
||||
simple_stateful_iterable_vec!(CollectionMovie, HorizontallyScrollableText),
|
||||
ActiveRadarrBlock::CollectionDetails,
|
||||
@@ -88,6 +89,7 @@ mod tests {
|
||||
test_iterable_home_and_end!(
|
||||
test_collection_details_home_end,
|
||||
CollectionDetailsHandler,
|
||||
radarr_data,
|
||||
collection_movies,
|
||||
extended_stateful_iterable_vec!(CollectionMovie, HorizontallyScrollableText),
|
||||
ActiveRadarrBlock::CollectionDetails,
|
||||
|
||||
@@ -34,6 +34,7 @@ mod tests {
|
||||
test_iterable_scroll!(
|
||||
test_collections_scroll,
|
||||
CollectionsHandler,
|
||||
radarr_data,
|
||||
collections,
|
||||
simple_stateful_iterable_vec!(Collection, HorizontallyScrollableText),
|
||||
ActiveRadarrBlock::Collections,
|
||||
@@ -153,6 +154,7 @@ mod tests {
|
||||
test_iterable_home_and_end!(
|
||||
test_collections_home_end,
|
||||
CollectionsHandler,
|
||||
radarr_data,
|
||||
collections,
|
||||
extended_stateful_iterable_vec!(Collection, HorizontallyScrollableText),
|
||||
ActiveRadarrBlock::Collections,
|
||||
|
||||
@@ -22,6 +22,7 @@ mod tests {
|
||||
test_iterable_scroll!(
|
||||
test_downloads_scroll,
|
||||
DownloadsHandler,
|
||||
radarr_data,
|
||||
downloads,
|
||||
DownloadRecord,
|
||||
ActiveRadarrBlock::Downloads,
|
||||
@@ -69,6 +70,7 @@ mod tests {
|
||||
test_iterable_home_and_end!(
|
||||
test_downloads_home_end,
|
||||
DownloadsHandler,
|
||||
radarr_data,
|
||||
downloads,
|
||||
DownloadRecord,
|
||||
ActiveRadarrBlock::Downloads,
|
||||
|
||||
@@ -25,6 +25,7 @@ mod tests {
|
||||
test_iterable_scroll!(
|
||||
test_indexers_scroll,
|
||||
IndexersHandler,
|
||||
radarr_data,
|
||||
indexers,
|
||||
simple_stateful_iterable_vec!(Indexer, String, protocol),
|
||||
ActiveRadarrBlock::Indexers,
|
||||
@@ -71,6 +72,7 @@ mod tests {
|
||||
test_iterable_home_and_end!(
|
||||
test_indexers_home_end,
|
||||
IndexersHandler,
|
||||
radarr_data,
|
||||
indexers,
|
||||
extended_stateful_iterable_vec!(Indexer, String, protocol),
|
||||
ActiveRadarrBlock::Indexers,
|
||||
|
||||
@@ -30,6 +30,7 @@ mod tests {
|
||||
test_iterable_scroll!(
|
||||
test_movies_scroll,
|
||||
LibraryHandler,
|
||||
radarr_data,
|
||||
movies,
|
||||
simple_stateful_iterable_vec!(Movie, HorizontallyScrollableText),
|
||||
ActiveRadarrBlock::Movies,
|
||||
@@ -134,6 +135,7 @@ mod tests {
|
||||
test_iterable_home_and_end!(
|
||||
test_movies_home_end,
|
||||
LibraryHandler,
|
||||
radarr_data,
|
||||
movies,
|
||||
extended_stateful_iterable_vec!(Movie, HorizontallyScrollableText),
|
||||
ActiveRadarrBlock::Movies,
|
||||
|
||||
@@ -228,48 +228,4 @@ mod utils {
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! assert_delete_prompt {
|
||||
($block:expr, $expected_block:expr) => {
|
||||
let mut app = App::default();
|
||||
|
||||
RadarrHandler::with(DELETE_KEY, &mut app, $block, None).handle();
|
||||
|
||||
assert_eq!(app.get_current_route(), $expected_block.into());
|
||||
};
|
||||
|
||||
($handler:ident, $block:expr, $expected_block:expr) => {
|
||||
let mut app = App::default();
|
||||
|
||||
$handler::with(DELETE_KEY, &mut app, $block, None).handle();
|
||||
|
||||
assert_eq!(app.get_current_route(), $expected_block.into());
|
||||
};
|
||||
|
||||
($app:expr, $block:expr, $expected_block:expr) => {
|
||||
RadarrHandler::with(DELETE_KEY, &mut $app, $block, None).handle();
|
||||
|
||||
assert_eq!($app.get_current_route(), $expected_block.into());
|
||||
};
|
||||
|
||||
($handler:ident, $app:expr, $block:expr, $expected_block:expr) => {
|
||||
$handler::with(DELETE_KEY, &mut $app, $block, None).handle();
|
||||
|
||||
assert_eq!($app.get_current_route(), $expected_block.into());
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! assert_refresh_key {
|
||||
($handler:ident, $block:expr) => {
|
||||
let mut app = App::default();
|
||||
app.push_navigation_stack($block.into());
|
||||
|
||||
$handler::with(DEFAULT_KEYBINDINGS.refresh.key, &mut app, $block, None).handle();
|
||||
|
||||
assert_eq!(app.get_current_route(), $block.into());
|
||||
assert!(app.should_refresh);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ mod tests {
|
||||
test_iterable_scroll!(
|
||||
test_root_folders_scroll,
|
||||
RootFoldersHandler,
|
||||
radarr_data,
|
||||
root_folders,
|
||||
simple_stateful_iterable_vec!(RootFolder, String, path),
|
||||
ActiveRadarrBlock::RootFolders,
|
||||
@@ -71,6 +72,7 @@ mod tests {
|
||||
test_iterable_home_and_end!(
|
||||
test_root_folders_home_end,
|
||||
RootFoldersHandler,
|
||||
radarr_data,
|
||||
root_folders,
|
||||
extended_stateful_iterable_vec!(RootFolder, String, path),
|
||||
ActiveRadarrBlock::RootFolders,
|
||||
|
||||
@@ -26,6 +26,7 @@ mod tests {
|
||||
test_iterable_scroll!(
|
||||
test_log_details_scroll,
|
||||
SystemDetailsHandler,
|
||||
radarr_data,
|
||||
log_details,
|
||||
simple_stateful_iterable_vec!(HorizontallyScrollableText, String, text),
|
||||
ActiveRadarrBlock::SystemLogs,
|
||||
@@ -241,6 +242,7 @@ mod tests {
|
||||
test_iterable_home_and_end!(
|
||||
test_log_details_home_end,
|
||||
SystemDetailsHandler,
|
||||
radarr_data,
|
||||
log_details,
|
||||
extended_stateful_iterable_vec!(HorizontallyScrollableText, String, text),
|
||||
ActiveRadarrBlock::SystemLogs,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,460 @@
|
||||
use crate::{
|
||||
app::App,
|
||||
event::Key,
|
||||
handle_text_box_keys, handle_text_box_left_right_keys,
|
||||
handlers::{handle_clear_errors, handle_prompt_toggle, KeyEventHandler},
|
||||
models::{
|
||||
servarr_data::sonarr::sonarr_data::{
|
||||
ActiveSonarrBlock, DELETE_SERIES_SELECTION_BLOCKS, EDIT_SERIES_SELECTION_BLOCKS,
|
||||
SERIES_BLOCKS,
|
||||
},
|
||||
sonarr_models::Series,
|
||||
stateful_table::SortOption,
|
||||
BlockSelectionState, HorizontallyScrollableText, Scrollable,
|
||||
},
|
||||
network::sonarr_network::SonarrEvent,
|
||||
};
|
||||
|
||||
use super::handle_change_tab_left_right_keys;
|
||||
use crate::app::key_binding::DEFAULT_KEYBINDINGS;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "library_handler_tests.rs"]
|
||||
mod library_handler_tests;
|
||||
|
||||
pub(super) struct LibraryHandler<'a, 'b> {
|
||||
key: Key,
|
||||
app: &'a mut App<'b>,
|
||||
active_sonarr_block: ActiveSonarrBlock,
|
||||
_context: Option<ActiveSonarrBlock>,
|
||||
}
|
||||
|
||||
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for LibraryHandler<'a, 'b> {
|
||||
fn handle(&mut self) {
|
||||
match self.active_sonarr_block {
|
||||
_ => self.handle_key_event(),
|
||||
}
|
||||
}
|
||||
|
||||
fn accepts(active_block: ActiveSonarrBlock) -> bool {
|
||||
SERIES_BLOCKS.contains(&active_block)
|
||||
}
|
||||
|
||||
fn with(
|
||||
key: Key,
|
||||
app: &'a mut App<'b>,
|
||||
active_block: ActiveSonarrBlock,
|
||||
_context: Option<ActiveSonarrBlock>,
|
||||
) -> LibraryHandler<'a, 'b> {
|
||||
LibraryHandler {
|
||||
key,
|
||||
app,
|
||||
active_sonarr_block: active_block,
|
||||
_context,
|
||||
}
|
||||
}
|
||||
|
||||
fn get_key(&self) -> Key {
|
||||
self.key
|
||||
}
|
||||
|
||||
fn is_ready(&self) -> bool {
|
||||
!self.app.is_loading && !self.app.data.sonarr_data.series.is_empty()
|
||||
}
|
||||
|
||||
fn handle_scroll_up(&mut self) {
|
||||
match self.active_sonarr_block {
|
||||
ActiveSonarrBlock::Series => self.app.data.sonarr_data.series.scroll_up(),
|
||||
ActiveSonarrBlock::SeriesSortPrompt => self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.series
|
||||
.sort
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.scroll_up(),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_scroll_down(&mut self) {
|
||||
match self.active_sonarr_block {
|
||||
ActiveSonarrBlock::Series => self.app.data.sonarr_data.series.scroll_down(),
|
||||
ActiveSonarrBlock::SeriesSortPrompt => self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.series
|
||||
.sort
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.scroll_down(),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_home(&mut self) {
|
||||
match self.active_sonarr_block {
|
||||
ActiveSonarrBlock::Series => self.app.data.sonarr_data.series.scroll_to_top(),
|
||||
ActiveSonarrBlock::SearchSeries => {
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.series
|
||||
.search
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.scroll_home();
|
||||
}
|
||||
ActiveSonarrBlock::FilterSeries => {
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.series
|
||||
.filter
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.scroll_home();
|
||||
}
|
||||
ActiveSonarrBlock::SeriesSortPrompt => self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.series
|
||||
.sort
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.scroll_to_top(),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_end(&mut self) {
|
||||
match self.active_sonarr_block {
|
||||
ActiveSonarrBlock::Series => self.app.data.sonarr_data.series.scroll_to_bottom(),
|
||||
ActiveSonarrBlock::SearchSeries => self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.series
|
||||
.search
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.reset_offset(),
|
||||
ActiveSonarrBlock::FilterSeries => self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.series
|
||||
.filter
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.reset_offset(),
|
||||
ActiveSonarrBlock::SeriesSortPrompt => self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.series
|
||||
.sort
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.scroll_to_bottom(),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_delete(&mut self) {
|
||||
if self.active_sonarr_block == ActiveSonarrBlock::Series {
|
||||
self
|
||||
.app
|
||||
.push_navigation_stack(ActiveSonarrBlock::DeleteSeriesPrompt.into());
|
||||
self.app.data.sonarr_data.selected_block =
|
||||
BlockSelectionState::new(DELETE_SERIES_SELECTION_BLOCKS);
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_left_right_action(&mut self) {
|
||||
match self.active_sonarr_block {
|
||||
ActiveSonarrBlock::Series => handle_change_tab_left_right_keys(self.app, self.key),
|
||||
ActiveSonarrBlock::UpdateAllSeriesPrompt => handle_prompt_toggle(self.app, self.key),
|
||||
ActiveSonarrBlock::SearchSeries => {
|
||||
handle_text_box_left_right_keys!(
|
||||
self,
|
||||
self.key,
|
||||
self.app.data.sonarr_data.series.search.as_mut().unwrap()
|
||||
)
|
||||
}
|
||||
ActiveSonarrBlock::FilterSeries => {
|
||||
handle_text_box_left_right_keys!(
|
||||
self,
|
||||
self.key,
|
||||
self.app.data.sonarr_data.series.filter.as_mut().unwrap()
|
||||
)
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_submit(&mut self) {
|
||||
match self.active_sonarr_block {
|
||||
ActiveSonarrBlock::Series => self
|
||||
.app
|
||||
.push_navigation_stack(ActiveSonarrBlock::SeriesDetails.into()),
|
||||
ActiveSonarrBlock::SearchSeries => {
|
||||
self.app.pop_navigation_stack();
|
||||
self.app.should_ignore_quit_key = false;
|
||||
|
||||
if self.app.data.sonarr_data.series.search.is_some() {
|
||||
let has_match = self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.series
|
||||
.apply_search(|series| &series.title.text);
|
||||
|
||||
if !has_match {
|
||||
self
|
||||
.app
|
||||
.push_navigation_stack(ActiveSonarrBlock::SearchSeriesError.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
ActiveSonarrBlock::FilterSeries => {
|
||||
self.app.pop_navigation_stack();
|
||||
self.app.should_ignore_quit_key = false;
|
||||
|
||||
if self.app.data.sonarr_data.series.filter.is_some() {
|
||||
let has_matches = self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.series
|
||||
.apply_filter(|series| &series.title.text);
|
||||
|
||||
if !has_matches {
|
||||
self
|
||||
.app
|
||||
.push_navigation_stack(ActiveSonarrBlock::FilterSeriesError.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
ActiveSonarrBlock::UpdateAllSeriesPrompt => {
|
||||
if self.app.data.sonarr_data.prompt_confirm {
|
||||
self.app.data.sonarr_data.prompt_confirm_action = Some(SonarrEvent::UpdateAllSeries);
|
||||
}
|
||||
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
ActiveSonarrBlock::SeriesSortPrompt => {
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.series
|
||||
.items
|
||||
.sort_by(|a, b| a.id.cmp(&b.id));
|
||||
self.app.data.sonarr_data.series.apply_sorting();
|
||||
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_esc(&mut self) {
|
||||
match self.active_sonarr_block {
|
||||
ActiveSonarrBlock::FilterSeries | ActiveSonarrBlock::FilterSeriesError => {
|
||||
self.app.pop_navigation_stack();
|
||||
self.app.data.sonarr_data.series.reset_filter();
|
||||
self.app.should_ignore_quit_key = false;
|
||||
}
|
||||
ActiveSonarrBlock::SearchSeries | ActiveSonarrBlock::SearchSeriesError => {
|
||||
self.app.pop_navigation_stack();
|
||||
self.app.data.sonarr_data.series.reset_search();
|
||||
self.app.should_ignore_quit_key = false;
|
||||
}
|
||||
ActiveSonarrBlock::UpdateAllSeriesPrompt => {
|
||||
self.app.pop_navigation_stack();
|
||||
self.app.data.sonarr_data.prompt_confirm = false;
|
||||
}
|
||||
ActiveSonarrBlock::SeriesSortPrompt => {
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
_ => {
|
||||
self.app.data.sonarr_data.series.reset_search();
|
||||
self.app.data.sonarr_data.series.reset_filter();
|
||||
handle_clear_errors(self.app);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_char_key_event(&mut self) {
|
||||
let key = self.key;
|
||||
match self.active_sonarr_block {
|
||||
ActiveSonarrBlock::Series => match self.key {
|
||||
_ if key == DEFAULT_KEYBINDINGS.search.key => {
|
||||
self
|
||||
.app
|
||||
.push_navigation_stack(ActiveSonarrBlock::SearchSeries.into());
|
||||
self.app.data.sonarr_data.series.search = Some(HorizontallyScrollableText::default());
|
||||
self.app.should_ignore_quit_key = true;
|
||||
}
|
||||
_ if key == DEFAULT_KEYBINDINGS.filter.key => {
|
||||
self
|
||||
.app
|
||||
.push_navigation_stack(ActiveSonarrBlock::FilterSeries.into());
|
||||
self.app.data.sonarr_data.series.reset_filter();
|
||||
self.app.data.sonarr_data.series.filter = Some(HorizontallyScrollableText::default());
|
||||
self.app.should_ignore_quit_key = true;
|
||||
}
|
||||
_ if key == DEFAULT_KEYBINDINGS.edit.key => {
|
||||
self.app.push_navigation_stack(
|
||||
(
|
||||
ActiveSonarrBlock::EditSeriesPrompt,
|
||||
Some(ActiveSonarrBlock::Series),
|
||||
)
|
||||
.into(),
|
||||
);
|
||||
self.app.data.sonarr_data.edit_series_modal = Some((&self.app.data.sonarr_data).into());
|
||||
self.app.data.sonarr_data.selected_block =
|
||||
BlockSelectionState::new(EDIT_SERIES_SELECTION_BLOCKS);
|
||||
}
|
||||
_ if key == DEFAULT_KEYBINDINGS.add.key => {
|
||||
self
|
||||
.app
|
||||
.push_navigation_stack(ActiveSonarrBlock::AddSeriesSearchInput.into());
|
||||
self.app.data.sonarr_data.add_series_search = Some(HorizontallyScrollableText::default());
|
||||
self.app.should_ignore_quit_key = true;
|
||||
}
|
||||
_ if key == DEFAULT_KEYBINDINGS.update.key => {
|
||||
self
|
||||
.app
|
||||
.push_navigation_stack(ActiveSonarrBlock::UpdateAllSeriesPrompt.into());
|
||||
}
|
||||
_ if key == DEFAULT_KEYBINDINGS.refresh.key => {
|
||||
self.app.should_refresh = true;
|
||||
}
|
||||
_ if key == DEFAULT_KEYBINDINGS.sort.key => {
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.series
|
||||
.sorting(series_sorting_options());
|
||||
self
|
||||
.app
|
||||
.push_navigation_stack(ActiveSonarrBlock::SeriesSortPrompt.into());
|
||||
}
|
||||
_ => (),
|
||||
},
|
||||
ActiveSonarrBlock::SearchSeries => {
|
||||
handle_text_box_keys!(
|
||||
self,
|
||||
key,
|
||||
self.app.data.sonarr_data.series.search.as_mut().unwrap()
|
||||
)
|
||||
}
|
||||
ActiveSonarrBlock::FilterSeries => {
|
||||
handle_text_box_keys!(
|
||||
self,
|
||||
key,
|
||||
self.app.data.sonarr_data.series.filter.as_mut().unwrap()
|
||||
)
|
||||
}
|
||||
ActiveSonarrBlock::UpdateAllSeriesPrompt => {
|
||||
if key == DEFAULT_KEYBINDINGS.confirm.key {
|
||||
self.app.data.sonarr_data.prompt_confirm = true;
|
||||
self.app.data.sonarr_data.prompt_confirm_action = Some(SonarrEvent::UpdateAllSeries);
|
||||
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn series_sorting_options() -> Vec<SortOption<Series>> {
|
||||
vec![
|
||||
SortOption {
|
||||
name: "Title",
|
||||
cmp_fn: Some(|a, b| {
|
||||
a.title
|
||||
.text
|
||||
.to_lowercase()
|
||||
.cmp(&b.title.text.to_lowercase())
|
||||
}),
|
||||
},
|
||||
SortOption {
|
||||
name: "Year",
|
||||
cmp_fn: Some(|a, b| a.year.cmp(&b.year)),
|
||||
},
|
||||
SortOption {
|
||||
name: "Network",
|
||||
cmp_fn: Some(|a, b| {
|
||||
a.network
|
||||
.as_ref()
|
||||
.unwrap_or(&String::new())
|
||||
.to_lowercase()
|
||||
.cmp(&b.network.as_ref().unwrap_or(&String::new()).to_lowercase())
|
||||
}),
|
||||
},
|
||||
SortOption {
|
||||
name: "Runtime",
|
||||
cmp_fn: Some(|a, b| a.runtime.cmp(&b.runtime)),
|
||||
},
|
||||
SortOption {
|
||||
name: "Rating",
|
||||
cmp_fn: Some(|a, b| {
|
||||
a.certification
|
||||
.as_ref()
|
||||
.unwrap_or(&String::new())
|
||||
.to_lowercase()
|
||||
.cmp(
|
||||
&b.certification
|
||||
.as_ref()
|
||||
.unwrap_or(&String::new())
|
||||
.to_lowercase(),
|
||||
)
|
||||
}),
|
||||
},
|
||||
SortOption {
|
||||
name: "Type",
|
||||
cmp_fn: Some(|a, b| a.series_type.to_string().cmp(&b.series_type.to_string())),
|
||||
},
|
||||
SortOption {
|
||||
name: "Quality",
|
||||
cmp_fn: Some(|a, b| a.quality_profile_id.cmp(&b.quality_profile_id)),
|
||||
},
|
||||
SortOption {
|
||||
name: "Language",
|
||||
cmp_fn: Some(|a, b| a.language_profile_id.cmp(&b.language_profile_id)),
|
||||
},
|
||||
SortOption {
|
||||
name: "Monitored",
|
||||
cmp_fn: Some(|a, b| a.monitored.cmp(&b.monitored)),
|
||||
},
|
||||
SortOption {
|
||||
name: "Tags",
|
||||
cmp_fn: Some(|a, b| {
|
||||
let a_str = a
|
||||
.tags
|
||||
.iter()
|
||||
.map(|tag| tag.as_i64().unwrap().to_string())
|
||||
.collect::<Vec<String>>()
|
||||
.join(",");
|
||||
let b_str = b
|
||||
.tags
|
||||
.iter()
|
||||
.map(|tag| tag.as_i64().unwrap().to_string())
|
||||
.collect::<Vec<String>>()
|
||||
.join(",");
|
||||
|
||||
a_str.cmp(&b_str)
|
||||
}),
|
||||
},
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
use library::LibraryHandler;
|
||||
|
||||
use crate::{
|
||||
app::{key_binding::DEFAULT_KEYBINDINGS, App},
|
||||
event::Key,
|
||||
models::servarr_data::sonarr::sonarr_data::ActiveSonarrBlock,
|
||||
};
|
||||
|
||||
use super::KeyEventHandler;
|
||||
|
||||
mod library;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "sonarr_handler_tests.rs"]
|
||||
mod sonarr_handler_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "sonarr_handler_test_utils.rs"]
|
||||
mod sonarr_handler_test_utils;
|
||||
|
||||
pub(super) struct SonarrHandler<'a, 'b> {
|
||||
key: Key,
|
||||
app: &'a mut App<'b>,
|
||||
active_sonarr_block: ActiveSonarrBlock,
|
||||
context: Option<ActiveSonarrBlock>,
|
||||
}
|
||||
|
||||
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for SonarrHandler<'a, 'b> {
|
||||
fn handle(&mut self) {
|
||||
match self.active_sonarr_block {
|
||||
_ if LibraryHandler::accepts(self.active_sonarr_block) => {
|
||||
LibraryHandler::with(self.key, self.app, self.active_sonarr_block, self.context).handle();
|
||||
}
|
||||
_ => self.handle_key_event(),
|
||||
}
|
||||
}
|
||||
|
||||
fn accepts(_active_block: ActiveSonarrBlock) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn with(
|
||||
key: Key,
|
||||
app: &'a mut App<'b>,
|
||||
active_block: ActiveSonarrBlock,
|
||||
context: Option<ActiveSonarrBlock>,
|
||||
) -> SonarrHandler<'a, 'b> {
|
||||
SonarrHandler {
|
||||
key,
|
||||
app,
|
||||
active_sonarr_block: active_block,
|
||||
context,
|
||||
}
|
||||
}
|
||||
|
||||
fn get_key(&self) -> Key {
|
||||
self.key
|
||||
}
|
||||
|
||||
fn is_ready(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn handle_scroll_up(&mut self) {}
|
||||
|
||||
fn handle_scroll_down(&mut self) {}
|
||||
|
||||
fn handle_home(&mut self) {}
|
||||
|
||||
fn handle_end(&mut self) {}
|
||||
|
||||
fn handle_delete(&mut self) {}
|
||||
|
||||
fn handle_left_right_action(&mut self) {}
|
||||
|
||||
fn handle_submit(&mut self) {}
|
||||
|
||||
fn handle_esc(&mut self) {}
|
||||
|
||||
fn handle_char_key_event(&mut self) {}
|
||||
}
|
||||
|
||||
pub fn handle_change_tab_left_right_keys(app: &mut App<'_>, key: Key) {
|
||||
let key_ref = key;
|
||||
match key_ref {
|
||||
_ if key == DEFAULT_KEYBINDINGS.left.key => {
|
||||
app.data.sonarr_data.main_tabs.previous();
|
||||
app.pop_and_push_navigation_stack(app.data.sonarr_data.main_tabs.get_active_route());
|
||||
}
|
||||
_ if key == DEFAULT_KEYBINDINGS.right.key => {
|
||||
app.data.sonarr_data.main_tabs.next();
|
||||
app.pop_and_push_navigation_stack(app.data.sonarr_data.main_tabs.get_active_route());
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
#[cfg(test)]
|
||||
#[macro_use]
|
||||
mod utils {
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! test_edit_series_key {
|
||||
($handler:ident, $block:expr, $context:expr) => {
|
||||
let mut app = App::default();
|
||||
let mut sonarr_data = SonarrData {
|
||||
quality_profile_map: BiMap::from_iter([
|
||||
(2222, "HD - 1080p".to_owned()),
|
||||
(1111, "Any".to_owned()),
|
||||
]),
|
||||
language_profiles_map: BiMap::from_iter([
|
||||
(2222, "English".to_owned()),
|
||||
(1111, "Any".to_owned()),
|
||||
]),
|
||||
tags_map: BiMap::from_iter([(1, "test".to_owned())]),
|
||||
..create_test_sonarr_data()
|
||||
};
|
||||
sonarr_data.series.set_items(vec![Series {
|
||||
path: "/nfs/series/Test".to_owned().into(),
|
||||
monitored: true,
|
||||
season_folder: true,
|
||||
quality_profile_id: 2222,
|
||||
language_profile_id: 2222,
|
||||
series_type: SeriesType::Anime,
|
||||
tags: vec![Number::from(1)],
|
||||
..Series::default()
|
||||
}]);
|
||||
app.data.sonarr_data = sonarr_data;
|
||||
|
||||
$handler::with(DEFAULT_KEYBINDINGS.edit.key, &mut app, $block, None).handle();
|
||||
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
(ActiveSonarrBlock::EditSeriesPrompt, Some($context)).into()
|
||||
);
|
||||
assert_eq!(
|
||||
app.data.sonarr_data.selected_block.get_active_block(),
|
||||
ActiveSonarrBlock::EditSeriesToggleMonitored
|
||||
);
|
||||
assert_eq!(
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.edit_series_modal
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.series_type_list
|
||||
.items,
|
||||
Vec::from_iter(SeriesType::iter())
|
||||
);
|
||||
assert_eq!(
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.edit_series_modal
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.series_type_list
|
||||
.current_selection(),
|
||||
&SeriesType::Anime
|
||||
);
|
||||
assert_eq!(
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.edit_series_modal
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.quality_profile_list
|
||||
.items,
|
||||
vec!["Any".to_owned(), "HD - 1080p".to_owned()]
|
||||
);
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.edit_series_modal
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.quality_profile_list
|
||||
.current_selection(),
|
||||
"HD - 1080p"
|
||||
);
|
||||
assert_eq!(
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.edit_series_modal
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.language_profile_list
|
||||
.items,
|
||||
vec!["Any".to_owned(), "English".to_owned()]
|
||||
);
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.edit_series_modal
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.language_profile_list
|
||||
.current_selection(),
|
||||
"English"
|
||||
);
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.edit_series_modal
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.path
|
||||
.text,
|
||||
"/nfs/series/Test"
|
||||
);
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.edit_series_modal
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.tags
|
||||
.text,
|
||||
"test"
|
||||
);
|
||||
assert_eq!(
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.edit_series_modal
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.monitored,
|
||||
Some(true)
|
||||
);
|
||||
assert_eq!(
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.edit_series_modal
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.use_season_folders,
|
||||
Some(true)
|
||||
);
|
||||
assert_eq!(
|
||||
app.data.sonarr_data.selected_block.blocks,
|
||||
$crate::models::servarr_data::sonarr::sonarr_data::EDIT_SERIES_SELECTION_BLOCKS
|
||||
);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::app::key_binding::DEFAULT_KEYBINDINGS;
|
||||
use crate::app::App;
|
||||
use crate::handlers::sonarr_handlers::handle_change_tab_left_right_keys;
|
||||
use crate::handlers::sonarr_handlers::SonarrHandler;
|
||||
use crate::handlers::KeyEventHandler;
|
||||
use crate::models::servarr_data::sonarr::sonarr_data::ActiveSonarrBlock;
|
||||
use crate::test_handler_delegation;
|
||||
use pretty_assertions::assert_eq;
|
||||
use rstest::rstest;
|
||||
|
||||
#[rstest]
|
||||
#[case(0, ActiveSonarrBlock::System, ActiveSonarrBlock::Downloads)]
|
||||
#[case(1, ActiveSonarrBlock::Series, ActiveSonarrBlock::Blocklist)]
|
||||
#[case(2, ActiveSonarrBlock::Downloads, ActiveSonarrBlock::History)]
|
||||
#[case(3, ActiveSonarrBlock::Blocklist, ActiveSonarrBlock::RootFolders)]
|
||||
#[case(4, ActiveSonarrBlock::History, ActiveSonarrBlock::Indexers)]
|
||||
#[case(5, ActiveSonarrBlock::RootFolders, ActiveSonarrBlock::System)]
|
||||
#[case(6, ActiveSonarrBlock::Indexers, ActiveSonarrBlock::Series)]
|
||||
fn test_sonarr_handler_change_tab_left_right_keys(
|
||||
#[case] index: usize,
|
||||
#[case] left_block: ActiveSonarrBlock,
|
||||
#[case] right_block: ActiveSonarrBlock,
|
||||
) {
|
||||
let mut app = App::default();
|
||||
app.data.sonarr_data.main_tabs.set_index(index);
|
||||
|
||||
handle_change_tab_left_right_keys(&mut app, DEFAULT_KEYBINDINGS.left.key);
|
||||
|
||||
assert_eq!(
|
||||
app.data.sonarr_data.main_tabs.get_active_route(),
|
||||
left_block.into()
|
||||
);
|
||||
assert_eq!(app.get_current_route(), left_block.into());
|
||||
|
||||
app.data.sonarr_data.main_tabs.set_index(index);
|
||||
|
||||
handle_change_tab_left_right_keys(&mut app, DEFAULT_KEYBINDINGS.right.key);
|
||||
|
||||
assert_eq!(
|
||||
app.data.sonarr_data.main_tabs.get_active_route(),
|
||||
right_block.into()
|
||||
);
|
||||
assert_eq!(app.get_current_route(), right_block.into());
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_delegates_library_blocks_to_library_handler(
|
||||
#[values(
|
||||
// ActiveSonarrBlock::AddSeriesAlreadyInLibrary,
|
||||
// ActiveSonarrBlock::AddSeriesConfirmPrompt,
|
||||
// ActiveSonarrBlock::AddSeriesEmptySearchResults,
|
||||
// ActiveSonarrBlock::AddSeriesPrompt,
|
||||
// ActiveSonarrBlock::AddSeriesSearchInput,
|
||||
// ActiveSonarrBlock::AddSeriesSearchResults,
|
||||
// ActiveSonarrBlock::AddSeriesSelectLanguageProfile,
|
||||
// ActiveSonarrBlock::AddSeriesSelectMonitor,
|
||||
// ActiveSonarrBlock::AddSeriesSelectQualityProfile,
|
||||
// ActiveSonarrBlock::AddSeriesSelectRootFolder,
|
||||
// ActiveSonarrBlock::AddSeriesSelectSeriesType,
|
||||
// ActiveSonarrBlock::AddSeriesTagsInput,
|
||||
// ActiveSonarrBlock::AddSeriesToggleUseSeasonFolder,
|
||||
// ActiveSonarrBlock::AutomaticallySearchEpisodePrompt,
|
||||
// ActiveSonarrBlock::AutomaticallySearchSeasonPrompt,
|
||||
// ActiveSonarrBlock::AutomaticallySearchSeriesPrompt,
|
||||
// ActiveSonarrBlock::DeleteEpisodeFilePrompt,
|
||||
// ActiveSonarrBlock::DeleteSeriesConfirmPrompt,
|
||||
// ActiveSonarrBlock::DeleteSeriesPrompt,
|
||||
// ActiveSonarrBlock::DeleteSeriesToggleAddListExclusion,
|
||||
// ActiveSonarrBlock::DeleteSeriesToggleDeleteFile,
|
||||
// ActiveSonarrBlock::EditSeriesPrompt,
|
||||
// ActiveSonarrBlock::EditSeriesConfirmPrompt,
|
||||
// ActiveSonarrBlock::EditSeriesPathInput,
|
||||
// ActiveSonarrBlock::EditSeriesSelectSeriesType,
|
||||
// ActiveSonarrBlock::EditSeriesSelectQualityProfile,
|
||||
// ActiveSonarrBlock::EditSeriesSelectLanguageProfile,
|
||||
// ActiveSonarrBlock::EditSeriesTagsInput,
|
||||
// ActiveSonarrBlock::EditSeriesToggleMonitored,
|
||||
// ActiveSonarrBlock::EditSeriesToggleSeasonFolder,
|
||||
// ActiveSonarrBlock::EpisodeDetails,
|
||||
// ActiveSonarrBlock::EpisodeFile,
|
||||
// ActiveSonarrBlock::EpisodeHistory,
|
||||
// ActiveSonarrBlock::EpisodesSortPrompt,
|
||||
// ActiveSonarrBlock::FilterEpisodes,
|
||||
// ActiveSonarrBlock::FilterEpisodesError,
|
||||
ActiveSonarrBlock::FilterSeries,
|
||||
ActiveSonarrBlock::FilterSeriesError,
|
||||
// ActiveSonarrBlock::FilterSeriesHistory,
|
||||
// ActiveSonarrBlock::FilterSeriesHistoryError,
|
||||
// ActiveSonarrBlock::ManualEpisodeSearch,
|
||||
// ActiveSonarrBlock::ManualEpisodeSearchConfirmPrompt,
|
||||
// ActiveSonarrBlock::ManualEpisodeSearchSortPrompt,
|
||||
// ActiveSonarrBlock::ManualSeasonSearch,
|
||||
// ActiveSonarrBlock::ManualSeasonSearchConfirmPrompt,
|
||||
// ActiveSonarrBlock::ManualSeasonSearchSortPrompt,
|
||||
// ActiveSonarrBlock::SearchEpisodes,
|
||||
// ActiveSonarrBlock::SearchEpisodesError,
|
||||
// ActiveSonarrBlock::SearchSeason,
|
||||
// ActiveSonarrBlock::SearchSeasonError,
|
||||
ActiveSonarrBlock::SearchSeries,
|
||||
ActiveSonarrBlock::SearchSeriesError,
|
||||
// ActiveSonarrBlock::SearchSeriesHistory,
|
||||
// ActiveSonarrBlock::SearchSeriesHistoryError,
|
||||
// ActiveSonarrBlock::SeasonDetails,
|
||||
ActiveSonarrBlock::Series,
|
||||
// ActiveSonarrBlock::SeriesDetails,
|
||||
// ActiveSonarrBlock::SeriesHistory,
|
||||
// ActiveSonarrBlock::SeriesHistorySortPrompt,
|
||||
ActiveSonarrBlock::SeriesSortPrompt,
|
||||
ActiveSonarrBlock::UpdateAllSeriesPrompt,
|
||||
// ActiveSonarrBlock::UpdateAndScanSeriesPrompt
|
||||
)]
|
||||
active_sonarr_block: ActiveSonarrBlock,
|
||||
) {
|
||||
test_handler_delegation!(
|
||||
SonarrHandler,
|
||||
ActiveSonarrBlock::Series,
|
||||
active_sonarr_block
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user