refactor(handlers): Refactored the handlers to all use the handle_table_events macro when appropriate and created tests for the macro so tests don't have to be duplicated across each handler
This commit is contained in:
@@ -112,14 +112,14 @@ mod test_utils {
|
||||
|
||||
$handler::with(&key, &mut app, &$block, &$context).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
pretty_assertions::assert_str_eq!(
|
||||
app.data.$servarr_data.$data_ref.current_selection(),
|
||||
"Test 2"
|
||||
);
|
||||
|
||||
$handler::with(&key, &mut app, &$block, &$context).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
pretty_assertions::assert_str_eq!(
|
||||
app.data.$servarr_data.$data_ref.current_selection(),
|
||||
"Test 1"
|
||||
);
|
||||
@@ -139,14 +139,14 @@ mod test_utils {
|
||||
|
||||
$handler::with(key, &mut app, $block, $context).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
pretty_assertions::assert_str_eq!(
|
||||
app.data.$servarr_data.$data_ref.current_selection().$field,
|
||||
"Test 2"
|
||||
);
|
||||
|
||||
$handler::with(key, &mut app, $block, $context).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
pretty_assertions::assert_str_eq!(
|
||||
app.data.$servarr_data.$data_ref.current_selection().$field,
|
||||
"Test 1"
|
||||
);
|
||||
@@ -162,14 +162,14 @@ mod test_utils {
|
||||
|
||||
$handler::with(key, &mut app, $block, $context).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
pretty_assertions::assert_str_eq!(
|
||||
app.data.$servarr_data.$data_ref.current_selection().$field,
|
||||
"Test 2"
|
||||
);
|
||||
|
||||
$handler::with(key, &mut app, $block, $context).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
pretty_assertions::assert_str_eq!(
|
||||
app.data.$servarr_data.$data_ref.current_selection().$field,
|
||||
"Test 1"
|
||||
);
|
||||
@@ -185,7 +185,7 @@ mod test_utils {
|
||||
|
||||
$handler::with(key, &mut app, $block, $context).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
pretty_assertions::assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.$servarr_data
|
||||
@@ -198,7 +198,7 @@ mod test_utils {
|
||||
|
||||
$handler::with(key, &mut app, $block, $context).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
pretty_assertions::assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.$servarr_data
|
||||
@@ -227,14 +227,14 @@ mod test_utils {
|
||||
|
||||
$handler::with(DEFAULT_KEYBINDINGS.end.key, &mut app, $block, $context).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
pretty_assertions::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!(
|
||||
pretty_assertions::assert_str_eq!(
|
||||
app.data.$servarr_data.$data_ref.current_selection(),
|
||||
"Test 1"
|
||||
);
|
||||
@@ -254,14 +254,14 @@ mod test_utils {
|
||||
|
||||
$handler::with(DEFAULT_KEYBINDINGS.end.key, &mut app, $block, $context).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
pretty_assertions::assert_str_eq!(
|
||||
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!(
|
||||
pretty_assertions::assert_str_eq!(
|
||||
app.data.$servarr_data.$data_ref.current_selection().$field,
|
||||
"Test 1"
|
||||
);
|
||||
@@ -277,14 +277,14 @@ mod test_utils {
|
||||
|
||||
$handler::with(DEFAULT_KEYBINDINGS.end.key, &mut app, $block, $context).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
pretty_assertions::assert_str_eq!(
|
||||
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!(
|
||||
pretty_assertions::assert_str_eq!(
|
||||
app.data.$servarr_data.$data_ref.current_selection().$field,
|
||||
"Test 1"
|
||||
);
|
||||
@@ -300,7 +300,7 @@ mod test_utils {
|
||||
|
||||
$handler::with(DEFAULT_KEYBINDINGS.end.key, &mut app, $block, $context).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
pretty_assertions::assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.$servarr_data
|
||||
@@ -313,7 +313,7 @@ mod test_utils {
|
||||
|
||||
$handler::with(DEFAULT_KEYBINDINGS.home.key, &mut app, $block, $context).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
pretty_assertions::assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.$servarr_data
|
||||
@@ -335,12 +335,14 @@ mod test_utils {
|
||||
app.data.sonarr_data.root_folders.set_items(vec![$crate::models::servarr_models::RootFolder::default()]);
|
||||
app.data.sonarr_data.indexers.set_items(vec![$crate::models::servarr_models::Indexer::default()]);
|
||||
app.data.sonarr_data.blocklist.set_items(vec![$crate::models::sonarr_models::BlocklistItem::default()]);
|
||||
app.data.sonarr_data.add_searched_series = Some($crate::models::stateful_table::StatefulTable::default());
|
||||
app.data.radarr_data.movies.set_items(vec![$crate::models::radarr_models::Movie::default()]);
|
||||
app.data.radarr_data.collections.set_items(vec![$crate::models::radarr_models::Collection::default()]);
|
||||
app.data.radarr_data.collection_movies.set_items(vec![$crate::models::radarr_models::CollectionMovie::default()]);
|
||||
app.data.radarr_data.indexers.set_items(vec![$crate::models::servarr_models::Indexer::default()]);
|
||||
app.data.radarr_data.root_folders.set_items(vec![$crate::models::servarr_models::RootFolder::default()]);
|
||||
app.data.radarr_data.blocklist.set_items(vec![$crate::models::radarr_models::BlocklistItem::default()]);
|
||||
app.data.radarr_data.add_searched_movies = Some($crate::models::stateful_table::StatefulTable::default());
|
||||
let mut movie_details_modal = $crate::models::servarr_data::radarr::modals::MovieDetailsModal::default();
|
||||
movie_details_modal
|
||||
.movie_history
|
||||
@@ -362,7 +364,7 @@ mod test_utils {
|
||||
|
||||
$handler::with(DEFAULT_KEYBINDINGS.esc.key, &mut app, $active_block, None).handle();
|
||||
|
||||
assert_eq!(app.get_current_route(), $base.into());
|
||||
pretty_assertions::assert_eq!(app.get_current_route(), $base.into());
|
||||
};
|
||||
}
|
||||
|
||||
@@ -373,13 +375,13 @@ mod test_utils {
|
||||
|
||||
$handler::with(DELETE_KEY, &mut app, $block, None).handle();
|
||||
|
||||
assert_eq!(app.get_current_route(), $expected_block.into());
|
||||
pretty_assertions::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());
|
||||
pretty_assertions::assert_eq!($app.get_current_route(), $expected_block.into());
|
||||
};
|
||||
}
|
||||
|
||||
@@ -391,7 +393,7 @@ mod test_utils {
|
||||
|
||||
$handler::with(DEFAULT_KEYBINDINGS.refresh.key, &mut app, $block, None).handle();
|
||||
|
||||
assert_eq!(app.get_current_route(), $block.into());
|
||||
pretty_assertions::assert_eq!(app.get_current_route(), $block.into());
|
||||
assert!(app.should_refresh);
|
||||
};
|
||||
}
|
||||
|
||||
+4
-4
@@ -132,10 +132,10 @@ fn handle_prompt_toggle(app: &mut App<'_>, key: Key) {
|
||||
macro_rules! handle_text_box_left_right_keys {
|
||||
($self:expr, $key:expr, $input:expr) => {
|
||||
match $self.key {
|
||||
_ if $key == DEFAULT_KEYBINDINGS.left.key => {
|
||||
_ if $key == $crate::app::key_binding::DEFAULT_KEYBINDINGS.left.key => {
|
||||
$input.scroll_left();
|
||||
}
|
||||
_ if $key == DEFAULT_KEYBINDINGS.right.key => {
|
||||
_ if $key == $crate::app::key_binding::DEFAULT_KEYBINDINGS.right.key => {
|
||||
$input.scroll_right();
|
||||
}
|
||||
_ => (),
|
||||
@@ -147,7 +147,7 @@ macro_rules! handle_text_box_left_right_keys {
|
||||
macro_rules! handle_text_box_keys {
|
||||
($self:expr, $key:expr, $input:expr) => {
|
||||
match $self.key {
|
||||
_ if $key == DEFAULT_KEYBINDINGS.backspace.key => {
|
||||
_ if $key == $crate::app::key_binding::DEFAULT_KEYBINDINGS.backspace.key => {
|
||||
$input.pop();
|
||||
}
|
||||
Key::Char(character) => {
|
||||
@@ -163,7 +163,7 @@ macro_rules! handle_prompt_left_right_keys {
|
||||
($self:expr, $confirm_prompt:expr, $data:ident) => {
|
||||
if $self.app.data.$data.selected_block.get_active_block() == $confirm_prompt {
|
||||
handle_prompt_toggle($self.app, $self.key);
|
||||
} else if $self.key == DEFAULT_KEYBINDINGS.left.key {
|
||||
} else if $self.key == $crate::app::key_binding::DEFAULT_KEYBINDINGS.left.key {
|
||||
$self.app.data.$data.selected_block.left();
|
||||
} else {
|
||||
$self.app.data.$data.selected_block.right();
|
||||
|
||||
@@ -14,238 +14,6 @@ mod tests {
|
||||
use crate::models::radarr_models::{BlocklistItem, BlocklistItemMovie};
|
||||
use crate::models::servarr_data::radarr::radarr_data::{ActiveRadarrBlock, BLOCKLIST_BLOCKS};
|
||||
use crate::models::servarr_models::{Language, Quality, QualityWrapper};
|
||||
use crate::models::stateful_table::SortOption;
|
||||
|
||||
mod test_handle_scroll_up_and_down {
|
||||
use pretty_assertions::{assert_eq, assert_str_eq};
|
||||
use rstest::rstest;
|
||||
|
||||
use crate::models::radarr_models::BlocklistItem;
|
||||
use crate::{simple_stateful_iterable_vec, test_iterable_scroll};
|
||||
|
||||
use super::*;
|
||||
|
||||
test_iterable_scroll!(
|
||||
test_blocklist_scroll,
|
||||
BlocklistHandler,
|
||||
radarr_data,
|
||||
blocklist,
|
||||
simple_stateful_iterable_vec!(BlocklistItem, String, source_title),
|
||||
ActiveRadarrBlock::Blocklist,
|
||||
None,
|
||||
source_title,
|
||||
to_string
|
||||
);
|
||||
|
||||
#[rstest]
|
||||
fn test_blocklist_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
|
||||
.blocklist
|
||||
.set_items(simple_stateful_iterable_vec!(
|
||||
BlocklistItem,
|
||||
String,
|
||||
source_title
|
||||
));
|
||||
|
||||
BlocklistHandler::with(key, &mut app, ActiveRadarrBlock::Blocklist, None).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.blocklist
|
||||
.current_selection()
|
||||
.source_title
|
||||
.to_string(),
|
||||
"Test 1"
|
||||
);
|
||||
|
||||
BlocklistHandler::with(key, &mut app, ActiveRadarrBlock::Blocklist, None).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.blocklist
|
||||
.current_selection()
|
||||
.source_title
|
||||
.to_string(),
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_blocklist_sort_scroll(
|
||||
#[values(DEFAULT_KEYBINDINGS.up.key, DEFAULT_KEYBINDINGS.down.key)] key: Key,
|
||||
) {
|
||||
let blocklist_field_vec = sort_options();
|
||||
let mut app = App::default();
|
||||
app.data.radarr_data.blocklist.sorting(sort_options());
|
||||
|
||||
if key == Key::Up {
|
||||
for i in (0..blocklist_field_vec.len()).rev() {
|
||||
BlocklistHandler::with(key, &mut app, ActiveRadarrBlock::BlocklistSortPrompt, None)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.blocklist
|
||||
.sort
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection(),
|
||||
&blocklist_field_vec[i]
|
||||
);
|
||||
}
|
||||
} else {
|
||||
for i in 0..blocklist_field_vec.len() {
|
||||
BlocklistHandler::with(key, &mut app, ActiveRadarrBlock::BlocklistSortPrompt, None)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.blocklist
|
||||
.sort
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection(),
|
||||
&blocklist_field_vec[(i + 1) % blocklist_field_vec.len()]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_home_end {
|
||||
use pretty_assertions::{assert_eq, assert_str_eq};
|
||||
|
||||
use crate::models::radarr_models::BlocklistItem;
|
||||
use crate::{extended_stateful_iterable_vec, test_iterable_home_and_end};
|
||||
|
||||
use super::*;
|
||||
|
||||
test_iterable_home_and_end!(
|
||||
test_blocklist_home_and_end,
|
||||
BlocklistHandler,
|
||||
radarr_data,
|
||||
blocklist,
|
||||
extended_stateful_iterable_vec!(BlocklistItem, String, source_title),
|
||||
ActiveRadarrBlock::Blocklist,
|
||||
None,
|
||||
source_title,
|
||||
to_string
|
||||
);
|
||||
|
||||
#[test]
|
||||
fn test_blocklist_home_and_end_no_op_when_not_ready() {
|
||||
let mut app = App::default();
|
||||
app.is_loading = true;
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.blocklist
|
||||
.set_items(extended_stateful_iterable_vec!(
|
||||
BlocklistItem,
|
||||
String,
|
||||
source_title
|
||||
));
|
||||
|
||||
BlocklistHandler::with(
|
||||
DEFAULT_KEYBINDINGS.end.key,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::Blocklist,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.blocklist
|
||||
.current_selection()
|
||||
.source_title
|
||||
.to_string(),
|
||||
"Test 1"
|
||||
);
|
||||
|
||||
BlocklistHandler::with(
|
||||
DEFAULT_KEYBINDINGS.home.key,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::Blocklist,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.blocklist
|
||||
.current_selection()
|
||||
.source_title
|
||||
.to_string(),
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_blocklist_sort_home_end() {
|
||||
let blocklist_field_vec = sort_options();
|
||||
let mut app = App::default();
|
||||
app.data.radarr_data.blocklist.sorting(sort_options());
|
||||
|
||||
BlocklistHandler::with(
|
||||
DEFAULT_KEYBINDINGS.end.key,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::BlocklistSortPrompt,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.blocklist
|
||||
.sort
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection(),
|
||||
&blocklist_field_vec[blocklist_field_vec.len() - 1]
|
||||
);
|
||||
|
||||
BlocklistHandler::with(
|
||||
DEFAULT_KEYBINDINGS.home.key,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::BlocklistSortPrompt,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.blocklist
|
||||
.sort
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection(),
|
||||
&blocklist_field_vec[0]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_delete {
|
||||
use pretty_assertions::assert_eq;
|
||||
@@ -439,31 +207,6 @@ mod tests {
|
||||
assert_eq!(app.data.radarr_data.prompt_confirm_action, None);
|
||||
assert_eq!(app.get_current_route(), ActiveRadarrBlock::Blocklist.into());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_blocklist_sort_prompt_submit() {
|
||||
let mut app = App::default();
|
||||
app.data.radarr_data.blocklist.sort_asc = true;
|
||||
app.data.radarr_data.blocklist.sorting(sort_options());
|
||||
app.data.radarr_data.blocklist.set_items(blocklist_vec());
|
||||
app.push_navigation_stack(ActiveRadarrBlock::Blocklist.into());
|
||||
app.push_navigation_stack(ActiveRadarrBlock::BlocklistSortPrompt.into());
|
||||
|
||||
let mut expected_vec = blocklist_vec();
|
||||
expected_vec.sort_by(|a, b| a.id.cmp(&b.id));
|
||||
expected_vec.reverse();
|
||||
|
||||
BlocklistHandler::with(
|
||||
SUBMIT_KEY,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::BlocklistSortPrompt,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(app.get_current_route(), ActiveRadarrBlock::Blocklist.into());
|
||||
assert_eq!(app.data.radarr_data.blocklist.items, expected_vec);
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_esc {
|
||||
@@ -517,24 +260,6 @@ mod tests {
|
||||
assert_eq!(app.get_current_route(), ActiveRadarrBlock::Blocklist.into());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_blocklist_sort_prompt_block_esc() {
|
||||
let mut app = App::default();
|
||||
app.data.radarr_data.blocklist.set_items(vec![BlocklistItem::default()]);
|
||||
app.push_navigation_stack(ActiveRadarrBlock::Blocklist.into());
|
||||
app.push_navigation_stack(ActiveRadarrBlock::BlocklistSortPrompt.into());
|
||||
|
||||
BlocklistHandler::with(
|
||||
ESC_KEY,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::BlocklistSortPrompt,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(app.get_current_route(), ActiveRadarrBlock::Blocklist.into());
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_default_esc(#[values(true, false)] is_ready: bool) {
|
||||
let mut app = App::default();
|
||||
@@ -632,51 +357,6 @@ mod tests {
|
||||
assert_eq!(app.get_current_route(), ActiveRadarrBlock::Blocklist.into());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sort_key() {
|
||||
let mut app = App::default();
|
||||
app.push_navigation_stack(ActiveRadarrBlock::Blocklist.into());
|
||||
app.data.radarr_data.blocklist.set_items(blocklist_vec());
|
||||
|
||||
BlocklistHandler::with(
|
||||
DEFAULT_KEYBINDINGS.sort.key,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::Blocklist,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
ActiveRadarrBlock::BlocklistSortPrompt.into()
|
||||
);
|
||||
assert_eq!(
|
||||
app.data.radarr_data.blocklist.sort.as_ref().unwrap().items,
|
||||
blocklist_sorting_options()
|
||||
);
|
||||
assert!(!app.data.radarr_data.blocklist.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::Blocklist.into());
|
||||
app.data.radarr_data.blocklist.set_items(blocklist_vec());
|
||||
|
||||
BlocklistHandler::with(
|
||||
DEFAULT_KEYBINDINGS.sort.key,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::Blocklist,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(app.get_current_route(), ActiveRadarrBlock::Blocklist.into());
|
||||
assert!(app.data.radarr_data.blocklist.sort.is_none());
|
||||
assert!(!app.data.radarr_data.blocklist.sort_asc);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
#[case(
|
||||
ActiveRadarrBlock::Blocklist,
|
||||
@@ -987,15 +667,4 @@ mod tests {
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
fn sort_options() -> Vec<SortOption<BlocklistItem>> {
|
||||
vec![SortOption {
|
||||
name: "Test 1",
|
||||
cmp_fn: Some(|a, b| {
|
||||
b.source_title
|
||||
.to_lowercase()
|
||||
.cmp(&a.source_title.to_lowercase())
|
||||
}),
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,11 @@ use crate::app::App;
|
||||
use crate::event::Key;
|
||||
use crate::handle_table_events;
|
||||
use crate::handlers::radarr_handlers::handle_change_tab_left_right_keys;
|
||||
use crate::handlers::table_handler::TableHandlingProps;
|
||||
use crate::handlers::table_handler::TableHandlingConfig;
|
||||
use crate::handlers::{handle_clear_errors, handle_prompt_toggle, KeyEventHandler};
|
||||
use crate::models::radarr_models::BlocklistItem;
|
||||
use crate::models::servarr_data::radarr::radarr_data::{ActiveRadarrBlock, BLOCKLIST_BLOCKS};
|
||||
use crate::models::stateful_table::SortOption;
|
||||
use crate::models::Scrollable;
|
||||
use crate::network::radarr_network::RadarrEvent;
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -33,13 +32,13 @@ impl<'a, 'b> BlocklistHandler<'a, 'b> {
|
||||
|
||||
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for BlocklistHandler<'a, 'b> {
|
||||
fn handle(&mut self) {
|
||||
let blocklist_table_handling_props =
|
||||
TableHandlingProps::new(ActiveRadarrBlock::Blocklist.into())
|
||||
let blocklist_table_handling_config =
|
||||
TableHandlingConfig::new(ActiveRadarrBlock::Blocklist.into())
|
||||
.sorting_block(ActiveRadarrBlock::BlocklistSortPrompt.into())
|
||||
.sort_by_fn(|a: &BlocklistItem, b: &BlocklistItem| a.id.cmp(&b.id))
|
||||
.sort_options(blocklist_sorting_options());
|
||||
|
||||
if !self.handle_blocklist_table_events(blocklist_table_handling_props) {
|
||||
if !self.handle_blocklist_table_events(blocklist_table_handling_config) {
|
||||
self.handle_key_event();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ use crate::app::key_binding::DEFAULT_KEYBINDINGS;
|
||||
use crate::app::App;
|
||||
use crate::event::Key;
|
||||
use crate::handle_table_events;
|
||||
use crate::handlers::table_handler::TableHandlingProps;
|
||||
use crate::handlers::table_handler::TableHandlingConfig;
|
||||
use crate::handlers::KeyEventHandler;
|
||||
use crate::models::radarr_models::CollectionMovie;
|
||||
use crate::models::servarr_data::radarr::radarr_data::{
|
||||
@@ -10,7 +10,7 @@ use crate::models::servarr_data::radarr::radarr_data::{
|
||||
EDIT_COLLECTION_SELECTION_BLOCKS,
|
||||
};
|
||||
use crate::models::stateful_table::StatefulTable;
|
||||
use crate::models::{BlockSelectionState, Scrollable};
|
||||
use crate::models::BlockSelectionState;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "collection_details_handler_tests.rs"]
|
||||
@@ -34,10 +34,10 @@ impl<'a, 'b> CollectionDetailsHandler<'a, 'b> {
|
||||
|
||||
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for CollectionDetailsHandler<'a, 'b> {
|
||||
fn handle(&mut self) {
|
||||
let collection_movies_table_handling_props =
|
||||
TableHandlingProps::new(ActiveRadarrBlock::CollectionDetails.into());
|
||||
let collection_movies_table_handling_config =
|
||||
TableHandlingConfig::new(ActiveRadarrBlock::CollectionDetails.into());
|
||||
|
||||
if !self.handle_collection_movies_table_events(collection_movies_table_handling_props) {
|
||||
if !self.handle_collection_movies_table_events(collection_movies_table_handling_config) {
|
||||
self.handle_key_event();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,144 +12,6 @@ mod tests {
|
||||
use crate::models::servarr_data::radarr::radarr_data::{
|
||||
ActiveRadarrBlock, COLLECTION_DETAILS_BLOCKS,
|
||||
};
|
||||
use crate::models::HorizontallyScrollableText;
|
||||
|
||||
mod test_handle_scroll_up_and_down {
|
||||
use rstest::rstest;
|
||||
|
||||
use crate::{simple_stateful_iterable_vec, test_iterable_scroll};
|
||||
|
||||
use super::*;
|
||||
|
||||
test_iterable_scroll!(
|
||||
test_collection_details_scroll,
|
||||
CollectionDetailsHandler,
|
||||
radarr_data,
|
||||
collection_movies,
|
||||
simple_stateful_iterable_vec!(CollectionMovie, HorizontallyScrollableText),
|
||||
ActiveRadarrBlock::CollectionDetails,
|
||||
None,
|
||||
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 {
|
||||
use crate::{extended_stateful_iterable_vec, test_iterable_home_and_end};
|
||||
|
||||
use super::*;
|
||||
|
||||
test_iterable_home_and_end!(
|
||||
test_collection_details_home_end,
|
||||
CollectionDetailsHandler,
|
||||
radarr_data,
|
||||
collection_movies,
|
||||
extended_stateful_iterable_vec!(CollectionMovie, HorizontallyScrollableText),
|
||||
ActiveRadarrBlock::CollectionDetails,
|
||||
None,
|
||||
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 {
|
||||
use bimap::BiMap;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -5,14 +5,14 @@ use crate::handle_table_events;
|
||||
use crate::handlers::radarr_handlers::collections::collection_details_handler::CollectionDetailsHandler;
|
||||
use crate::handlers::radarr_handlers::collections::edit_collection_handler::EditCollectionHandler;
|
||||
use crate::handlers::radarr_handlers::handle_change_tab_left_right_keys;
|
||||
use crate::handlers::table_handler::TableHandlingProps;
|
||||
use crate::handlers::table_handler::TableHandlingConfig;
|
||||
use crate::handlers::{handle_clear_errors, handle_prompt_toggle, KeyEventHandler};
|
||||
use crate::models::radarr_models::Collection;
|
||||
use crate::models::servarr_data::radarr::radarr_data::{
|
||||
ActiveRadarrBlock, COLLECTIONS_BLOCKS, EDIT_COLLECTION_SELECTION_BLOCKS,
|
||||
};
|
||||
use crate::models::stateful_table::SortOption;
|
||||
use crate::models::{BlockSelectionState, Scrollable};
|
||||
use crate::models::BlockSelectionState;
|
||||
use crate::network::radarr_network::RadarrEvent;
|
||||
|
||||
mod collection_details_handler;
|
||||
@@ -40,8 +40,8 @@ impl<'a, 'b> CollectionsHandler<'a, 'b> {
|
||||
|
||||
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for CollectionsHandler<'a, 'b> {
|
||||
fn handle(&mut self) {
|
||||
let collections_table_handling_props =
|
||||
TableHandlingProps::new(ActiveRadarrBlock::Collections.into())
|
||||
let collections_table_handling_config =
|
||||
TableHandlingConfig::new(ActiveRadarrBlock::Collections.into())
|
||||
.sorting_block(ActiveRadarrBlock::CollectionsSortPrompt.into())
|
||||
.sort_by_fn(|a: &Collection, b: &Collection| a.id.cmp(&b.id))
|
||||
.sort_options(collections_sorting_options())
|
||||
@@ -52,7 +52,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for CollectionsHandler<'
|
||||
.filter_error_block(ActiveRadarrBlock::FilterCollectionsError.into())
|
||||
.filter_field_fn(|collection| &collection.title.text);
|
||||
|
||||
if !self.handle_collections_table_events(collections_table_handling_props) {
|
||||
if !self.handle_collections_table_events(collections_table_handling_config) {
|
||||
match self.active_radarr_block {
|
||||
_ if CollectionDetailsHandler::accepts(self.active_radarr_block) => {
|
||||
CollectionDetailsHandler::with(
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use pretty_assertions::assert_str_eq;
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
use crate::app::key_binding::DEFAULT_KEYBINDINGS;
|
||||
@@ -11,111 +10,6 @@ mod tests {
|
||||
use crate::models::radarr_models::DownloadRecord;
|
||||
use crate::models::servarr_data::radarr::radarr_data::{ActiveRadarrBlock, DOWNLOADS_BLOCKS};
|
||||
|
||||
mod test_handle_scroll_up_and_down {
|
||||
use rstest::rstest;
|
||||
|
||||
use crate::models::radarr_models::DownloadRecord;
|
||||
use crate::{simple_stateful_iterable_vec, test_iterable_scroll};
|
||||
|
||||
use super::*;
|
||||
|
||||
test_iterable_scroll!(
|
||||
test_downloads_scroll,
|
||||
DownloadsHandler,
|
||||
radarr_data,
|
||||
downloads,
|
||||
DownloadRecord,
|
||||
ActiveRadarrBlock::Downloads,
|
||||
None,
|
||||
title
|
||||
);
|
||||
|
||||
#[rstest]
|
||||
fn test_downloads_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
|
||||
.downloads
|
||||
.set_items(simple_stateful_iterable_vec!(DownloadRecord));
|
||||
|
||||
DownloadsHandler::with(key, &mut app, ActiveRadarrBlock::Downloads, None).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app.data.radarr_data.downloads.current_selection().title,
|
||||
"Test 1"
|
||||
);
|
||||
|
||||
DownloadsHandler::with(key, &mut app, ActiveRadarrBlock::Downloads, None).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app.data.radarr_data.downloads.current_selection().title,
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_home_end {
|
||||
use crate::models::radarr_models::DownloadRecord;
|
||||
use crate::{extended_stateful_iterable_vec, test_iterable_home_and_end};
|
||||
|
||||
use super::*;
|
||||
|
||||
test_iterable_home_and_end!(
|
||||
test_downloads_home_end,
|
||||
DownloadsHandler,
|
||||
radarr_data,
|
||||
downloads,
|
||||
DownloadRecord,
|
||||
ActiveRadarrBlock::Downloads,
|
||||
None,
|
||||
title
|
||||
);
|
||||
|
||||
#[test]
|
||||
fn test_downloads_home_end_no_op_when_not_ready() {
|
||||
let mut app = App::default();
|
||||
app.is_loading = true;
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.downloads
|
||||
.set_items(extended_stateful_iterable_vec!(DownloadRecord));
|
||||
|
||||
DownloadsHandler::with(
|
||||
DEFAULT_KEYBINDINGS.end.key,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::Downloads,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app.data.radarr_data.downloads.current_selection().title,
|
||||
"Test 1"
|
||||
);
|
||||
|
||||
DownloadsHandler::with(
|
||||
DEFAULT_KEYBINDINGS.home.key,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::Downloads,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app.data.radarr_data.downloads.current_selection().title,
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_delete {
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
|
||||
@@ -3,11 +3,10 @@ use crate::app::App;
|
||||
use crate::event::Key;
|
||||
use crate::handle_table_events;
|
||||
use crate::handlers::radarr_handlers::handle_change_tab_left_right_keys;
|
||||
use crate::handlers::table_handler::TableHandlingProps;
|
||||
use crate::handlers::table_handler::TableHandlingConfig;
|
||||
use crate::handlers::{handle_clear_errors, handle_prompt_toggle, KeyEventHandler};
|
||||
use crate::models::radarr_models::DownloadRecord;
|
||||
use crate::models::servarr_data::radarr::radarr_data::{ActiveRadarrBlock, DOWNLOADS_BLOCKS};
|
||||
use crate::models::Scrollable;
|
||||
use crate::network::radarr_network::RadarrEvent;
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -32,10 +31,10 @@ impl<'a, 'b> DownloadsHandler<'a, 'b> {
|
||||
|
||||
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for DownloadsHandler<'a, 'b> {
|
||||
fn handle(&mut self) {
|
||||
let downloads_table_handling_props =
|
||||
TableHandlingProps::new(ActiveRadarrBlock::Downloads.into());
|
||||
let downloads_table_handling_config =
|
||||
TableHandlingConfig::new(ActiveRadarrBlock::Downloads.into());
|
||||
|
||||
if !self.handle_downloads_table_events(downloads_table_handling_props) {
|
||||
if !self.handle_downloads_table_events(downloads_table_handling_config) {
|
||||
self.handle_key_event();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use pretty_assertions::{assert_eq, assert_str_eq};
|
||||
use rstest::rstest;
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
@@ -15,109 +14,6 @@ mod tests {
|
||||
use crate::models::servarr_models::Indexer;
|
||||
use crate::test_handler_delegation;
|
||||
|
||||
mod test_handle_scroll_up_and_down {
|
||||
use rstest::rstest;
|
||||
|
||||
use crate::{simple_stateful_iterable_vec, test_iterable_scroll};
|
||||
|
||||
use super::*;
|
||||
|
||||
test_iterable_scroll!(
|
||||
test_indexers_scroll,
|
||||
IndexersHandler,
|
||||
radarr_data,
|
||||
indexers,
|
||||
simple_stateful_iterable_vec!(Indexer, String, protocol),
|
||||
ActiveRadarrBlock::Indexers,
|
||||
None,
|
||||
protocol
|
||||
);
|
||||
|
||||
#[rstest]
|
||||
fn test_indexers_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
|
||||
.indexers
|
||||
.set_items(simple_stateful_iterable_vec!(Indexer, String, protocol));
|
||||
|
||||
IndexersHandler::with(key, &mut app, ActiveRadarrBlock::Indexers, None).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app.data.radarr_data.indexers.current_selection().protocol,
|
||||
"Test 1"
|
||||
);
|
||||
|
||||
IndexersHandler::with(key, &mut app, ActiveRadarrBlock::Indexers, None).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app.data.radarr_data.indexers.current_selection().protocol,
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_home_end {
|
||||
use crate::{extended_stateful_iterable_vec, test_iterable_home_and_end};
|
||||
|
||||
use super::*;
|
||||
|
||||
test_iterable_home_and_end!(
|
||||
test_indexers_home_end,
|
||||
IndexersHandler,
|
||||
radarr_data,
|
||||
indexers,
|
||||
extended_stateful_iterable_vec!(Indexer, String, protocol),
|
||||
ActiveRadarrBlock::Indexers,
|
||||
None,
|
||||
protocol
|
||||
);
|
||||
|
||||
#[test]
|
||||
fn test_indexers_home_end_no_op_when_not_ready() {
|
||||
let mut app = App::default();
|
||||
app.is_loading = true;
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.indexers
|
||||
.set_items(extended_stateful_iterable_vec!(Indexer, String, protocol));
|
||||
|
||||
IndexersHandler::with(
|
||||
DEFAULT_KEYBINDINGS.end.key,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::Indexers,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app.data.radarr_data.indexers.current_selection().protocol,
|
||||
"Test 1"
|
||||
);
|
||||
|
||||
IndexersHandler::with(
|
||||
DEFAULT_KEYBINDINGS.home.key,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::Indexers,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app.data.radarr_data.indexers.current_selection().protocol,
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_delete {
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ use crate::handlers::radarr_handlers::handle_change_tab_left_right_keys;
|
||||
use crate::handlers::radarr_handlers::indexers::edit_indexer_handler::EditIndexerHandler;
|
||||
use crate::handlers::radarr_handlers::indexers::edit_indexer_settings_handler::IndexerSettingsHandler;
|
||||
use crate::handlers::radarr_handlers::indexers::test_all_indexers_handler::TestAllIndexersHandler;
|
||||
use crate::handlers::table_handler::TableHandlingProps;
|
||||
use crate::handlers::table_handler::TableHandlingConfig;
|
||||
use crate::handlers::{handle_clear_errors, handle_prompt_toggle, KeyEventHandler};
|
||||
use crate::models::servarr_data::radarr::radarr_data::{
|
||||
ActiveRadarrBlock, EDIT_INDEXER_NZB_SELECTION_BLOCKS, EDIT_INDEXER_TORRENT_SELECTION_BLOCKS,
|
||||
@@ -14,7 +14,6 @@ use crate::models::servarr_data::radarr::radarr_data::{
|
||||
};
|
||||
use crate::models::servarr_models::Indexer;
|
||||
use crate::models::BlockSelectionState;
|
||||
use crate::models::Scrollable;
|
||||
use crate::network::radarr_network::RadarrEvent;
|
||||
|
||||
mod edit_indexer_handler;
|
||||
@@ -38,9 +37,10 @@ impl<'a, 'b> IndexersHandler<'a, 'b> {
|
||||
|
||||
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for IndexersHandler<'a, 'b> {
|
||||
fn handle(&mut self) {
|
||||
let indexer_table_handling_props = TableHandlingProps::new(ActiveRadarrBlock::Indexers.into());
|
||||
let indexer_table_handling_config =
|
||||
TableHandlingConfig::new(ActiveRadarrBlock::Indexers.into());
|
||||
|
||||
if !self.handle_indexers_table_events(indexer_table_handling_props) {
|
||||
if !self.handle_indexers_table_events(indexer_table_handling_config) {
|
||||
match self.active_radarr_block {
|
||||
_ if EditIndexerHandler::accepts(self.active_radarr_block) => {
|
||||
EditIndexerHandler::with(self.key, self.app, self.active_radarr_block, self.context)
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
use crate::app::App;
|
||||
use crate::event::Key;
|
||||
use crate::handle_table_events;
|
||||
use crate::handlers::table_handler::TableHandlingConfig;
|
||||
use crate::handlers::KeyEventHandler;
|
||||
use crate::models::servarr_data::modals::IndexerTestResultModalItem;
|
||||
use crate::models::servarr_data::radarr::radarr_data::ActiveRadarrBlock;
|
||||
use crate::models::Scrollable;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "test_all_indexers_handler_tests.rs"]
|
||||
@@ -15,7 +17,33 @@ pub(super) struct TestAllIndexersHandler<'a, 'b> {
|
||||
_context: Option<ActiveRadarrBlock>,
|
||||
}
|
||||
|
||||
impl<'a, 'b> TestAllIndexersHandler<'a, 'b> {
|
||||
handle_table_events!(
|
||||
self,
|
||||
indexer_test_all_results,
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.indexer_test_all_results
|
||||
.as_mut()
|
||||
.unwrap(),
|
||||
IndexerTestResultModalItem
|
||||
);
|
||||
}
|
||||
|
||||
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for TestAllIndexersHandler<'a, 'b> {
|
||||
fn handle(&mut self) {
|
||||
let test_all_indexers_test_results_table_handler_config =
|
||||
TableHandlingConfig::new(ActiveRadarrBlock::TestAllIndexers.into());
|
||||
|
||||
if !self.handle_indexer_test_all_results_table_events(
|
||||
test_all_indexers_test_results_table_handler_config,
|
||||
) {
|
||||
self.handle_key_event();
|
||||
}
|
||||
}
|
||||
|
||||
fn accepts(active_block: ActiveRadarrBlock) -> bool {
|
||||
active_block == ActiveRadarrBlock::TestAllIndexers
|
||||
}
|
||||
@@ -48,57 +76,13 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for TestAllIndexersHandl
|
||||
!self.app.is_loading && table_is_ready
|
||||
}
|
||||
|
||||
fn handle_scroll_up(&mut self) {
|
||||
if self.active_radarr_block == ActiveRadarrBlock::TestAllIndexers {
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.indexer_test_all_results
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.scroll_up()
|
||||
}
|
||||
}
|
||||
fn handle_scroll_up(&mut self) {}
|
||||
|
||||
fn handle_scroll_down(&mut self) {
|
||||
if self.active_radarr_block == ActiveRadarrBlock::TestAllIndexers {
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.indexer_test_all_results
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.scroll_down()
|
||||
}
|
||||
}
|
||||
fn handle_scroll_down(&mut self) {}
|
||||
|
||||
fn handle_home(&mut self) {
|
||||
if self.active_radarr_block == ActiveRadarrBlock::TestAllIndexers {
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.indexer_test_all_results
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.scroll_to_top()
|
||||
}
|
||||
}
|
||||
fn handle_home(&mut self) {}
|
||||
|
||||
fn handle_end(&mut self) {
|
||||
if self.active_radarr_block == ActiveRadarrBlock::TestAllIndexers {
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.indexer_test_all_results
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.scroll_to_bottom()
|
||||
}
|
||||
}
|
||||
fn handle_end(&mut self) {}
|
||||
|
||||
fn handle_delete(&mut self) {}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
mod tests {
|
||||
use crate::app::key_binding::DEFAULT_KEYBINDINGS;
|
||||
use crate::app::App;
|
||||
use crate::event::Key;
|
||||
use crate::handlers::radarr_handlers::indexers::test_all_indexers_handler::TestAllIndexersHandler;
|
||||
use crate::handlers::KeyEventHandler;
|
||||
use crate::models::servarr_data::modals::IndexerTestResultModalItem;
|
||||
@@ -10,220 +9,6 @@ mod tests {
|
||||
use crate::models::stateful_table::StatefulTable;
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
mod test_handle_scroll_up_and_down {
|
||||
use pretty_assertions::assert_str_eq;
|
||||
use rstest::rstest;
|
||||
|
||||
use crate::models::servarr_data::modals::IndexerTestResultModalItem;
|
||||
use crate::models::stateful_table::StatefulTable;
|
||||
use crate::simple_stateful_iterable_vec;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[rstest]
|
||||
fn test_test_all_indexers_results_scroll(
|
||||
#[values(DEFAULT_KEYBINDINGS.up.key, DEFAULT_KEYBINDINGS.down.key)] key: Key,
|
||||
) {
|
||||
let mut app = App::default();
|
||||
let mut indexer_test_results = StatefulTable::default();
|
||||
indexer_test_results.set_items(simple_stateful_iterable_vec!(
|
||||
IndexerTestResultModalItem,
|
||||
String,
|
||||
name
|
||||
));
|
||||
app.data.radarr_data.indexer_test_all_results = Some(indexer_test_results);
|
||||
|
||||
TestAllIndexersHandler::with(key, &mut app, ActiveRadarrBlock::TestAllIndexers, None)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.indexer_test_all_results
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.name,
|
||||
"Test 2"
|
||||
);
|
||||
|
||||
TestAllIndexersHandler::with(key, &mut app, ActiveRadarrBlock::TestAllIndexers, None)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.indexer_test_all_results
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.name,
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_test_all_indexers_results_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;
|
||||
let mut indexer_test_results = StatefulTable::default();
|
||||
indexer_test_results.set_items(simple_stateful_iterable_vec!(
|
||||
IndexerTestResultModalItem,
|
||||
String,
|
||||
name
|
||||
));
|
||||
app.data.radarr_data.indexer_test_all_results = Some(indexer_test_results);
|
||||
|
||||
TestAllIndexersHandler::with(key, &mut app, ActiveRadarrBlock::TestAllIndexers, None)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.indexer_test_all_results
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.name,
|
||||
"Test 1"
|
||||
);
|
||||
|
||||
TestAllIndexersHandler::with(key, &mut app, ActiveRadarrBlock::TestAllIndexers, None)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.indexer_test_all_results
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.name,
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_home_end {
|
||||
use crate::extended_stateful_iterable_vec;
|
||||
use crate::models::servarr_data::modals::IndexerTestResultModalItem;
|
||||
use crate::models::stateful_table::StatefulTable;
|
||||
use pretty_assertions::assert_str_eq;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_test_all_indexers_results_home_end() {
|
||||
let mut app = App::default();
|
||||
let mut indexer_test_results = StatefulTable::default();
|
||||
indexer_test_results.set_items(extended_stateful_iterable_vec!(
|
||||
IndexerTestResultModalItem,
|
||||
String,
|
||||
name
|
||||
));
|
||||
app.data.radarr_data.indexer_test_all_results = Some(indexer_test_results);
|
||||
|
||||
TestAllIndexersHandler::with(
|
||||
DEFAULT_KEYBINDINGS.end.key,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::TestAllIndexers,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.indexer_test_all_results
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.name,
|
||||
"Test 3"
|
||||
);
|
||||
|
||||
TestAllIndexersHandler::with(
|
||||
DEFAULT_KEYBINDINGS.home.key,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::TestAllIndexers,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.indexer_test_all_results
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.name,
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_test_all_indexers_results_home_end_no_op_when_not_ready() {
|
||||
let mut app = App::default();
|
||||
app.is_loading = true;
|
||||
let mut indexer_test_results = StatefulTable::default();
|
||||
indexer_test_results.set_items(extended_stateful_iterable_vec!(
|
||||
IndexerTestResultModalItem,
|
||||
String,
|
||||
name
|
||||
));
|
||||
app.data.radarr_data.indexer_test_all_results = Some(indexer_test_results);
|
||||
|
||||
TestAllIndexersHandler::with(
|
||||
DEFAULT_KEYBINDINGS.end.key,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::TestAllIndexers,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.indexer_test_all_results
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.name,
|
||||
"Test 1"
|
||||
);
|
||||
|
||||
TestAllIndexersHandler::with(
|
||||
DEFAULT_KEYBINDINGS.home.key,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::TestAllIndexers,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.indexer_test_all_results
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.name,
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_esc {
|
||||
use super::*;
|
||||
use crate::models::stateful_table::StatefulTable;
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
use crate::app::key_binding::DEFAULT_KEYBINDINGS;
|
||||
use crate::handlers::table_handler::TableHandlingConfig;
|
||||
use crate::handlers::{handle_prompt_toggle, KeyEventHandler};
|
||||
use crate::models::radarr_models::AddMovieSearchResult;
|
||||
use crate::models::servarr_data::radarr::radarr_data::{
|
||||
ActiveRadarrBlock, ADD_MOVIE_BLOCKS, ADD_MOVIE_SELECTION_BLOCKS,
|
||||
};
|
||||
use crate::models::{BlockSelectionState, Scrollable};
|
||||
use crate::network::radarr_network::RadarrEvent;
|
||||
use crate::{handle_text_box_keys, handle_text_box_left_right_keys, App, Key};
|
||||
use crate::{handle_table_events, handle_text_box_keys, handle_text_box_left_right_keys, App, Key};
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "add_movie_handler_tests.rs"]
|
||||
@@ -18,7 +20,31 @@ pub(super) struct AddMovieHandler<'a, 'b> {
|
||||
context: Option<ActiveRadarrBlock>,
|
||||
}
|
||||
|
||||
impl<'a, 'b> AddMovieHandler<'a, 'b> {
|
||||
handle_table_events!(
|
||||
self,
|
||||
add_movie_search_results,
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.add_searched_movies
|
||||
.as_mut()
|
||||
.unwrap(),
|
||||
AddMovieSearchResult
|
||||
);
|
||||
}
|
||||
|
||||
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for AddMovieHandler<'a, 'b> {
|
||||
fn handle(&mut self) {
|
||||
let add_movie_table_handling_config =
|
||||
TableHandlingConfig::new(ActiveRadarrBlock::AddMovieSearchResults.into());
|
||||
|
||||
if !self.handle_add_movie_search_results_table_events(add_movie_table_handling_config) {
|
||||
self.handle_key_event();
|
||||
}
|
||||
}
|
||||
|
||||
fn accepts(active_block: ActiveRadarrBlock) -> bool {
|
||||
ADD_MOVIE_BLOCKS.contains(&active_block)
|
||||
}
|
||||
@@ -47,14 +73,6 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for AddMovieHandler<'a,
|
||||
|
||||
fn handle_scroll_up(&mut self) {
|
||||
match self.active_radarr_block {
|
||||
ActiveRadarrBlock::AddMovieSearchResults => self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.add_searched_movies
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.scroll_up(),
|
||||
ActiveRadarrBlock::AddMovieSelectMonitor => self
|
||||
.app
|
||||
.data
|
||||
@@ -98,14 +116,6 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for AddMovieHandler<'a,
|
||||
|
||||
fn handle_scroll_down(&mut self) {
|
||||
match self.active_radarr_block {
|
||||
ActiveRadarrBlock::AddMovieSearchResults => self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.add_searched_movies
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.scroll_down(),
|
||||
ActiveRadarrBlock::AddMovieSelectMonitor => self
|
||||
.app
|
||||
.data
|
||||
@@ -149,14 +159,6 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for AddMovieHandler<'a,
|
||||
|
||||
fn handle_home(&mut self) {
|
||||
match self.active_radarr_block {
|
||||
ActiveRadarrBlock::AddMovieSearchResults => self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.add_searched_movies
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.scroll_to_top(),
|
||||
ActiveRadarrBlock::AddMovieSelectMonitor => self
|
||||
.app
|
||||
.data
|
||||
@@ -216,14 +218,6 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for AddMovieHandler<'a,
|
||||
|
||||
fn handle_end(&mut self) {
|
||||
match self.active_radarr_block {
|
||||
ActiveRadarrBlock::AddMovieSearchResults => self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.add_searched_movies
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.scroll_to_bottom(),
|
||||
ActiveRadarrBlock::AddMovieSelectMonitor => self
|
||||
.app
|
||||
.data
|
||||
|
||||
@@ -20,123 +20,11 @@ mod tests {
|
||||
|
||||
use crate::models::servarr_data::radarr::modals::AddMovieModal;
|
||||
use crate::models::servarr_data::radarr::radarr_data::ADD_MOVIE_SELECTION_BLOCKS;
|
||||
use crate::models::stateful_table::StatefulTable;
|
||||
use crate::models::BlockSelectionState;
|
||||
use crate::simple_stateful_iterable_vec;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[rstest]
|
||||
fn test_add_movie_search_results_scroll(
|
||||
#[values(DEFAULT_KEYBINDINGS.up.key, DEFAULT_KEYBINDINGS.down.key)] key: Key,
|
||||
) {
|
||||
let mut app = App::default();
|
||||
let mut add_searched_movies = StatefulTable::default();
|
||||
add_searched_movies.set_items(simple_stateful_iterable_vec!(
|
||||
AddMovieSearchResult,
|
||||
HorizontallyScrollableText
|
||||
));
|
||||
app.data.radarr_data.add_searched_movies = Some(add_searched_movies);
|
||||
|
||||
AddMovieHandler::with(
|
||||
key,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::AddMovieSearchResults,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.add_searched_movies
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.title
|
||||
.to_string(),
|
||||
"Test 2"
|
||||
);
|
||||
|
||||
AddMovieHandler::with(
|
||||
key,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::AddMovieSearchResults,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.add_searched_movies
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.title
|
||||
.to_string(),
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_add_movie_search_results_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;
|
||||
let mut add_searched_movies = StatefulTable::default();
|
||||
add_searched_movies.set_items(simple_stateful_iterable_vec!(
|
||||
AddMovieSearchResult,
|
||||
HorizontallyScrollableText
|
||||
));
|
||||
app.data.radarr_data.add_searched_movies = Some(add_searched_movies);
|
||||
|
||||
AddMovieHandler::with(
|
||||
key,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::AddMovieSearchResults,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.add_searched_movies
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.title
|
||||
.to_string(),
|
||||
"Test 1"
|
||||
);
|
||||
|
||||
AddMovieHandler::with(
|
||||
key,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::AddMovieSearchResults,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.add_searched_movies
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.title
|
||||
.to_string(),
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_add_movie_select_monitor_scroll(
|
||||
#[values(DEFAULT_KEYBINDINGS.up.key, DEFAULT_KEYBINDINGS.down.key)] key: Key,
|
||||
@@ -421,117 +309,9 @@ mod tests {
|
||||
|
||||
use crate::extended_stateful_iterable_vec;
|
||||
use crate::models::servarr_data::radarr::modals::AddMovieModal;
|
||||
use crate::models::stateful_table::StatefulTable;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_add_movie_search_results_home_end() {
|
||||
let mut app = App::default();
|
||||
let mut add_searched_movies = StatefulTable::default();
|
||||
add_searched_movies.set_items(extended_stateful_iterable_vec!(
|
||||
AddMovieSearchResult,
|
||||
HorizontallyScrollableText
|
||||
));
|
||||
app.data.radarr_data.add_searched_movies = Some(add_searched_movies);
|
||||
|
||||
AddMovieHandler::with(
|
||||
DEFAULT_KEYBINDINGS.end.key,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::AddMovieSearchResults,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.add_searched_movies
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.title
|
||||
.to_string(),
|
||||
"Test 3"
|
||||
);
|
||||
|
||||
AddMovieHandler::with(
|
||||
DEFAULT_KEYBINDINGS.home.key,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::AddMovieSearchResults,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.add_searched_movies
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.title
|
||||
.to_string(),
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_add_movie_search_results_home_end_no_op_when_not_ready() {
|
||||
let mut app = App::default();
|
||||
app.is_loading = true;
|
||||
let mut add_searched_movies = StatefulTable::default();
|
||||
add_searched_movies.set_items(extended_stateful_iterable_vec!(
|
||||
AddMovieSearchResult,
|
||||
HorizontallyScrollableText
|
||||
));
|
||||
app.data.radarr_data.add_searched_movies = Some(add_searched_movies);
|
||||
|
||||
AddMovieHandler::with(
|
||||
DEFAULT_KEYBINDINGS.end.key,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::AddMovieSearchResults,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.add_searched_movies
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.title
|
||||
.to_string(),
|
||||
"Test 1"
|
||||
);
|
||||
|
||||
AddMovieHandler::with(
|
||||
DEFAULT_KEYBINDINGS.home.key,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::AddMovieSearchResults,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.add_searched_movies
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.title
|
||||
.to_string(),
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_add_movie_select_monitor_home_end() {
|
||||
let monitor_vec = Vec::from_iter(MovieMonitor::iter());
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -9,13 +9,13 @@ use crate::handlers::radarr_handlers::library::movie_details_handler::MovieDetai
|
||||
use crate::handlers::{handle_clear_errors, handle_prompt_toggle, KeyEventHandler};
|
||||
|
||||
use crate::handle_table_events;
|
||||
use crate::handlers::table_handler::TableHandlingProps;
|
||||
use crate::handlers::table_handler::TableHandlingConfig;
|
||||
use crate::models::radarr_models::Movie;
|
||||
use crate::models::servarr_data::radarr::radarr_data::{
|
||||
ActiveRadarrBlock, DELETE_MOVIE_SELECTION_BLOCKS, EDIT_MOVIE_SELECTION_BLOCKS, LIBRARY_BLOCKS,
|
||||
};
|
||||
use crate::models::stateful_table::SortOption;
|
||||
use crate::models::{BlockSelectionState, HorizontallyScrollableText, Scrollable};
|
||||
use crate::models::{BlockSelectionState, HorizontallyScrollableText};
|
||||
use crate::network::radarr_network::RadarrEvent;
|
||||
|
||||
mod add_movie_handler;
|
||||
@@ -40,7 +40,7 @@ impl<'a, 'b> LibraryHandler<'a, 'b> {
|
||||
|
||||
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for LibraryHandler<'a, 'b> {
|
||||
fn handle(&mut self) {
|
||||
let movie_table_handling_props = TableHandlingProps::new(ActiveRadarrBlock::Movies.into())
|
||||
let movie_table_handling_config = TableHandlingConfig::new(ActiveRadarrBlock::Movies.into())
|
||||
.sorting_block(ActiveRadarrBlock::MoviesSortPrompt.into())
|
||||
.sort_by_fn(|a: &Movie, b: &Movie| a.id.cmp(&b.id))
|
||||
.sort_options(movies_sorting_options())
|
||||
@@ -51,7 +51,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for LibraryHandler<'a, '
|
||||
.filter_error_block(ActiveRadarrBlock::FilterMoviesError.into())
|
||||
.filter_field_fn(|movie| &movie.title.text);
|
||||
|
||||
if !self.handle_movies_table_events(movie_table_handling_props) {
|
||||
if !self.handle_movies_table_events(movie_table_handling_config) {
|
||||
match self.active_radarr_block {
|
||||
_ if AddMovieHandler::accepts(self.active_radarr_block) => {
|
||||
AddMovieHandler::with(self.key, self.app, self.active_radarr_block, self.context)
|
||||
|
||||
@@ -4,7 +4,7 @@ use crate::app::key_binding::DEFAULT_KEYBINDINGS;
|
||||
use crate::app::App;
|
||||
use crate::event::Key;
|
||||
use crate::handle_table_events;
|
||||
use crate::handlers::table_handler::TableHandlingProps;
|
||||
use crate::handlers::table_handler::TableHandlingConfig;
|
||||
use crate::handlers::{handle_prompt_toggle, KeyEventHandler};
|
||||
use crate::models::radarr_models::{Credit, MovieHistoryItem, RadarrRelease};
|
||||
use crate::models::servarr_data::radarr::radarr_data::{
|
||||
@@ -83,19 +83,19 @@ impl<'a, 'b> MovieDetailsHandler<'a, 'b> {
|
||||
|
||||
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for MovieDetailsHandler<'a, 'b> {
|
||||
fn handle(&mut self) {
|
||||
let movie_history_table_handling_props =
|
||||
TableHandlingProps::new(ActiveRadarrBlock::MovieHistory.into());
|
||||
let movie_releases_table_handling_props =
|
||||
TableHandlingProps::new(ActiveRadarrBlock::ManualSearch.into())
|
||||
let movie_history_table_handling_config =
|
||||
TableHandlingConfig::new(ActiveRadarrBlock::MovieHistory.into());
|
||||
let movie_releases_table_handling_config =
|
||||
TableHandlingConfig::new(ActiveRadarrBlock::ManualSearch.into())
|
||||
.sorting_block(ActiveRadarrBlock::ManualSearchSortPrompt.into())
|
||||
.sort_options(releases_sorting_options());
|
||||
let movie_cast_table_handling_props = TableHandlingProps::new(ActiveRadarrBlock::Cast.into());
|
||||
let movie_crew_table_handling_props = TableHandlingProps::new(ActiveRadarrBlock::Crew.into());
|
||||
let movie_cast_table_handling_config = TableHandlingConfig::new(ActiveRadarrBlock::Cast.into());
|
||||
let movie_crew_table_handling_config = TableHandlingConfig::new(ActiveRadarrBlock::Crew.into());
|
||||
|
||||
if !self.handle_movie_history_table_events(movie_history_table_handling_props)
|
||||
&& !self.handle_movie_releases_table_events(movie_releases_table_handling_props)
|
||||
&& !self.handle_movie_cast_table_events(movie_cast_table_handling_props)
|
||||
&& !self.handle_movie_crew_table_events(movie_crew_table_handling_props)
|
||||
if !self.handle_movie_history_table_events(movie_history_table_handling_config)
|
||||
&& !self.handle_movie_releases_table_events(movie_releases_table_handling_config)
|
||||
&& !self.handle_movie_cast_table_events(movie_cast_table_handling_config)
|
||||
&& !self.handle_movie_crew_table_events(movie_crew_table_handling_config)
|
||||
{
|
||||
self.handle_key_event();
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,11 +2,11 @@ use crate::app::key_binding::DEFAULT_KEYBINDINGS;
|
||||
use crate::app::App;
|
||||
use crate::event::Key;
|
||||
use crate::handlers::radarr_handlers::handle_change_tab_left_right_keys;
|
||||
use crate::handlers::table_handler::TableHandlingProps;
|
||||
use crate::handlers::table_handler::TableHandlingConfig;
|
||||
use crate::handlers::{handle_clear_errors, handle_prompt_toggle, KeyEventHandler};
|
||||
use crate::models::servarr_data::radarr::radarr_data::{ActiveRadarrBlock, ROOT_FOLDERS_BLOCKS};
|
||||
use crate::models::servarr_models::RootFolder;
|
||||
use crate::models::{HorizontallyScrollableText, Scrollable};
|
||||
use crate::models::HorizontallyScrollableText;
|
||||
use crate::network::radarr_network::RadarrEvent;
|
||||
use crate::{handle_table_events, handle_text_box_keys, handle_text_box_left_right_keys};
|
||||
|
||||
@@ -32,10 +32,10 @@ impl<'a, 'b> RootFoldersHandler<'a, 'b> {
|
||||
|
||||
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for RootFoldersHandler<'a, 'b> {
|
||||
fn handle(&mut self) {
|
||||
let root_folder_table_handling_props =
|
||||
TableHandlingProps::new(ActiveRadarrBlock::RootFolders.into());
|
||||
let root_folder_table_handling_config =
|
||||
TableHandlingConfig::new(ActiveRadarrBlock::RootFolders.into());
|
||||
|
||||
if !self.handle_root_folders_table_events(root_folder_table_handling_props) {
|
||||
if !self.handle_root_folders_table_events(root_folder_table_handling_config) {
|
||||
self.handle_key_event();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use pretty_assertions::assert_str_eq;
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
use crate::app::key_binding::DEFAULT_KEYBINDINGS;
|
||||
@@ -12,110 +11,12 @@ mod tests {
|
||||
use crate::models::servarr_models::RootFolder;
|
||||
use crate::models::HorizontallyScrollableText;
|
||||
|
||||
mod test_handle_scroll_up_and_down {
|
||||
use rstest::rstest;
|
||||
|
||||
use crate::models::servarr_models::RootFolder;
|
||||
use crate::{simple_stateful_iterable_vec, test_iterable_scroll};
|
||||
|
||||
use super::*;
|
||||
|
||||
test_iterable_scroll!(
|
||||
test_root_folders_scroll,
|
||||
RootFoldersHandler,
|
||||
radarr_data,
|
||||
root_folders,
|
||||
simple_stateful_iterable_vec!(RootFolder, String, path),
|
||||
ActiveRadarrBlock::RootFolders,
|
||||
None,
|
||||
path
|
||||
);
|
||||
|
||||
#[rstest]
|
||||
fn test_root_folders_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
|
||||
.root_folders
|
||||
.set_items(simple_stateful_iterable_vec!(RootFolder, String, path));
|
||||
|
||||
RootFoldersHandler::with(key, &mut app, ActiveRadarrBlock::RootFolders, None).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app.data.radarr_data.root_folders.current_selection().path,
|
||||
"Test 1"
|
||||
);
|
||||
|
||||
RootFoldersHandler::with(key, &mut app, ActiveRadarrBlock::RootFolders, None).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app.data.radarr_data.root_folders.current_selection().path,
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_home_end {
|
||||
use pretty_assertions::assert_eq;
|
||||
use std::sync::atomic::Ordering;
|
||||
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
use crate::models::servarr_models::RootFolder;
|
||||
use crate::{extended_stateful_iterable_vec, test_iterable_home_and_end};
|
||||
|
||||
use super::*;
|
||||
|
||||
test_iterable_home_and_end!(
|
||||
test_root_folders_home_end,
|
||||
RootFoldersHandler,
|
||||
radarr_data,
|
||||
root_folders,
|
||||
extended_stateful_iterable_vec!(RootFolder, String, path),
|
||||
ActiveRadarrBlock::RootFolders,
|
||||
None,
|
||||
path
|
||||
);
|
||||
|
||||
#[test]
|
||||
fn test_root_folders_home_end_no_op_when_not_ready() {
|
||||
let mut app = App::default();
|
||||
app.is_loading = true;
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.root_folders
|
||||
.set_items(extended_stateful_iterable_vec!(RootFolder, String, path));
|
||||
|
||||
RootFoldersHandler::with(
|
||||
DEFAULT_KEYBINDINGS.end.key,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::RootFolders,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app.data.radarr_data.root_folders.current_selection().path,
|
||||
"Test 1"
|
||||
);
|
||||
|
||||
RootFoldersHandler::with(
|
||||
DEFAULT_KEYBINDINGS.home.key,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::RootFolders,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app.data.radarr_data.root_folders.current_selection().path,
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
use crate::models::servarr_models::RootFolder;
|
||||
|
||||
#[test]
|
||||
fn test_add_root_folder_prompt_home_end_keys() {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use pretty_assertions::assert_eq;
|
||||
use rstest::rstest;
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
|
||||
@@ -14,242 +14,6 @@ mod tests {
|
||||
use crate::models::servarr_data::sonarr::sonarr_data::{ActiveSonarrBlock, BLOCKLIST_BLOCKS};
|
||||
use crate::models::servarr_models::{Language, Quality, QualityWrapper};
|
||||
use crate::models::sonarr_models::BlocklistItem;
|
||||
use crate::models::stateful_table::SortOption;
|
||||
|
||||
mod test_handle_scroll_up_and_down {
|
||||
use pretty_assertions::{assert_eq, assert_str_eq};
|
||||
use rstest::rstest;
|
||||
|
||||
use crate::models::sonarr_models::BlocklistItem;
|
||||
use crate::{simple_stateful_iterable_vec, test_iterable_scroll};
|
||||
|
||||
use super::*;
|
||||
|
||||
test_iterable_scroll!(
|
||||
test_blocklist_scroll,
|
||||
BlocklistHandler,
|
||||
sonarr_data,
|
||||
blocklist,
|
||||
simple_stateful_iterable_vec!(BlocklistItem, String, source_title),
|
||||
ActiveSonarrBlock::Blocklist,
|
||||
None,
|
||||
source_title,
|
||||
to_string
|
||||
);
|
||||
|
||||
#[rstest]
|
||||
fn test_blocklist_scroll_no_op_when_not_ready(
|
||||
#[values(DEFAULT_KEYBINDINGS.up.key, DEFAULT_KEYBINDINGS.down.key)] key: Key,
|
||||
) {
|
||||
let mut app = App::default();
|
||||
app.push_navigation_stack(ActiveSonarrBlock::Blocklist.into());
|
||||
app.is_loading = true;
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.blocklist
|
||||
.set_items(simple_stateful_iterable_vec!(
|
||||
BlocklistItem,
|
||||
String,
|
||||
source_title
|
||||
));
|
||||
|
||||
BlocklistHandler::with(key, &mut app, ActiveSonarrBlock::Blocklist, None).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.blocklist
|
||||
.current_selection()
|
||||
.source_title
|
||||
.to_string(),
|
||||
"Test 1"
|
||||
);
|
||||
|
||||
BlocklistHandler::with(key, &mut app, ActiveSonarrBlock::Blocklist, None).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.blocklist
|
||||
.current_selection()
|
||||
.source_title
|
||||
.to_string(),
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_blocklist_sort_scroll(
|
||||
#[values(DEFAULT_KEYBINDINGS.up.key, DEFAULT_KEYBINDINGS.down.key)] key: Key,
|
||||
) {
|
||||
let blocklist_field_vec = sort_options();
|
||||
let mut app = App::default();
|
||||
app.push_navigation_stack(ActiveSonarrBlock::Blocklist.into());
|
||||
app.data.sonarr_data.blocklist.sorting(sort_options());
|
||||
|
||||
if key == Key::Up {
|
||||
for i in (0..blocklist_field_vec.len()).rev() {
|
||||
BlocklistHandler::with(key, &mut app, ActiveSonarrBlock::BlocklistSortPrompt, None)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.blocklist
|
||||
.sort
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection(),
|
||||
&blocklist_field_vec[i]
|
||||
);
|
||||
}
|
||||
} else {
|
||||
for i in 0..blocklist_field_vec.len() {
|
||||
BlocklistHandler::with(key, &mut app, ActiveSonarrBlock::BlocklistSortPrompt, None)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.blocklist
|
||||
.sort
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection(),
|
||||
&blocklist_field_vec[(i + 1) % blocklist_field_vec.len()]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_home_end {
|
||||
use pretty_assertions::{assert_eq, assert_str_eq};
|
||||
|
||||
use crate::models::sonarr_models::BlocklistItem;
|
||||
use crate::{extended_stateful_iterable_vec, test_iterable_home_and_end};
|
||||
|
||||
use super::*;
|
||||
|
||||
test_iterable_home_and_end!(
|
||||
test_blocklist_home_and_end,
|
||||
BlocklistHandler,
|
||||
sonarr_data,
|
||||
blocklist,
|
||||
extended_stateful_iterable_vec!(BlocklistItem, String, source_title),
|
||||
ActiveSonarrBlock::Blocklist,
|
||||
None,
|
||||
source_title,
|
||||
to_string
|
||||
);
|
||||
|
||||
#[test]
|
||||
fn test_blocklist_home_and_end_no_op_when_not_ready() {
|
||||
let mut app = App::default();
|
||||
app.push_navigation_stack(ActiveSonarrBlock::Blocklist.into());
|
||||
app.is_loading = true;
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.blocklist
|
||||
.set_items(extended_stateful_iterable_vec!(
|
||||
BlocklistItem,
|
||||
String,
|
||||
source_title
|
||||
));
|
||||
|
||||
BlocklistHandler::with(
|
||||
DEFAULT_KEYBINDINGS.end.key,
|
||||
&mut app,
|
||||
ActiveSonarrBlock::Blocklist,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.blocklist
|
||||
.current_selection()
|
||||
.source_title
|
||||
.to_string(),
|
||||
"Test 1"
|
||||
);
|
||||
|
||||
BlocklistHandler::with(
|
||||
DEFAULT_KEYBINDINGS.home.key,
|
||||
&mut app,
|
||||
ActiveSonarrBlock::Blocklist,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.blocklist
|
||||
.current_selection()
|
||||
.source_title
|
||||
.to_string(),
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_blocklist_sort_home_end() {
|
||||
let blocklist_field_vec = sort_options();
|
||||
let mut app = App::default();
|
||||
app.push_navigation_stack(ActiveSonarrBlock::Blocklist.into());
|
||||
app.data.sonarr_data.blocklist.sorting(sort_options());
|
||||
|
||||
BlocklistHandler::with(
|
||||
DEFAULT_KEYBINDINGS.end.key,
|
||||
&mut app,
|
||||
ActiveSonarrBlock::BlocklistSortPrompt,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.blocklist
|
||||
.sort
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection(),
|
||||
&blocklist_field_vec[blocklist_field_vec.len() - 1]
|
||||
);
|
||||
|
||||
BlocklistHandler::with(
|
||||
DEFAULT_KEYBINDINGS.home.key,
|
||||
&mut app,
|
||||
ActiveSonarrBlock::BlocklistSortPrompt,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.blocklist
|
||||
.sort
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection(),
|
||||
&blocklist_field_vec[0]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_delete {
|
||||
use pretty_assertions::assert_eq;
|
||||
@@ -444,31 +208,6 @@ mod tests {
|
||||
assert_eq!(app.data.sonarr_data.prompt_confirm_action, None);
|
||||
assert_eq!(app.get_current_route(), ActiveSonarrBlock::Blocklist.into());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_blocklist_sort_prompt_submit() {
|
||||
let mut app = App::default();
|
||||
app.data.sonarr_data.blocklist.sort_asc = true;
|
||||
app.data.sonarr_data.blocklist.sorting(sort_options());
|
||||
app.data.sonarr_data.blocklist.set_items(blocklist_vec());
|
||||
app.push_navigation_stack(ActiveSonarrBlock::Blocklist.into());
|
||||
app.push_navigation_stack(ActiveSonarrBlock::BlocklistSortPrompt.into());
|
||||
|
||||
let mut expected_vec = blocklist_vec();
|
||||
expected_vec.sort_by(|a, b| a.id.cmp(&b.id));
|
||||
expected_vec.reverse();
|
||||
|
||||
BlocklistHandler::with(
|
||||
SUBMIT_KEY,
|
||||
&mut app,
|
||||
ActiveSonarrBlock::BlocklistSortPrompt,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(app.get_current_route(), ActiveSonarrBlock::Blocklist.into());
|
||||
assert_eq!(app.data.sonarr_data.blocklist.items, expected_vec);
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_esc {
|
||||
@@ -520,23 +259,6 @@ mod tests {
|
||||
assert_eq!(app.get_current_route(), ActiveSonarrBlock::Blocklist.into());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_blocklist_sort_prompt_block_esc() {
|
||||
let mut app = App::default();
|
||||
app.push_navigation_stack(ActiveSonarrBlock::Blocklist.into());
|
||||
app.push_navigation_stack(ActiveSonarrBlock::BlocklistSortPrompt.into());
|
||||
|
||||
BlocklistHandler::with(
|
||||
ESC_KEY,
|
||||
&mut app,
|
||||
ActiveSonarrBlock::BlocklistSortPrompt,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(app.get_current_route(), ActiveSonarrBlock::Blocklist.into());
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_default_esc(#[values(true, false)] is_ready: bool) {
|
||||
let mut app = App::default();
|
||||
@@ -635,51 +357,6 @@ mod tests {
|
||||
assert_eq!(app.get_current_route(), ActiveSonarrBlock::Blocklist.into());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sort_key() {
|
||||
let mut app = App::default();
|
||||
app.push_navigation_stack(ActiveSonarrBlock::Blocklist.into());
|
||||
app.data.sonarr_data.blocklist.set_items(blocklist_vec());
|
||||
|
||||
BlocklistHandler::with(
|
||||
DEFAULT_KEYBINDINGS.sort.key,
|
||||
&mut app,
|
||||
ActiveSonarrBlock::Blocklist,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
ActiveSonarrBlock::BlocklistSortPrompt.into()
|
||||
);
|
||||
assert_eq!(
|
||||
app.data.sonarr_data.blocklist.sort.as_ref().unwrap().items,
|
||||
blocklist_sorting_options()
|
||||
);
|
||||
assert!(!app.data.sonarr_data.blocklist.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(ActiveSonarrBlock::Blocklist.into());
|
||||
app.data.sonarr_data.blocklist.set_items(blocklist_vec());
|
||||
|
||||
BlocklistHandler::with(
|
||||
DEFAULT_KEYBINDINGS.sort.key,
|
||||
&mut app,
|
||||
ActiveSonarrBlock::Blocklist,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(app.get_current_route(), ActiveSonarrBlock::Blocklist.into());
|
||||
assert!(app.data.sonarr_data.blocklist.sort.is_none());
|
||||
assert!(!app.data.sonarr_data.blocklist.sort_asc);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
#[case(
|
||||
ActiveSonarrBlock::Blocklist,
|
||||
@@ -931,15 +608,4 @@ mod tests {
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
fn sort_options() -> Vec<SortOption<BlocklistItem>> {
|
||||
vec![SortOption {
|
||||
name: "Test 1",
|
||||
cmp_fn: Some(|a, b| {
|
||||
b.source_title
|
||||
.to_lowercase()
|
||||
.cmp(&a.source_title.to_lowercase())
|
||||
}),
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,11 @@ use crate::app::App;
|
||||
use crate::event::Key;
|
||||
use crate::handle_table_events;
|
||||
use crate::handlers::sonarr_handlers::handle_change_tab_left_right_keys;
|
||||
use crate::handlers::table_handler::TableHandlingProps;
|
||||
use crate::handlers::table_handler::TableHandlingConfig;
|
||||
use crate::handlers::{handle_clear_errors, handle_prompt_toggle, KeyEventHandler};
|
||||
use crate::models::servarr_data::sonarr::sonarr_data::{ActiveSonarrBlock, BLOCKLIST_BLOCKS};
|
||||
use crate::models::sonarr_models::BlocklistItem;
|
||||
use crate::models::stateful_table::SortOption;
|
||||
use crate::models::Scrollable;
|
||||
use crate::network::sonarr_network::SonarrEvent;
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -33,13 +32,13 @@ impl<'a, 'b> BlocklistHandler<'a, 'b> {
|
||||
|
||||
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for BlocklistHandler<'a, 'b> {
|
||||
fn handle(&mut self) {
|
||||
let blocklist_table_handling_props =
|
||||
TableHandlingProps::new(ActiveSonarrBlock::Blocklist.into())
|
||||
let blocklist_table_handling_config =
|
||||
TableHandlingConfig::new(ActiveSonarrBlock::Blocklist.into())
|
||||
.sorting_block(ActiveSonarrBlock::BlocklistSortPrompt.into())
|
||||
.sort_by_fn(|a: &BlocklistItem, b: &BlocklistItem| a.id.cmp(&b.id))
|
||||
.sort_options(blocklist_sorting_options());
|
||||
|
||||
if !self.handle_blocklist_table_events(blocklist_table_handling_props) {
|
||||
if !self.handle_blocklist_table_events(blocklist_table_handling_config) {
|
||||
self.handle_key_event();
|
||||
}
|
||||
}
|
||||
@@ -70,69 +69,13 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for BlocklistHandler<'a,
|
||||
!self.app.is_loading && !self.app.data.sonarr_data.blocklist.is_empty()
|
||||
}
|
||||
|
||||
fn handle_scroll_up(&mut self) {
|
||||
match self.active_sonarr_block {
|
||||
ActiveSonarrBlock::Blocklist => self.app.data.sonarr_data.blocklist.scroll_up(),
|
||||
ActiveSonarrBlock::BlocklistSortPrompt => self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.blocklist
|
||||
.sort
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.scroll_up(),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
fn handle_scroll_up(&mut self) {}
|
||||
|
||||
fn handle_scroll_down(&mut self) {
|
||||
match self.active_sonarr_block {
|
||||
ActiveSonarrBlock::Blocklist => self.app.data.sonarr_data.blocklist.scroll_down(),
|
||||
ActiveSonarrBlock::BlocklistSortPrompt => self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.blocklist
|
||||
.sort
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.scroll_down(),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
fn handle_scroll_down(&mut self) {}
|
||||
|
||||
fn handle_home(&mut self) {
|
||||
match self.active_sonarr_block {
|
||||
ActiveSonarrBlock::Blocklist => self.app.data.sonarr_data.blocklist.scroll_to_top(),
|
||||
ActiveSonarrBlock::BlocklistSortPrompt => self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.blocklist
|
||||
.sort
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.scroll_to_top(),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
fn handle_home(&mut self) {}
|
||||
|
||||
fn handle_end(&mut self) {
|
||||
match self.active_sonarr_block {
|
||||
ActiveSonarrBlock::Blocklist => self.app.data.sonarr_data.blocklist.scroll_to_bottom(),
|
||||
ActiveSonarrBlock::BlocklistSortPrompt => self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.blocklist
|
||||
.sort
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.scroll_to_bottom(),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
fn handle_end(&mut self) {}
|
||||
|
||||
fn handle_delete(&mut self) {
|
||||
if self.active_sonarr_block == ActiveSonarrBlock::Blocklist {
|
||||
@@ -168,18 +111,6 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for BlocklistHandler<'a,
|
||||
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
ActiveSonarrBlock::BlocklistSortPrompt => {
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.blocklist
|
||||
.items
|
||||
.sort_by(|a, b| a.id.cmp(&b.id));
|
||||
self.app.data.sonarr_data.blocklist.apply_sorting();
|
||||
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
ActiveSonarrBlock::Blocklist => {
|
||||
self
|
||||
.app
|
||||
@@ -215,17 +146,6 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for BlocklistHandler<'a,
|
||||
.app
|
||||
.push_navigation_stack(ActiveSonarrBlock::BlocklistClearAllItemsPrompt.into());
|
||||
}
|
||||
_ if key == DEFAULT_KEYBINDINGS.sort.key => {
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.blocklist
|
||||
.sorting(blocklist_sorting_options());
|
||||
self
|
||||
.app
|
||||
.push_navigation_stack(ActiveSonarrBlock::BlocklistSortPrompt.into());
|
||||
}
|
||||
_ => (),
|
||||
},
|
||||
ActiveSonarrBlock::DeleteBlocklistItemPrompt => {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use pretty_assertions::assert_str_eq;
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
use crate::app::key_binding::DEFAULT_KEYBINDINGS;
|
||||
@@ -11,113 +10,6 @@ mod tests {
|
||||
use crate::models::servarr_data::sonarr::sonarr_data::{ActiveSonarrBlock, DOWNLOADS_BLOCKS};
|
||||
use crate::models::sonarr_models::DownloadRecord;
|
||||
|
||||
mod test_handle_scroll_up_and_down {
|
||||
use rstest::rstest;
|
||||
|
||||
use crate::models::sonarr_models::DownloadRecord;
|
||||
use crate::{simple_stateful_iterable_vec, test_iterable_scroll};
|
||||
|
||||
use super::*;
|
||||
|
||||
test_iterable_scroll!(
|
||||
test_downloads_scroll,
|
||||
DownloadsHandler,
|
||||
sonarr_data,
|
||||
downloads,
|
||||
DownloadRecord,
|
||||
ActiveSonarrBlock::Downloads,
|
||||
None,
|
||||
title
|
||||
);
|
||||
|
||||
#[rstest]
|
||||
fn test_downloads_scroll_no_op_when_not_ready(
|
||||
#[values(
|
||||
DEFAULT_KEYBINDINGS.up.key, DEFAULT_KEYBINDINGS.down.key
|
||||
)]
|
||||
key: Key,
|
||||
) {
|
||||
let mut app = App::default();
|
||||
app.push_navigation_stack(ActiveSonarrBlock::Downloads.into());
|
||||
app.is_loading = true;
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.downloads
|
||||
.set_items(simple_stateful_iterable_vec!(DownloadRecord));
|
||||
|
||||
DownloadsHandler::with(key, &mut app, ActiveSonarrBlock::Downloads, None).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app.data.sonarr_data.downloads.current_selection().title,
|
||||
"Test 1"
|
||||
);
|
||||
|
||||
DownloadsHandler::with(key, &mut app, ActiveSonarrBlock::Downloads, None).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app.data.sonarr_data.downloads.current_selection().title,
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_home_end {
|
||||
use crate::models::sonarr_models::DownloadRecord;
|
||||
use crate::{extended_stateful_iterable_vec, test_iterable_home_and_end};
|
||||
|
||||
use super::*;
|
||||
|
||||
test_iterable_home_and_end!(
|
||||
test_downloads_home_end,
|
||||
DownloadsHandler,
|
||||
sonarr_data,
|
||||
downloads,
|
||||
DownloadRecord,
|
||||
ActiveSonarrBlock::Downloads,
|
||||
None,
|
||||
title
|
||||
);
|
||||
|
||||
#[test]
|
||||
fn test_downloads_home_end_no_op_when_not_ready() {
|
||||
let mut app = App::default();
|
||||
app.push_navigation_stack(ActiveSonarrBlock::Downloads.into());
|
||||
app.is_loading = true;
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.downloads
|
||||
.set_items(extended_stateful_iterable_vec!(DownloadRecord));
|
||||
|
||||
DownloadsHandler::with(
|
||||
DEFAULT_KEYBINDINGS.end.key,
|
||||
&mut app,
|
||||
ActiveSonarrBlock::Downloads,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app.data.sonarr_data.downloads.current_selection().title,
|
||||
"Test 1"
|
||||
);
|
||||
|
||||
DownloadsHandler::with(
|
||||
DEFAULT_KEYBINDINGS.home.key,
|
||||
&mut app,
|
||||
ActiveSonarrBlock::Downloads,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app.data.sonarr_data.downloads.current_selection().title,
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_delete {
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
|
||||
@@ -3,11 +3,10 @@ use crate::app::App;
|
||||
use crate::event::Key;
|
||||
use crate::handle_table_events;
|
||||
use crate::handlers::sonarr_handlers::handle_change_tab_left_right_keys;
|
||||
use crate::handlers::table_handler::TableHandlingProps;
|
||||
use crate::handlers::table_handler::TableHandlingConfig;
|
||||
use crate::handlers::{handle_clear_errors, handle_prompt_toggle, KeyEventHandler};
|
||||
use crate::models::servarr_data::sonarr::sonarr_data::{ActiveSonarrBlock, DOWNLOADS_BLOCKS};
|
||||
use crate::models::sonarr_models::DownloadRecord;
|
||||
use crate::models::Scrollable;
|
||||
use crate::network::sonarr_network::SonarrEvent;
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -32,10 +31,10 @@ impl<'a, 'b> DownloadsHandler<'a, 'b> {
|
||||
|
||||
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for DownloadsHandler<'a, 'b> {
|
||||
fn handle(&mut self) {
|
||||
let download_table_handling_props =
|
||||
TableHandlingProps::new(ActiveSonarrBlock::Downloads.into());
|
||||
let download_table_handling_config =
|
||||
TableHandlingConfig::new(ActiveSonarrBlock::Downloads.into());
|
||||
|
||||
if !self.handle_downloads_table_events(download_table_handling_props) {
|
||||
if !self.handle_downloads_table_events(download_table_handling_config) {
|
||||
self.handle_key_event();
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -3,12 +3,11 @@ use crate::app::App;
|
||||
use crate::event::Key;
|
||||
use crate::handle_table_events;
|
||||
use crate::handlers::sonarr_handlers::handle_change_tab_left_right_keys;
|
||||
use crate::handlers::table_handler::TableHandlingProps;
|
||||
use crate::handlers::table_handler::TableHandlingConfig;
|
||||
use crate::handlers::{handle_clear_errors, KeyEventHandler};
|
||||
use crate::models::servarr_data::sonarr::sonarr_data::{ActiveSonarrBlock, HISTORY_BLOCKS};
|
||||
use crate::models::sonarr_models::SonarrHistoryItem;
|
||||
use crate::models::stateful_table::SortOption;
|
||||
use crate::models::Scrollable;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "history_handler_tests.rs"]
|
||||
@@ -32,7 +31,7 @@ impl<'a, 'b> HistoryHandler<'a, 'b> {
|
||||
|
||||
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for HistoryHandler<'a, 'b> {
|
||||
fn handle(&mut self) {
|
||||
let history_table_handling_props = TableHandlingProps::new(ActiveSonarrBlock::History.into())
|
||||
let history_table_handling_config = TableHandlingConfig::new(ActiveSonarrBlock::History.into())
|
||||
.sorting_block(ActiveSonarrBlock::HistorySortPrompt.into())
|
||||
.sort_by_fn(|a: &SonarrHistoryItem, b: &SonarrHistoryItem| a.id.cmp(&b.id))
|
||||
.sort_options(history_sorting_options())
|
||||
@@ -43,7 +42,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for HistoryHandler<'a, '
|
||||
.filter_error_block(ActiveSonarrBlock::FilterHistoryError.into())
|
||||
.filter_field_fn(|history| &history.source_title.text);
|
||||
|
||||
if !self.handle_history_table_events(history_table_handling_props) {
|
||||
if !self.handle_history_table_events(history_table_handling_config) {
|
||||
self.handle_key_event();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use pretty_assertions::{assert_eq, assert_str_eq};
|
||||
use rstest::rstest;
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
@@ -15,111 +14,6 @@ mod tests {
|
||||
use crate::models::servarr_models::Indexer;
|
||||
use crate::test_handler_delegation;
|
||||
|
||||
mod test_handle_scroll_up_and_down {
|
||||
use rstest::rstest;
|
||||
|
||||
use crate::{simple_stateful_iterable_vec, test_iterable_scroll};
|
||||
|
||||
use super::*;
|
||||
|
||||
test_iterable_scroll!(
|
||||
test_indexers_scroll,
|
||||
IndexersHandler,
|
||||
sonarr_data,
|
||||
indexers,
|
||||
simple_stateful_iterable_vec!(Indexer, String, protocol),
|
||||
ActiveSonarrBlock::Indexers,
|
||||
None,
|
||||
protocol
|
||||
);
|
||||
|
||||
#[rstest]
|
||||
fn test_indexers_scroll_no_op_when_not_ready(
|
||||
#[values(
|
||||
DEFAULT_KEYBINDINGS.up.key, DEFAULT_KEYBINDINGS.down.key
|
||||
)]
|
||||
key: Key,
|
||||
) {
|
||||
let mut app = App::default();
|
||||
app.push_navigation_stack(ActiveSonarrBlock::Indexers.into());
|
||||
app.is_loading = true;
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.indexers
|
||||
.set_items(simple_stateful_iterable_vec!(Indexer, String, protocol));
|
||||
|
||||
IndexersHandler::with(key, &mut app, ActiveSonarrBlock::Indexers, None).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app.data.sonarr_data.indexers.current_selection().protocol,
|
||||
"Test 1"
|
||||
);
|
||||
|
||||
IndexersHandler::with(key, &mut app, ActiveSonarrBlock::Indexers, None).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app.data.sonarr_data.indexers.current_selection().protocol,
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_home_end {
|
||||
use crate::{extended_stateful_iterable_vec, test_iterable_home_and_end};
|
||||
|
||||
use super::*;
|
||||
|
||||
test_iterable_home_and_end!(
|
||||
test_indexers_home_end,
|
||||
IndexersHandler,
|
||||
sonarr_data,
|
||||
indexers,
|
||||
extended_stateful_iterable_vec!(Indexer, String, protocol),
|
||||
ActiveSonarrBlock::Indexers,
|
||||
None,
|
||||
protocol
|
||||
);
|
||||
|
||||
#[test]
|
||||
fn test_indexers_home_end_no_op_when_not_ready() {
|
||||
let mut app = App::default();
|
||||
app.push_navigation_stack(ActiveSonarrBlock::Indexers.into());
|
||||
app.is_loading = true;
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.indexers
|
||||
.set_items(extended_stateful_iterable_vec!(Indexer, String, protocol));
|
||||
|
||||
IndexersHandler::with(
|
||||
DEFAULT_KEYBINDINGS.end.key,
|
||||
&mut app,
|
||||
ActiveSonarrBlock::Indexers,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app.data.sonarr_data.indexers.current_selection().protocol,
|
||||
"Test 1"
|
||||
);
|
||||
|
||||
IndexersHandler::with(
|
||||
DEFAULT_KEYBINDINGS.home.key,
|
||||
&mut app,
|
||||
ActiveSonarrBlock::Indexers,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app.data.sonarr_data.indexers.current_selection().protocol,
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_delete {
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
@@ -515,7 +409,11 @@ mod tests {
|
||||
#[test]
|
||||
fn test_indexer_settings_key() {
|
||||
let mut app = App::default();
|
||||
app.data.sonarr_data.indexers.set_items(vec![Indexer::default()]);
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.indexers
|
||||
.set_items(vec![Indexer::default()]);
|
||||
app.push_navigation_stack(ActiveSonarrBlock::Indexers.into());
|
||||
app
|
||||
.data
|
||||
|
||||
@@ -6,7 +6,7 @@ use crate::handlers::sonarr_handlers::handle_change_tab_left_right_keys;
|
||||
use crate::handlers::sonarr_handlers::indexers::edit_indexer_handler::EditIndexerHandler;
|
||||
use crate::handlers::sonarr_handlers::indexers::edit_indexer_settings_handler::IndexerSettingsHandler;
|
||||
use crate::handlers::sonarr_handlers::indexers::test_all_indexers_handler::TestAllIndexersHandler;
|
||||
use crate::handlers::table_handler::TableHandlingProps;
|
||||
use crate::handlers::table_handler::TableHandlingConfig;
|
||||
use crate::handlers::{handle_clear_errors, handle_prompt_toggle, KeyEventHandler};
|
||||
use crate::models::servarr_data::sonarr::sonarr_data::{
|
||||
ActiveSonarrBlock, EDIT_INDEXER_NZB_SELECTION_BLOCKS, EDIT_INDEXER_TORRENT_SELECTION_BLOCKS,
|
||||
@@ -14,7 +14,6 @@ use crate::models::servarr_data::sonarr::sonarr_data::{
|
||||
};
|
||||
use crate::models::servarr_models::Indexer;
|
||||
use crate::models::BlockSelectionState;
|
||||
use crate::models::Scrollable;
|
||||
use crate::network::sonarr_network::SonarrEvent;
|
||||
|
||||
mod edit_indexer_handler;
|
||||
@@ -38,9 +37,10 @@ impl<'a, 'b> IndexersHandler<'a, 'b> {
|
||||
|
||||
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for IndexersHandler<'a, 'b> {
|
||||
fn handle(&mut self) {
|
||||
let indexers_table_handling_props = TableHandlingProps::new(ActiveSonarrBlock::Indexers.into());
|
||||
let indexers_table_handling_config =
|
||||
TableHandlingConfig::new(ActiveSonarrBlock::Indexers.into());
|
||||
|
||||
if !self.handle_indexers_table_events(indexers_table_handling_props) {
|
||||
if !self.handle_indexers_table_events(indexers_table_handling_config) {
|
||||
match self.active_sonarr_block {
|
||||
_ if EditIndexerHandler::accepts(self.active_sonarr_block) => {
|
||||
EditIndexerHandler::with(self.key, self.app, self.active_sonarr_block, self.context)
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
use crate::app::App;
|
||||
use crate::event::Key;
|
||||
use crate::handle_table_events;
|
||||
use crate::handlers::table_handler::TableHandlingConfig;
|
||||
use crate::handlers::KeyEventHandler;
|
||||
use crate::models::servarr_data::modals::IndexerTestResultModalItem;
|
||||
use crate::models::servarr_data::sonarr::sonarr_data::ActiveSonarrBlock;
|
||||
use crate::models::Scrollable;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "test_all_indexers_handler_tests.rs"]
|
||||
@@ -15,7 +17,33 @@ pub(super) struct TestAllIndexersHandler<'a, 'b> {
|
||||
_context: Option<ActiveSonarrBlock>,
|
||||
}
|
||||
|
||||
impl<'a, 'b> TestAllIndexersHandler<'a, 'b> {
|
||||
handle_table_events!(
|
||||
self,
|
||||
indexer_test_all_results,
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.indexer_test_all_results
|
||||
.as_mut()
|
||||
.unwrap(),
|
||||
IndexerTestResultModalItem
|
||||
);
|
||||
}
|
||||
|
||||
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for TestAllIndexersHandler<'a, 'b> {
|
||||
fn handle(&mut self) {
|
||||
let indexer_test_all_results_table_handling_config =
|
||||
TableHandlingConfig::new(ActiveSonarrBlock::TestAllIndexers.into());
|
||||
|
||||
if !self
|
||||
.handle_indexer_test_all_results_table_events(indexer_test_all_results_table_handling_config)
|
||||
{
|
||||
self.handle_key_event();
|
||||
}
|
||||
}
|
||||
|
||||
fn accepts(active_block: ActiveSonarrBlock) -> bool {
|
||||
active_block == ActiveSonarrBlock::TestAllIndexers
|
||||
}
|
||||
@@ -48,57 +76,13 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for TestAllIndexersHandl
|
||||
!self.app.is_loading && table_is_ready
|
||||
}
|
||||
|
||||
fn handle_scroll_up(&mut self) {
|
||||
if self.active_sonarr_block == ActiveSonarrBlock::TestAllIndexers {
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.indexer_test_all_results
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.scroll_up()
|
||||
}
|
||||
}
|
||||
fn handle_scroll_up(&mut self) {}
|
||||
|
||||
fn handle_scroll_down(&mut self) {
|
||||
if self.active_sonarr_block == ActiveSonarrBlock::TestAllIndexers {
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.indexer_test_all_results
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.scroll_down()
|
||||
}
|
||||
}
|
||||
fn handle_scroll_down(&mut self) {}
|
||||
|
||||
fn handle_home(&mut self) {
|
||||
if self.active_sonarr_block == ActiveSonarrBlock::TestAllIndexers {
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.indexer_test_all_results
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.scroll_to_top()
|
||||
}
|
||||
}
|
||||
fn handle_home(&mut self) {}
|
||||
|
||||
fn handle_end(&mut self) {
|
||||
if self.active_sonarr_block == ActiveSonarrBlock::TestAllIndexers {
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.indexer_test_all_results
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.scroll_to_bottom()
|
||||
}
|
||||
}
|
||||
fn handle_end(&mut self) {}
|
||||
|
||||
fn handle_delete(&mut self) {}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
mod tests {
|
||||
use crate::app::key_binding::DEFAULT_KEYBINDINGS;
|
||||
use crate::app::App;
|
||||
use crate::event::Key;
|
||||
use crate::handlers::sonarr_handlers::indexers::test_all_indexers_handler::TestAllIndexersHandler;
|
||||
use crate::handlers::KeyEventHandler;
|
||||
use crate::models::servarr_data::modals::IndexerTestResultModalItem;
|
||||
@@ -10,224 +9,6 @@ mod tests {
|
||||
use crate::models::stateful_table::StatefulTable;
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
mod test_handle_scroll_up_and_down {
|
||||
use pretty_assertions::assert_str_eq;
|
||||
use rstest::rstest;
|
||||
|
||||
use crate::models::servarr_data::modals::IndexerTestResultModalItem;
|
||||
use crate::models::stateful_table::StatefulTable;
|
||||
use crate::simple_stateful_iterable_vec;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[rstest]
|
||||
fn test_test_all_indexers_results_scroll(
|
||||
#[values(DEFAULT_KEYBINDINGS.up.key, DEFAULT_KEYBINDINGS.down.key)] key: Key,
|
||||
) {
|
||||
let mut app = App::default();
|
||||
app.push_navigation_stack(ActiveSonarrBlock::Indexers.into());
|
||||
let mut indexer_test_results = StatefulTable::default();
|
||||
indexer_test_results.set_items(simple_stateful_iterable_vec!(
|
||||
IndexerTestResultModalItem,
|
||||
String,
|
||||
name
|
||||
));
|
||||
app.data.sonarr_data.indexer_test_all_results = Some(indexer_test_results);
|
||||
|
||||
TestAllIndexersHandler::with(key, &mut app, ActiveSonarrBlock::TestAllIndexers, None)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.indexer_test_all_results
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.name,
|
||||
"Test 2"
|
||||
);
|
||||
|
||||
TestAllIndexersHandler::with(key, &mut app, ActiveSonarrBlock::TestAllIndexers, None)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.indexer_test_all_results
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.name,
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_test_all_indexers_results_scroll_no_op_when_not_ready(
|
||||
#[values(DEFAULT_KEYBINDINGS.up.key, DEFAULT_KEYBINDINGS.down.key)] key: Key,
|
||||
) {
|
||||
let mut app = App::default();
|
||||
app.push_navigation_stack(ActiveSonarrBlock::Indexers.into());
|
||||
app.is_loading = true;
|
||||
let mut indexer_test_results = StatefulTable::default();
|
||||
indexer_test_results.set_items(simple_stateful_iterable_vec!(
|
||||
IndexerTestResultModalItem,
|
||||
String,
|
||||
name
|
||||
));
|
||||
app.data.sonarr_data.indexer_test_all_results = Some(indexer_test_results);
|
||||
|
||||
TestAllIndexersHandler::with(key, &mut app, ActiveSonarrBlock::TestAllIndexers, None)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.indexer_test_all_results
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.name,
|
||||
"Test 1"
|
||||
);
|
||||
|
||||
TestAllIndexersHandler::with(key, &mut app, ActiveSonarrBlock::TestAllIndexers, None)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.indexer_test_all_results
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.name,
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_home_end {
|
||||
use crate::extended_stateful_iterable_vec;
|
||||
use crate::models::servarr_data::modals::IndexerTestResultModalItem;
|
||||
use crate::models::stateful_table::StatefulTable;
|
||||
use pretty_assertions::assert_str_eq;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_test_all_indexers_results_home_end() {
|
||||
let mut app = App::default();
|
||||
app.push_navigation_stack(ActiveSonarrBlock::Indexers.into());
|
||||
let mut indexer_test_results = StatefulTable::default();
|
||||
indexer_test_results.set_items(extended_stateful_iterable_vec!(
|
||||
IndexerTestResultModalItem,
|
||||
String,
|
||||
name
|
||||
));
|
||||
app.data.sonarr_data.indexer_test_all_results = Some(indexer_test_results);
|
||||
|
||||
TestAllIndexersHandler::with(
|
||||
DEFAULT_KEYBINDINGS.end.key,
|
||||
&mut app,
|
||||
ActiveSonarrBlock::TestAllIndexers,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.indexer_test_all_results
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.name,
|
||||
"Test 3"
|
||||
);
|
||||
|
||||
TestAllIndexersHandler::with(
|
||||
DEFAULT_KEYBINDINGS.home.key,
|
||||
&mut app,
|
||||
ActiveSonarrBlock::TestAllIndexers,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.indexer_test_all_results
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.name,
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_test_all_indexers_results_home_end_no_op_when_not_ready() {
|
||||
let mut app = App::default();
|
||||
app.push_navigation_stack(ActiveSonarrBlock::Indexers.into());
|
||||
app.is_loading = true;
|
||||
let mut indexer_test_results = StatefulTable::default();
|
||||
indexer_test_results.set_items(extended_stateful_iterable_vec!(
|
||||
IndexerTestResultModalItem,
|
||||
String,
|
||||
name
|
||||
));
|
||||
app.data.sonarr_data.indexer_test_all_results = Some(indexer_test_results);
|
||||
|
||||
TestAllIndexersHandler::with(
|
||||
DEFAULT_KEYBINDINGS.end.key,
|
||||
&mut app,
|
||||
ActiveSonarrBlock::TestAllIndexers,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.indexer_test_all_results
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.name,
|
||||
"Test 1"
|
||||
);
|
||||
|
||||
TestAllIndexersHandler::with(
|
||||
DEFAULT_KEYBINDINGS.home.key,
|
||||
&mut app,
|
||||
ActiveSonarrBlock::TestAllIndexers,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.indexer_test_all_results
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.name,
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_esc {
|
||||
use super::*;
|
||||
use crate::models::stateful_table::StatefulTable;
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
use crate::app::key_binding::DEFAULT_KEYBINDINGS;
|
||||
use crate::handlers::table_handler::TableHandlingConfig;
|
||||
use crate::handlers::{handle_prompt_toggle, KeyEventHandler};
|
||||
use crate::models::servarr_data::sonarr::sonarr_data::{
|
||||
ActiveSonarrBlock, ADD_SERIES_BLOCKS, ADD_SERIES_SELECTION_BLOCKS,
|
||||
};
|
||||
use crate::models::sonarr_models::AddSeriesSearchResult;
|
||||
use crate::models::{BlockSelectionState, Scrollable};
|
||||
use crate::network::sonarr_network::SonarrEvent;
|
||||
use crate::{handle_text_box_keys, handle_text_box_left_right_keys, App, Key};
|
||||
use crate::{handle_table_events, handle_text_box_keys, handle_text_box_left_right_keys, App, Key};
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "add_series_handler_tests.rs"]
|
||||
@@ -18,7 +20,31 @@ pub(super) struct AddSeriesHandler<'a, 'b> {
|
||||
_context: Option<ActiveSonarrBlock>,
|
||||
}
|
||||
|
||||
impl<'a, 'b> AddSeriesHandler<'a, 'b> {
|
||||
handle_table_events!(
|
||||
self,
|
||||
add_searched_series,
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.add_searched_series
|
||||
.as_mut()
|
||||
.unwrap(),
|
||||
AddSeriesSearchResult
|
||||
);
|
||||
}
|
||||
|
||||
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for AddSeriesHandler<'a, 'b> {
|
||||
fn handle(&mut self) {
|
||||
let add_series_table_handling_config =
|
||||
TableHandlingConfig::new(ActiveSonarrBlock::AddSeriesSearchResults.into());
|
||||
|
||||
if !self.handle_add_searched_series_table_events(add_series_table_handling_config) {
|
||||
self.handle_key_event();
|
||||
}
|
||||
}
|
||||
|
||||
fn accepts(active_block: ActiveSonarrBlock) -> bool {
|
||||
ADD_SERIES_BLOCKS.contains(&active_block)
|
||||
}
|
||||
@@ -47,14 +73,6 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for AddSeriesHandler<'a,
|
||||
|
||||
fn handle_scroll_up(&mut self) {
|
||||
match self.active_sonarr_block {
|
||||
ActiveSonarrBlock::AddSeriesSearchResults => self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.add_searched_series
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.scroll_up(),
|
||||
ActiveSonarrBlock::AddSeriesSelectMonitor => self
|
||||
.app
|
||||
.data
|
||||
@@ -107,14 +125,6 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for AddSeriesHandler<'a,
|
||||
|
||||
fn handle_scroll_down(&mut self) {
|
||||
match self.active_sonarr_block {
|
||||
ActiveSonarrBlock::AddSeriesSearchResults => self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.add_searched_series
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.scroll_down(),
|
||||
ActiveSonarrBlock::AddSeriesSelectMonitor => self
|
||||
.app
|
||||
.data
|
||||
@@ -167,14 +177,6 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for AddSeriesHandler<'a,
|
||||
|
||||
fn handle_home(&mut self) {
|
||||
match self.active_sonarr_block {
|
||||
ActiveSonarrBlock::AddSeriesSearchResults => self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.add_searched_series
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.scroll_to_top(),
|
||||
ActiveSonarrBlock::AddSeriesSelectMonitor => self
|
||||
.app
|
||||
.data
|
||||
@@ -243,14 +245,6 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for AddSeriesHandler<'a,
|
||||
|
||||
fn handle_end(&mut self) {
|
||||
match self.active_sonarr_block {
|
||||
ActiveSonarrBlock::AddSeriesSearchResults => self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.add_searched_series
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.scroll_to_bottom(),
|
||||
ActiveSonarrBlock::AddSeriesSelectMonitor => self
|
||||
.app
|
||||
.data
|
||||
|
||||
@@ -20,125 +20,11 @@ mod tests {
|
||||
|
||||
use crate::models::servarr_data::sonarr::modals::AddSeriesModal;
|
||||
use crate::models::servarr_data::sonarr::sonarr_data::ADD_SERIES_SELECTION_BLOCKS;
|
||||
use crate::models::stateful_table::StatefulTable;
|
||||
use crate::models::BlockSelectionState;
|
||||
use crate::simple_stateful_iterable_vec;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[rstest]
|
||||
fn test_add_series_search_results_scroll(
|
||||
#[values(DEFAULT_KEYBINDINGS.up.key, DEFAULT_KEYBINDINGS.down.key)] key: Key,
|
||||
) {
|
||||
let mut app = App::default();
|
||||
app.push_navigation_stack(ActiveSonarrBlock::Series.into());
|
||||
let mut add_searched_series = StatefulTable::default();
|
||||
add_searched_series.set_items(simple_stateful_iterable_vec!(
|
||||
AddSeriesSearchResult,
|
||||
HorizontallyScrollableText
|
||||
));
|
||||
app.data.sonarr_data.add_searched_series = Some(add_searched_series);
|
||||
|
||||
AddSeriesHandler::with(
|
||||
key,
|
||||
&mut app,
|
||||
ActiveSonarrBlock::AddSeriesSearchResults,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.add_searched_series
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.title
|
||||
.to_string(),
|
||||
"Test 2"
|
||||
);
|
||||
|
||||
AddSeriesHandler::with(
|
||||
key,
|
||||
&mut app,
|
||||
ActiveSonarrBlock::AddSeriesSearchResults,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.add_searched_series
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.title
|
||||
.to_string(),
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_add_series_search_results_scroll_no_op_when_not_ready(
|
||||
#[values(DEFAULT_KEYBINDINGS.up.key, DEFAULT_KEYBINDINGS.down.key)] key: Key,
|
||||
) {
|
||||
let mut app = App::default();
|
||||
app.push_navigation_stack(ActiveSonarrBlock::Series.into());
|
||||
app.is_loading = true;
|
||||
let mut add_searched_series = StatefulTable::default();
|
||||
add_searched_series.set_items(simple_stateful_iterable_vec!(
|
||||
AddSeriesSearchResult,
|
||||
HorizontallyScrollableText
|
||||
));
|
||||
app.data.sonarr_data.add_searched_series = Some(add_searched_series);
|
||||
|
||||
AddSeriesHandler::with(
|
||||
key,
|
||||
&mut app,
|
||||
ActiveSonarrBlock::AddSeriesSearchResults,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.add_searched_series
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.title
|
||||
.to_string(),
|
||||
"Test 1"
|
||||
);
|
||||
|
||||
AddSeriesHandler::with(
|
||||
key,
|
||||
&mut app,
|
||||
ActiveSonarrBlock::AddSeriesSearchResults,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.add_searched_series
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.title
|
||||
.to_string(),
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_add_series_select_monitor_scroll(
|
||||
#[values(DEFAULT_KEYBINDINGS.up.key, DEFAULT_KEYBINDINGS.down.key)] key: Key,
|
||||
@@ -486,119 +372,9 @@ mod tests {
|
||||
|
||||
use crate::extended_stateful_iterable_vec;
|
||||
use crate::models::servarr_data::sonarr::modals::AddSeriesModal;
|
||||
use crate::models::stateful_table::StatefulTable;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_add_series_search_results_home_end() {
|
||||
let mut app = App::default();
|
||||
app.push_navigation_stack(ActiveSonarrBlock::Series.into());
|
||||
let mut add_searched_series = StatefulTable::default();
|
||||
add_searched_series.set_items(extended_stateful_iterable_vec!(
|
||||
AddSeriesSearchResult,
|
||||
HorizontallyScrollableText
|
||||
));
|
||||
app.data.sonarr_data.add_searched_series = Some(add_searched_series);
|
||||
|
||||
AddSeriesHandler::with(
|
||||
DEFAULT_KEYBINDINGS.end.key,
|
||||
&mut app,
|
||||
ActiveSonarrBlock::AddSeriesSearchResults,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.add_searched_series
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.title
|
||||
.to_string(),
|
||||
"Test 3"
|
||||
);
|
||||
|
||||
AddSeriesHandler::with(
|
||||
DEFAULT_KEYBINDINGS.home.key,
|
||||
&mut app,
|
||||
ActiveSonarrBlock::AddSeriesSearchResults,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.add_searched_series
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.title
|
||||
.to_string(),
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_add_series_search_results_home_end_no_op_when_not_ready() {
|
||||
let mut app = App::default();
|
||||
app.push_navigation_stack(ActiveSonarrBlock::Series.into());
|
||||
app.is_loading = true;
|
||||
let mut add_searched_series = StatefulTable::default();
|
||||
add_searched_series.set_items(extended_stateful_iterable_vec!(
|
||||
AddSeriesSearchResult,
|
||||
HorizontallyScrollableText
|
||||
));
|
||||
app.data.sonarr_data.add_searched_series = Some(add_searched_series);
|
||||
|
||||
AddSeriesHandler::with(
|
||||
DEFAULT_KEYBINDINGS.end.key,
|
||||
&mut app,
|
||||
ActiveSonarrBlock::AddSeriesSearchResults,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.add_searched_series
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.title
|
||||
.to_string(),
|
||||
"Test 1"
|
||||
);
|
||||
|
||||
AddSeriesHandler::with(
|
||||
DEFAULT_KEYBINDINGS.home.key,
|
||||
&mut app,
|
||||
ActiveSonarrBlock::AddSeriesSearchResults,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.add_searched_series
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.title
|
||||
.to_string(),
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_add_series_select_monitor_home_end() {
|
||||
let monitor_vec = Vec::from_iter(SeriesMonitor::iter());
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -15,7 +15,7 @@ use crate::{
|
||||
},
|
||||
sonarr_models::Series,
|
||||
stateful_table::SortOption,
|
||||
BlockSelectionState, HorizontallyScrollableText, Scrollable,
|
||||
BlockSelectionState, HorizontallyScrollableText,
|
||||
},
|
||||
network::sonarr_network::SonarrEvent,
|
||||
};
|
||||
@@ -23,7 +23,7 @@ use crate::{
|
||||
use super::handle_change_tab_left_right_keys;
|
||||
use crate::app::key_binding::DEFAULT_KEYBINDINGS;
|
||||
use crate::handlers::sonarr_handlers::library::series_details_handler::SeriesDetailsHandler;
|
||||
use crate::handlers::table_handler::TableHandlingProps;
|
||||
use crate::handlers::table_handler::TableHandlingConfig;
|
||||
|
||||
mod add_series_handler;
|
||||
mod delete_series_handler;
|
||||
@@ -46,7 +46,7 @@ impl<'a, 'b> LibraryHandler<'a, 'b> {
|
||||
|
||||
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for LibraryHandler<'a, 'b> {
|
||||
fn handle(&mut self) {
|
||||
let series_table_handling_props = TableHandlingProps::new(ActiveSonarrBlock::Series.into())
|
||||
let series_table_handling_config = TableHandlingConfig::new(ActiveSonarrBlock::Series.into())
|
||||
.sorting_block(ActiveSonarrBlock::SeriesSortPrompt.into())
|
||||
.sort_by_fn(|a: &Series, b: &Series| a.id.cmp(&b.id))
|
||||
.sort_options(series_sorting_options())
|
||||
@@ -57,7 +57,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for LibraryHandler<'a, '
|
||||
.filter_error_block(ActiveSonarrBlock::FilterSeriesError.into())
|
||||
.filter_field_fn(|series| &series.title.text);
|
||||
|
||||
if !self.handle_series_table_events(series_table_handling_props) {
|
||||
if !self.handle_series_table_events(series_table_handling_config) {
|
||||
match self.active_sonarr_block {
|
||||
_ if AddSeriesHandler::accepts(self.active_sonarr_block) => {
|
||||
AddSeriesHandler::with(self.key, self.app, self.active_sonarr_block, self.context)
|
||||
|
||||
@@ -3,13 +3,13 @@ use crate::app::App;
|
||||
use crate::event::Key;
|
||||
use crate::handle_table_events;
|
||||
use crate::handlers::sonarr_handlers::history::history_sorting_options;
|
||||
use crate::handlers::table_handler::TableHandlingProps;
|
||||
use crate::handlers::table_handler::TableHandlingConfig;
|
||||
use crate::handlers::{handle_prompt_toggle, KeyEventHandler};
|
||||
use crate::models::servarr_data::sonarr::sonarr_data::{
|
||||
ActiveSonarrBlock, EDIT_SERIES_SELECTION_BLOCKS, SERIES_DETAILS_BLOCKS,
|
||||
};
|
||||
use crate::models::sonarr_models::{Season, SonarrHistoryItem};
|
||||
use crate::models::{BlockSelectionState, Scrollable};
|
||||
use crate::models::BlockSelectionState;
|
||||
use crate::network::sonarr_network::SonarrEvent;
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -41,8 +41,8 @@ impl<'a, 'b> SeriesDetailsHandler<'a, 'b> {
|
||||
|
||||
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for SeriesDetailsHandler<'a, 'b> {
|
||||
fn handle(&mut self) {
|
||||
let season_table_handling_props =
|
||||
TableHandlingProps::new(ActiveSonarrBlock::SeriesDetails.into())
|
||||
let season_table_handling_config =
|
||||
TableHandlingConfig::new(ActiveSonarrBlock::SeriesDetails.into())
|
||||
.searching_block(ActiveSonarrBlock::SearchSeason.into())
|
||||
.search_error_block(ActiveSonarrBlock::SearchSeasonError.into())
|
||||
.search_field_fn(|season: &Season| {
|
||||
@@ -51,8 +51,8 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for SeriesDetailsHandler
|
||||
.as_ref()
|
||||
.expect("Season was not populated with title in handlers")
|
||||
});
|
||||
let series_history_table_handling_props =
|
||||
TableHandlingProps::new(ActiveSonarrBlock::SeriesHistory.into())
|
||||
let series_history_table_handling_config =
|
||||
TableHandlingConfig::new(ActiveSonarrBlock::SeriesHistory.into())
|
||||
.sorting_block(ActiveSonarrBlock::SeriesHistorySortPrompt.into())
|
||||
.sort_options(history_sorting_options())
|
||||
.sort_by_fn(|a: &SonarrHistoryItem, b: &SonarrHistoryItem| a.id.cmp(&b.id))
|
||||
@@ -63,8 +63,8 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for SeriesDetailsHandler
|
||||
.filter_error_block(ActiveSonarrBlock::FilterSeriesHistoryError.into())
|
||||
.filter_field_fn(|history_item: &SonarrHistoryItem| &history_item.source_title.text);
|
||||
|
||||
if !self.handle_season_table_events(season_table_handling_props)
|
||||
&& !self.handle_series_history_table_events(series_history_table_handling_props)
|
||||
if !self.handle_season_table_events(season_table_handling_config)
|
||||
&& !self.handle_series_history_table_events(series_history_table_handling_config)
|
||||
{
|
||||
self.handle_key_event();
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,11 +2,11 @@ use crate::app::key_binding::DEFAULT_KEYBINDINGS;
|
||||
use crate::app::App;
|
||||
use crate::event::Key;
|
||||
use crate::handlers::sonarr_handlers::handle_change_tab_left_right_keys;
|
||||
use crate::handlers::table_handler::TableHandlingProps;
|
||||
use crate::handlers::table_handler::TableHandlingConfig;
|
||||
use crate::handlers::{handle_clear_errors, handle_prompt_toggle, KeyEventHandler};
|
||||
use crate::models::servarr_data::sonarr::sonarr_data::{ActiveSonarrBlock, ROOT_FOLDERS_BLOCKS};
|
||||
use crate::models::servarr_models::RootFolder;
|
||||
use crate::models::{HorizontallyScrollableText, Scrollable};
|
||||
use crate::models::HorizontallyScrollableText;
|
||||
use crate::network::sonarr_network::SonarrEvent;
|
||||
use crate::{handle_table_events, handle_text_box_keys, handle_text_box_left_right_keys};
|
||||
|
||||
@@ -32,10 +32,10 @@ impl<'a, 'b> RootFoldersHandler<'a, 'b> {
|
||||
|
||||
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for RootFoldersHandler<'a, 'b> {
|
||||
fn handle(&mut self) {
|
||||
let root_folders_table_handling_props =
|
||||
TableHandlingProps::new(ActiveSonarrBlock::RootFolders.into());
|
||||
let root_folders_table_handling_config =
|
||||
TableHandlingConfig::new(ActiveSonarrBlock::RootFolders.into());
|
||||
|
||||
if !self.handle_root_folders_table_events(root_folders_table_handling_props) {
|
||||
if !self.handle_root_folders_table_events(root_folders_table_handling_config) {
|
||||
self.handle_key_event();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use pretty_assertions::assert_str_eq;
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
use crate::app::key_binding::DEFAULT_KEYBINDINGS;
|
||||
@@ -12,113 +11,13 @@ mod tests {
|
||||
use crate::models::servarr_models::RootFolder;
|
||||
use crate::models::HorizontallyScrollableText;
|
||||
|
||||
mod test_handle_scroll_up_and_down {
|
||||
use rstest::rstest;
|
||||
|
||||
use crate::models::servarr_models::RootFolder;
|
||||
use crate::{simple_stateful_iterable_vec, test_iterable_scroll};
|
||||
|
||||
use super::*;
|
||||
|
||||
test_iterable_scroll!(
|
||||
test_root_folders_scroll,
|
||||
RootFoldersHandler,
|
||||
sonarr_data,
|
||||
root_folders,
|
||||
simple_stateful_iterable_vec!(RootFolder, String, path),
|
||||
ActiveSonarrBlock::RootFolders,
|
||||
None,
|
||||
path
|
||||
);
|
||||
|
||||
#[rstest]
|
||||
fn test_root_folders_scroll_no_op_when_not_ready(
|
||||
#[values(DEFAULT_KEYBINDINGS.up.key, DEFAULT_KEYBINDINGS.down.key)] key: Key,
|
||||
) {
|
||||
let mut app = App::default();
|
||||
app.push_navigation_stack(ActiveSonarrBlock::RootFolders.into());
|
||||
app.is_loading = true;
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.root_folders
|
||||
.set_items(simple_stateful_iterable_vec!(RootFolder, String, path));
|
||||
|
||||
RootFoldersHandler::with(key, &mut app, ActiveSonarrBlock::RootFolders, None).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app.data.sonarr_data.root_folders.current_selection().path,
|
||||
"Test 1"
|
||||
);
|
||||
|
||||
RootFoldersHandler::with(key, &mut app, ActiveSonarrBlock::RootFolders, None).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app.data.sonarr_data.root_folders.current_selection().path,
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_home_end {
|
||||
use crate::models::servarr_models::RootFolder;
|
||||
use pretty_assertions::assert_eq;
|
||||
use std::sync::atomic::Ordering;
|
||||
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
use crate::models::servarr_models::RootFolder;
|
||||
use crate::{extended_stateful_iterable_vec, test_iterable_home_and_end};
|
||||
|
||||
use super::*;
|
||||
|
||||
test_iterable_home_and_end!(
|
||||
test_root_folders_home_end,
|
||||
RootFoldersHandler,
|
||||
sonarr_data,
|
||||
root_folders,
|
||||
extended_stateful_iterable_vec!(RootFolder, String, path),
|
||||
ActiveSonarrBlock::RootFolders,
|
||||
None,
|
||||
path
|
||||
);
|
||||
|
||||
#[test]
|
||||
fn test_root_folders_home_end_no_op_when_not_ready() {
|
||||
let mut app = App::default();
|
||||
app.push_navigation_stack(ActiveSonarrBlock::RootFolders.into());
|
||||
app.is_loading = true;
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.root_folders
|
||||
.set_items(extended_stateful_iterable_vec!(RootFolder, String, path));
|
||||
|
||||
RootFoldersHandler::with(
|
||||
DEFAULT_KEYBINDINGS.end.key,
|
||||
&mut app,
|
||||
ActiveSonarrBlock::RootFolders,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app.data.sonarr_data.root_folders.current_selection().path,
|
||||
"Test 1"
|
||||
);
|
||||
|
||||
RootFoldersHandler::with(
|
||||
DEFAULT_KEYBINDINGS.home.key,
|
||||
&mut app,
|
||||
ActiveSonarrBlock::RootFolders,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app.data.sonarr_data.root_folders.current_selection().path,
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_add_root_folder_prompt_home_end_keys() {
|
||||
let mut app = App::default();
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use pretty_assertions::assert_eq;
|
||||
use rstest::rstest;
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
|
||||
@@ -4,8 +4,12 @@ use derive_setters::Setters;
|
||||
use std::cmp::Ordering;
|
||||
use std::fmt::Debug;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "table_handler_tests.rs"]
|
||||
mod table_handler_tests;
|
||||
|
||||
#[derive(Setters)]
|
||||
pub struct TableHandlingProps<T>
|
||||
pub struct TableHandlingConfig<T>
|
||||
where
|
||||
T: Clone + PartialEq + Eq + Debug + Default,
|
||||
{
|
||||
@@ -35,36 +39,36 @@ where
|
||||
macro_rules! handle_table_events {
|
||||
($self:expr, $name:ty, $table:expr, $row:ident) => {
|
||||
paste::paste! {
|
||||
fn [<handle_ $name _table_events>](&mut $self, props: $crate::handlers::table_handler::TableHandlingProps<$row>) -> bool {
|
||||
fn [<handle_ $name _table_events>](&mut $self, config: $crate::handlers::table_handler::TableHandlingConfig<$row>) -> bool {
|
||||
if $self.is_ready() {
|
||||
match $self.key {
|
||||
_ if $self.key == $crate::app::key_binding::DEFAULT_KEYBINDINGS.up.key => $self.[<handle_ $name _table_scroll_up>](props),
|
||||
_ if $self.key == $crate::app::key_binding::DEFAULT_KEYBINDINGS.down.key => $self.[<handle_ $name _table_scroll_down>](props),
|
||||
_ if $self.key == $crate::app::key_binding::DEFAULT_KEYBINDINGS.home.key => $self.[<handle_ $name _table_home>](props),
|
||||
_ if $self.key == $crate::app::key_binding::DEFAULT_KEYBINDINGS.end.key => $self.[<handle_ $name _table_end>](props),
|
||||
_ if $self.key == $crate::app::key_binding::DEFAULT_KEYBINDINGS.up.key => $self.[<handle_ $name _table_scroll_up>](config),
|
||||
_ if $self.key == $crate::app::key_binding::DEFAULT_KEYBINDINGS.down.key => $self.[<handle_ $name _table_scroll_down>](config),
|
||||
_ if $self.key == $crate::app::key_binding::DEFAULT_KEYBINDINGS.home.key => $self.[<handle_ $name _table_home>](config),
|
||||
_ if $self.key == $crate::app::key_binding::DEFAULT_KEYBINDINGS.end.key => $self.[<handle_ $name _table_end>](config),
|
||||
_ if $self.key == $crate::app::key_binding::DEFAULT_KEYBINDINGS.left.key
|
||||
|| $self.key == $crate::app::key_binding::DEFAULT_KEYBINDINGS.right.key =>
|
||||
{
|
||||
$self.[<handle_ $name _table_left_right>](props)
|
||||
$self.[<handle_ $name _table_left_right>](config)
|
||||
}
|
||||
_ if $self.key == $crate::app::key_binding::DEFAULT_KEYBINDINGS.submit.key => $self.[<handle_ $name _table_submit>](props),
|
||||
_ if $self.key == $crate::app::key_binding::DEFAULT_KEYBINDINGS.esc.key => $self.[<handle_ $name _table_esc>](props),
|
||||
_ if props.searching_block.is_some()
|
||||
&& $self.app.get_current_route() == *props.searching_block.as_ref().unwrap() =>
|
||||
_ if $self.key == $crate::app::key_binding::DEFAULT_KEYBINDINGS.submit.key => $self.[<handle_ $name _table_submit>](config),
|
||||
_ if $self.key == $crate::app::key_binding::DEFAULT_KEYBINDINGS.esc.key => $self.[<handle_ $name _table_esc>](config),
|
||||
_ if config.searching_block.is_some()
|
||||
&& $self.app.get_current_route() == *config.searching_block.as_ref().unwrap() =>
|
||||
{
|
||||
$self.[<handle_ $name _table_search_box_input>]()
|
||||
}
|
||||
_ if props.filtering_block.is_some()
|
||||
&& $self.app.get_current_route() == *props.filtering_block.as_ref().unwrap() =>
|
||||
_ if config.filtering_block.is_some()
|
||||
&& $self.app.get_current_route() == *config.filtering_block.as_ref().unwrap() =>
|
||||
{
|
||||
$self.[<handle_ $name _table_filter_box_input>]()
|
||||
}
|
||||
_ if $self.key == $crate::app::key_binding::DEFAULT_KEYBINDINGS.filter.key
|
||||
&& props.filtering_block.is_some() => $self.[<handle_ $name _table_filter_key>](props),
|
||||
&& config.filtering_block.is_some() => $self.[<handle_ $name _table_filter_key>](config),
|
||||
_ if $self.key == $crate::app::key_binding::DEFAULT_KEYBINDINGS.search.key
|
||||
&& props.searching_block.is_some() => $self.[<handle_ $name _table_search_key>](props),
|
||||
&& config.searching_block.is_some() => $self.[<handle_ $name _table_search_key>](config),
|
||||
_ if $self.key == $crate::app::key_binding::DEFAULT_KEYBINDINGS.sort.key
|
||||
&& props.sorting_block.is_some() => $self.[<handle_ $name _table_sort_key>](props),
|
||||
&& config.sorting_block.is_some() => $self.[<handle_ $name _table_sort_key>](config),
|
||||
_ => false,
|
||||
}
|
||||
} else {
|
||||
@@ -72,14 +76,16 @@ macro_rules! handle_table_events {
|
||||
}
|
||||
}
|
||||
|
||||
fn [<handle_ $name _table_scroll_up>](&mut $self, props: $crate::handlers::table_handler::TableHandlingProps<$row>) -> bool {
|
||||
fn [<handle_ $name _table_scroll_up>](&mut $self, config: $crate::handlers::table_handler::TableHandlingConfig<$row>) -> bool {
|
||||
use $crate::models::Scrollable;
|
||||
|
||||
match $self.app.get_current_route() {
|
||||
_ if props.table_block == $self.app.get_current_route() => {
|
||||
_ if config.table_block == $self.app.get_current_route() => {
|
||||
$table.scroll_up();
|
||||
true
|
||||
}
|
||||
_ if props.sorting_block.is_some()
|
||||
&& $self.app.get_current_route() == *props.sorting_block.as_ref().unwrap() =>
|
||||
_ if config.sorting_block.is_some()
|
||||
&& $self.app.get_current_route() == *config.sorting_block.as_ref().unwrap() =>
|
||||
{
|
||||
$table.sort.as_mut().unwrap().scroll_up();
|
||||
true
|
||||
@@ -88,14 +94,16 @@ macro_rules! handle_table_events {
|
||||
}
|
||||
}
|
||||
|
||||
fn [<handle_ $name _table_scroll_down>](&mut $self, props: $crate::handlers::table_handler::TableHandlingProps<$row>) -> bool {
|
||||
fn [<handle_ $name _table_scroll_down>](&mut $self, config: $crate::handlers::table_handler::TableHandlingConfig<$row>) -> bool {
|
||||
use $crate::models::Scrollable;
|
||||
|
||||
match $self.app.get_current_route() {
|
||||
_ if props.table_block == $self.app.get_current_route() => {
|
||||
_ if config.table_block == $self.app.get_current_route() => {
|
||||
$table.scroll_down();
|
||||
true
|
||||
}
|
||||
_ if props.sorting_block.is_some()
|
||||
&& $self.app.get_current_route() == *props.sorting_block.as_ref().unwrap() =>
|
||||
_ if config.sorting_block.is_some()
|
||||
&& $self.app.get_current_route() == *config.sorting_block.as_ref().unwrap() =>
|
||||
{
|
||||
$table
|
||||
.sort
|
||||
@@ -108,14 +116,16 @@ macro_rules! handle_table_events {
|
||||
}
|
||||
}
|
||||
|
||||
fn [<handle_ $name _table_home>](&mut $self, props: $crate::handlers::table_handler::TableHandlingProps<$row>) -> bool {
|
||||
fn [<handle_ $name _table_home>](&mut $self, config: $crate::handlers::table_handler::TableHandlingConfig<$row>) -> bool {
|
||||
use $crate::models::Scrollable;
|
||||
|
||||
match $self.app.get_current_route() {
|
||||
_ if props.table_block == $self.app.get_current_route() => {
|
||||
_ if config.table_block == $self.app.get_current_route() => {
|
||||
$table.scroll_to_top();
|
||||
true
|
||||
}
|
||||
_ if props.sorting_block.is_some()
|
||||
&& $self.app.get_current_route() == *props.sorting_block.as_ref().unwrap() =>
|
||||
_ if config.sorting_block.is_some()
|
||||
&& $self.app.get_current_route() == *config.sorting_block.as_ref().unwrap() =>
|
||||
{
|
||||
$table
|
||||
.sort
|
||||
@@ -124,8 +134,8 @@ macro_rules! handle_table_events {
|
||||
.scroll_to_top();
|
||||
true
|
||||
}
|
||||
_ if props.searching_block.is_some()
|
||||
&& $self.app.get_current_route() == *props.searching_block.as_ref().unwrap() =>
|
||||
_ if config.searching_block.is_some()
|
||||
&& $self.app.get_current_route() == *config.searching_block.as_ref().unwrap() =>
|
||||
{
|
||||
$table
|
||||
.search
|
||||
@@ -134,8 +144,8 @@ macro_rules! handle_table_events {
|
||||
.scroll_home();
|
||||
true
|
||||
}
|
||||
_ if props.filtering_block.is_some()
|
||||
&& $self.app.get_current_route() == *props.filtering_block.as_ref().unwrap() =>
|
||||
_ if config.filtering_block.is_some()
|
||||
&& $self.app.get_current_route() == *config.filtering_block.as_ref().unwrap() =>
|
||||
{
|
||||
$table
|
||||
.filter
|
||||
@@ -148,14 +158,16 @@ macro_rules! handle_table_events {
|
||||
}
|
||||
}
|
||||
|
||||
fn [<handle_ $name _table_end>](&mut $self, props: $crate::handlers::table_handler::TableHandlingProps<$row>) -> bool {
|
||||
fn [<handle_ $name _table_end>](&mut $self, config: $crate::handlers::table_handler::TableHandlingConfig<$row>) -> bool {
|
||||
use $crate::models::Scrollable;
|
||||
|
||||
match $self.app.get_current_route() {
|
||||
_ if props.table_block == $self.app.get_current_route() => {
|
||||
_ if config.table_block == $self.app.get_current_route() => {
|
||||
$table.scroll_to_bottom();
|
||||
true
|
||||
}
|
||||
_ if props.sorting_block.is_some()
|
||||
&& $self.app.get_current_route() == *props.sorting_block.as_ref().unwrap() =>
|
||||
_ if config.sorting_block.is_some()
|
||||
&& $self.app.get_current_route() == *config.sorting_block.as_ref().unwrap() =>
|
||||
{
|
||||
$table
|
||||
.sort
|
||||
@@ -164,8 +176,8 @@ macro_rules! handle_table_events {
|
||||
.scroll_to_bottom();
|
||||
true
|
||||
}
|
||||
_ if props.searching_block.is_some()
|
||||
&& $self.app.get_current_route() == *props.searching_block.as_ref().unwrap() =>
|
||||
_ if config.searching_block.is_some()
|
||||
&& $self.app.get_current_route() == *config.searching_block.as_ref().unwrap() =>
|
||||
{
|
||||
$table
|
||||
.search
|
||||
@@ -174,8 +186,8 @@ macro_rules! handle_table_events {
|
||||
.reset_offset();
|
||||
true
|
||||
}
|
||||
_ if props.filtering_block.is_some()
|
||||
&& $self.app.get_current_route() == *props.filtering_block.as_ref().unwrap() =>
|
||||
_ if config.filtering_block.is_some()
|
||||
&& $self.app.get_current_route() == *config.filtering_block.as_ref().unwrap() =>
|
||||
{
|
||||
$table
|
||||
.filter
|
||||
@@ -188,10 +200,10 @@ macro_rules! handle_table_events {
|
||||
}
|
||||
}
|
||||
|
||||
fn [<handle_ $name _table_left_right>](&mut $self, props: $crate::handlers::table_handler::TableHandlingProps<$row>) -> bool {
|
||||
fn [<handle_ $name _table_left_right>](&mut $self, config: $crate::handlers::table_handler::TableHandlingConfig<$row>) -> bool {
|
||||
match $self.app.get_current_route() {
|
||||
_ if props.searching_block.is_some()
|
||||
&& $self.app.get_current_route() == *props.searching_block.as_ref().unwrap() =>
|
||||
_ if config.searching_block.is_some()
|
||||
&& $self.app.get_current_route() == *config.searching_block.as_ref().unwrap() =>
|
||||
{
|
||||
$crate::handle_text_box_left_right_keys!(
|
||||
$self,
|
||||
@@ -200,8 +212,8 @@ macro_rules! handle_table_events {
|
||||
);
|
||||
true
|
||||
}
|
||||
_ if props.filtering_block.is_some()
|
||||
&& $self.app.get_current_route() == *props.filtering_block.as_ref().unwrap() =>
|
||||
_ if config.filtering_block.is_some()
|
||||
&& $self.app.get_current_route() == *config.filtering_block.as_ref().unwrap() =>
|
||||
{
|
||||
$crate::handle_text_box_left_right_keys!(
|
||||
$self,
|
||||
@@ -214,12 +226,12 @@ macro_rules! handle_table_events {
|
||||
}
|
||||
}
|
||||
|
||||
fn [<handle _$name _table_submit>](&mut $self, props: $crate::handlers::table_handler::TableHandlingProps<$row>) -> bool {
|
||||
fn [<handle _$name _table_submit>](&mut $self, config: $crate::handlers::table_handler::TableHandlingConfig<$row>) -> bool {
|
||||
match $self.app.get_current_route() {
|
||||
_ if props.sorting_block.is_some()
|
||||
&& $self.app.get_current_route() == *props.sorting_block.as_ref().unwrap() =>
|
||||
_ if config.sorting_block.is_some()
|
||||
&& $self.app.get_current_route() == *config.sorting_block.as_ref().unwrap() =>
|
||||
{
|
||||
if let Some(sort_by_fn) = props.sort_by_fn {
|
||||
if let Some(sort_by_fn) = config.sort_by_fn {
|
||||
$table.items.sort_by(sort_by_fn);
|
||||
}
|
||||
|
||||
@@ -228,21 +240,21 @@ macro_rules! handle_table_events {
|
||||
|
||||
true
|
||||
}
|
||||
_ if props.searching_block.is_some()
|
||||
&& $self.app.get_current_route() == *props.searching_block.as_ref().unwrap() =>
|
||||
_ if config.searching_block.is_some()
|
||||
&& $self.app.get_current_route() == *config.searching_block.as_ref().unwrap() =>
|
||||
{
|
||||
$self.app.pop_navigation_stack();
|
||||
$self.app.should_ignore_quit_key = false;
|
||||
|
||||
if $table.search.is_some() {
|
||||
let search_field_fn = props
|
||||
let search_field_fn = config
|
||||
.search_field_fn
|
||||
.expect("Search field function is required");
|
||||
let has_match = $table.apply_search(search_field_fn);
|
||||
|
||||
if !has_match {
|
||||
$self.app.push_navigation_stack(
|
||||
props
|
||||
config
|
||||
.search_error_block
|
||||
.expect("Search error block is undefined"),
|
||||
);
|
||||
@@ -251,21 +263,21 @@ macro_rules! handle_table_events {
|
||||
|
||||
true
|
||||
}
|
||||
_ if props.filtering_block.is_some()
|
||||
&& $self.app.get_current_route() == *props.filtering_block.as_ref().unwrap() =>
|
||||
_ if config.filtering_block.is_some()
|
||||
&& $self.app.get_current_route() == *config.filtering_block.as_ref().unwrap() =>
|
||||
{
|
||||
$self.app.pop_navigation_stack();
|
||||
$self.app.should_ignore_quit_key = false;
|
||||
|
||||
if $table.filter.is_some() {
|
||||
let filter_field_fn = props
|
||||
let filter_field_fn = config
|
||||
.filter_field_fn
|
||||
.expect("Search field function is required");
|
||||
let has_match = $table.apply_filter(filter_field_fn);
|
||||
|
||||
if !has_match {
|
||||
$self.app.push_navigation_stack(
|
||||
props
|
||||
config
|
||||
.filter_error_block
|
||||
.expect("Search error block is undefined"),
|
||||
);
|
||||
@@ -278,35 +290,35 @@ macro_rules! handle_table_events {
|
||||
}
|
||||
}
|
||||
|
||||
fn [<handle_ $name _table_esc>](&mut $self, props: $crate::handlers::table_handler::TableHandlingProps<$row>) -> bool {
|
||||
fn [<handle_ $name _table_esc>](&mut $self, config: $crate::handlers::table_handler::TableHandlingConfig<$row>) -> bool {
|
||||
match $self.app.get_current_route() {
|
||||
_ if props.sorting_block.is_some()
|
||||
&& $self.app.get_current_route() == *props.sorting_block.as_ref().unwrap() =>
|
||||
_ if config.sorting_block.is_some()
|
||||
&& $self.app.get_current_route() == *config.sorting_block.as_ref().unwrap() =>
|
||||
{
|
||||
$self.app.pop_navigation_stack();
|
||||
true
|
||||
}
|
||||
_ if (props.searching_block.is_some()
|
||||
&& $self.app.get_current_route() == *props.searching_block.as_ref().unwrap())
|
||||
|| (props.search_error_block.is_some()
|
||||
&& $self.app.get_current_route() == *props.search_error_block.as_ref().unwrap()) =>
|
||||
_ if (config.searching_block.is_some()
|
||||
&& $self.app.get_current_route() == *config.searching_block.as_ref().unwrap())
|
||||
|| (config.search_error_block.is_some()
|
||||
&& $self.app.get_current_route() == *config.search_error_block.as_ref().unwrap()) =>
|
||||
{
|
||||
$self.app.pop_navigation_stack();
|
||||
$table.reset_search();
|
||||
$self.app.should_ignore_quit_key = false;
|
||||
true
|
||||
}
|
||||
_ if (props.filtering_block.is_some()
|
||||
&& $self.app.get_current_route() == *props.filtering_block.as_ref().unwrap())
|
||||
|| (props.filter_error_block.is_some()
|
||||
&& $self.app.get_current_route() == *props.filter_error_block.as_ref().unwrap()) =>
|
||||
_ if (config.filtering_block.is_some()
|
||||
&& $self.app.get_current_route() == *config.filtering_block.as_ref().unwrap())
|
||||
|| (config.filter_error_block.is_some()
|
||||
&& $self.app.get_current_route() == *config.filter_error_block.as_ref().unwrap()) =>
|
||||
{
|
||||
$self.app.pop_navigation_stack();
|
||||
$table.reset_filter();
|
||||
$self.app.should_ignore_quit_key = false;
|
||||
true
|
||||
}
|
||||
_ if props.table_block == $self.app.get_current_route()
|
||||
_ if config.table_block == $self.app.get_current_route()
|
||||
&& $table.filtered_items.is_some() =>
|
||||
{
|
||||
$table.reset_filter();
|
||||
@@ -316,11 +328,11 @@ macro_rules! handle_table_events {
|
||||
}
|
||||
}
|
||||
|
||||
fn [<handle_ $name _table_filter_key>](&mut $self, props: $crate::handlers::table_handler::TableHandlingProps<$row>) -> bool {
|
||||
if matches!($self.app.get_current_route(), _ if props.table_block == $self.app.get_current_route()) {
|
||||
fn [<handle_ $name _table_filter_key>](&mut $self, config: $crate::handlers::table_handler::TableHandlingConfig<$row>) -> bool {
|
||||
if matches!($self.app.get_current_route(), _ if config.table_block == $self.app.get_current_route()) {
|
||||
$self
|
||||
.app
|
||||
.push_navigation_stack(props.filtering_block.expect("Filtering block is undefined").into());
|
||||
.push_navigation_stack(config.filtering_block.expect("Filtering block is undefined").into());
|
||||
$table.reset_filter();
|
||||
$table.filter = Some($crate::models::HorizontallyScrollableText::default());
|
||||
$self.app.should_ignore_quit_key = true;
|
||||
@@ -331,11 +343,11 @@ macro_rules! handle_table_events {
|
||||
}
|
||||
}
|
||||
|
||||
fn [<handle_ $name _table_search_key>](&mut $self, props: $crate::handlers::table_handler::TableHandlingProps<$row>) -> bool {
|
||||
if matches!($self.app.get_current_route(), _ if props.table_block == $self.app.get_current_route()) {
|
||||
fn [<handle_ $name _table_search_key>](&mut $self, config: $crate::handlers::table_handler::TableHandlingConfig<$row>) -> bool {
|
||||
if matches!($self.app.get_current_route(), _ if config.table_block == $self.app.get_current_route()) {
|
||||
$self
|
||||
.app
|
||||
.push_navigation_stack(props.searching_block.expect("Searching block is undefined"));
|
||||
.push_navigation_stack(config.searching_block.expect("Searching block is undefined"));
|
||||
$table.search = Some($crate::models::HorizontallyScrollableText::default());
|
||||
$self.app.should_ignore_quit_key = true;
|
||||
|
||||
@@ -345,10 +357,10 @@ macro_rules! handle_table_events {
|
||||
}
|
||||
}
|
||||
|
||||
fn [<handle_ $name _table_sort_key>](&mut $self, props: $crate::handlers::table_handler::TableHandlingProps<$row>) -> bool {
|
||||
if matches!($self.app.get_current_route(), _ if props.table_block == $self.app.get_current_route()) {
|
||||
fn [<handle_ $name _table_sort_key>](&mut $self, config: $crate::handlers::table_handler::TableHandlingConfig<$row>) -> bool {
|
||||
if matches!($self.app.get_current_route(), _ if config.table_block == $self.app.get_current_route()) {
|
||||
$table.sorting(
|
||||
props
|
||||
config
|
||||
.sort_options
|
||||
.as_ref()
|
||||
.expect("Sort options are undefined")
|
||||
@@ -356,7 +368,7 @@ macro_rules! handle_table_events {
|
||||
);
|
||||
$self
|
||||
.app
|
||||
.push_navigation_stack(props.sorting_block.expect("Sorting block is undefined"));
|
||||
.push_navigation_stack(config.sorting_block.expect("Sorting block is undefined"));
|
||||
true
|
||||
} else {
|
||||
false
|
||||
@@ -384,12 +396,12 @@ macro_rules! handle_table_events {
|
||||
};
|
||||
}
|
||||
|
||||
impl<T> TableHandlingProps<T>
|
||||
impl<T> TableHandlingConfig<T>
|
||||
where
|
||||
T: Clone + PartialEq + Eq + Debug + Default,
|
||||
{
|
||||
pub fn new(table_block: Route) -> Self {
|
||||
TableHandlingProps {
|
||||
TableHandlingConfig {
|
||||
sorting_block: None,
|
||||
sort_options: None,
|
||||
sort_by_fn: None,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user