feat: Full CLI and TUI support for the Lidarr Indexers tab

This commit is contained in:
2026-01-14 13:30:51 -07:00
parent 8abcf44866
commit c74d5936d2
91 changed files with 9481 additions and 166 deletions
@@ -0,0 +1,533 @@
use crate::app::App;
use crate::event::Key;
use crate::handlers::{KeyEventHandler, handle_prompt_toggle};
use crate::models::Route;
use crate::models::servarr_data::lidarr::lidarr_data::{ActiveLidarrBlock, EDIT_INDEXER_BLOCKS};
use crate::models::servarr_data::modals::EditIndexerModal;
use crate::models::servarr_models::EditIndexerParams;
use crate::network::lidarr_network::LidarrEvent;
use crate::{
handle_prompt_left_right_keys, handle_text_box_keys, handle_text_box_left_right_keys, matches_key,
};
#[cfg(test)]
#[path = "edit_indexer_handler_tests.rs"]
mod edit_indexer_handler_tests;
pub(super) struct EditIndexerHandler<'a, 'b> {
key: Key,
app: &'a mut App<'b>,
active_lidarr_block: ActiveLidarrBlock,
_context: Option<ActiveLidarrBlock>,
}
impl EditIndexerHandler<'_, '_> {
fn build_edit_indexer_params(&mut self) -> EditIndexerParams {
let edit_indexer_modal = self
.app
.data
.lidarr_data
.edit_indexer_modal
.take()
.expect("EditIndexerModal is None");
let indexer_id = self.app.data.lidarr_data.indexers.current_selection().id;
let tags = edit_indexer_modal.tags.text;
let EditIndexerModal {
name,
enable_rss,
enable_automatic_search,
enable_interactive_search,
url,
api_key,
seed_ratio,
priority,
..
} = edit_indexer_modal;
EditIndexerParams {
indexer_id,
name: Some(name.text),
enable_rss,
enable_automatic_search,
enable_interactive_search,
url: Some(url.text),
api_key: Some(api_key.text),
seed_ratio: Some(seed_ratio.text),
tags: None,
tag_input_string: Some(tags),
priority: Some(priority),
clear_tags: false,
}
}
}
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveLidarrBlock> for EditIndexerHandler<'a, 'b> {
fn accepts(active_block: ActiveLidarrBlock) -> bool {
EDIT_INDEXER_BLOCKS.contains(&active_block)
}
fn ignore_special_keys(&self) -> bool {
self.app.ignore_special_keys_for_textbox_input
}
fn new(
key: Key,
app: &'a mut App<'b>,
active_block: ActiveLidarrBlock,
_context: Option<ActiveLidarrBlock>,
) -> EditIndexerHandler<'a, 'b> {
EditIndexerHandler {
key,
app,
active_lidarr_block: active_block,
_context,
}
}
fn get_key(&self) -> Key {
self.key
}
fn is_ready(&self) -> bool {
!self.app.is_loading && self.app.data.lidarr_data.edit_indexer_modal.is_some()
}
fn handle_scroll_up(&mut self) {
match self.active_lidarr_block {
ActiveLidarrBlock::EditIndexerPrompt => {
self.app.data.lidarr_data.selected_block.up();
}
ActiveLidarrBlock::EditIndexerPriorityInput => {
self
.app
.data
.lidarr_data
.edit_indexer_modal
.as_mut()
.unwrap()
.priority += 1;
}
_ => (),
}
}
fn handle_scroll_down(&mut self) {
match self.active_lidarr_block {
ActiveLidarrBlock::EditIndexerPrompt => {
self.app.data.lidarr_data.selected_block.down();
}
ActiveLidarrBlock::EditIndexerPriorityInput => {
let edit_indexer_modal = self
.app
.data
.lidarr_data
.edit_indexer_modal
.as_mut()
.unwrap();
if edit_indexer_modal.priority > 1 {
edit_indexer_modal.priority -= 1;
}
}
_ => (),
}
}
fn handle_home(&mut self) {
match self.active_lidarr_block {
ActiveLidarrBlock::EditIndexerNameInput => {
self
.app
.data
.lidarr_data
.edit_indexer_modal
.as_mut()
.unwrap()
.name
.scroll_home();
}
ActiveLidarrBlock::EditIndexerUrlInput => {
self
.app
.data
.lidarr_data
.edit_indexer_modal
.as_mut()
.unwrap()
.url
.scroll_home();
}
ActiveLidarrBlock::EditIndexerApiKeyInput => {
self
.app
.data
.lidarr_data
.edit_indexer_modal
.as_mut()
.unwrap()
.api_key
.scroll_home();
}
ActiveLidarrBlock::EditIndexerSeedRatioInput => {
self
.app
.data
.lidarr_data
.edit_indexer_modal
.as_mut()
.unwrap()
.seed_ratio
.scroll_home();
}
ActiveLidarrBlock::EditIndexerTagsInput => {
self
.app
.data
.lidarr_data
.edit_indexer_modal
.as_mut()
.unwrap()
.tags
.scroll_home();
}
_ => (),
}
}
fn handle_end(&mut self) {
match self.active_lidarr_block {
ActiveLidarrBlock::EditIndexerNameInput => {
self
.app
.data
.lidarr_data
.edit_indexer_modal
.as_mut()
.unwrap()
.name
.reset_offset();
}
ActiveLidarrBlock::EditIndexerUrlInput => {
self
.app
.data
.lidarr_data
.edit_indexer_modal
.as_mut()
.unwrap()
.url
.reset_offset();
}
ActiveLidarrBlock::EditIndexerApiKeyInput => {
self
.app
.data
.lidarr_data
.edit_indexer_modal
.as_mut()
.unwrap()
.api_key
.reset_offset();
}
ActiveLidarrBlock::EditIndexerSeedRatioInput => {
self
.app
.data
.lidarr_data
.edit_indexer_modal
.as_mut()
.unwrap()
.seed_ratio
.reset_offset();
}
ActiveLidarrBlock::EditIndexerTagsInput => {
self
.app
.data
.lidarr_data
.edit_indexer_modal
.as_mut()
.unwrap()
.tags
.reset_offset();
}
_ => (),
}
}
fn handle_delete(&mut self) {}
fn handle_left_right_action(&mut self) {
match self.active_lidarr_block {
ActiveLidarrBlock::EditIndexerPrompt => {
handle_prompt_left_right_keys!(
self,
ActiveLidarrBlock::EditIndexerConfirmPrompt,
lidarr_data
);
}
ActiveLidarrBlock::EditIndexerNameInput => {
handle_text_box_left_right_keys!(
self,
self.key,
self
.app
.data
.lidarr_data
.edit_indexer_modal
.as_mut()
.unwrap()
.name
);
}
ActiveLidarrBlock::EditIndexerUrlInput => {
handle_text_box_left_right_keys!(
self,
self.key,
self
.app
.data
.lidarr_data
.edit_indexer_modal
.as_mut()
.unwrap()
.url
);
}
ActiveLidarrBlock::EditIndexerApiKeyInput => {
handle_text_box_left_right_keys!(
self,
self.key,
self
.app
.data
.lidarr_data
.edit_indexer_modal
.as_mut()
.unwrap()
.api_key
);
}
ActiveLidarrBlock::EditIndexerSeedRatioInput => {
handle_text_box_left_right_keys!(
self,
self.key,
self
.app
.data
.lidarr_data
.edit_indexer_modal
.as_mut()
.unwrap()
.seed_ratio
);
}
ActiveLidarrBlock::EditIndexerTagsInput => {
handle_text_box_left_right_keys!(
self,
self.key,
self
.app
.data
.lidarr_data
.edit_indexer_modal
.as_mut()
.unwrap()
.tags
);
}
_ => (),
}
}
fn handle_submit(&mut self) {
match self.active_lidarr_block {
ActiveLidarrBlock::EditIndexerPrompt => {
let selected_block = self.app.data.lidarr_data.selected_block.get_active_block();
match selected_block {
ActiveLidarrBlock::EditIndexerConfirmPrompt => {
if self.app.data.lidarr_data.prompt_confirm {
self.app.data.lidarr_data.prompt_confirm_action =
Some(LidarrEvent::EditIndexer(self.build_edit_indexer_params()));
self.app.should_refresh = true;
} else {
self.app.data.lidarr_data.edit_indexer_modal = None;
}
self.app.pop_navigation_stack();
}
ActiveLidarrBlock::EditIndexerNameInput
| ActiveLidarrBlock::EditIndexerUrlInput
| ActiveLidarrBlock::EditIndexerApiKeyInput
| ActiveLidarrBlock::EditIndexerSeedRatioInput
| ActiveLidarrBlock::EditIndexerTagsInput => {
self.app.push_navigation_stack(selected_block.into());
self.app.ignore_special_keys_for_textbox_input = true;
}
ActiveLidarrBlock::EditIndexerPriorityInput => self
.app
.push_navigation_stack(ActiveLidarrBlock::EditIndexerPriorityInput.into()),
ActiveLidarrBlock::EditIndexerToggleEnableRss => {
let indexer = self
.app
.data
.lidarr_data
.edit_indexer_modal
.as_mut()
.unwrap();
indexer.enable_rss = Some(!indexer.enable_rss.unwrap_or_default());
}
ActiveLidarrBlock::EditIndexerToggleEnableAutomaticSearch => {
let indexer = self
.app
.data
.lidarr_data
.edit_indexer_modal
.as_mut()
.unwrap();
indexer.enable_automatic_search =
Some(!indexer.enable_automatic_search.unwrap_or_default());
}
ActiveLidarrBlock::EditIndexerToggleEnableInteractiveSearch => {
let indexer = self
.app
.data
.lidarr_data
.edit_indexer_modal
.as_mut()
.unwrap();
indexer.enable_interactive_search =
Some(!indexer.enable_interactive_search.unwrap_or_default());
}
_ => (),
}
}
ActiveLidarrBlock::EditIndexerNameInput
| ActiveLidarrBlock::EditIndexerUrlInput
| ActiveLidarrBlock::EditIndexerApiKeyInput
| ActiveLidarrBlock::EditIndexerSeedRatioInput
| ActiveLidarrBlock::EditIndexerTagsInput => {
self.app.pop_navigation_stack();
self.app.ignore_special_keys_for_textbox_input = false;
}
ActiveLidarrBlock::EditIndexerPriorityInput => self.app.pop_navigation_stack(),
_ => (),
}
}
fn handle_esc(&mut self) {
match self.active_lidarr_block {
ActiveLidarrBlock::EditIndexerPrompt => {
self.app.pop_navigation_stack();
self.app.data.lidarr_data.prompt_confirm = false;
self.app.data.lidarr_data.edit_indexer_modal = None;
}
ActiveLidarrBlock::EditIndexerNameInput
| ActiveLidarrBlock::EditIndexerUrlInput
| ActiveLidarrBlock::EditIndexerApiKeyInput
| ActiveLidarrBlock::EditIndexerSeedRatioInput
| ActiveLidarrBlock::EditIndexerPriorityInput
| ActiveLidarrBlock::EditIndexerTagsInput => {
self.app.pop_navigation_stack();
self.app.ignore_special_keys_for_textbox_input = false;
}
_ => self.app.pop_navigation_stack(),
}
}
fn handle_char_key_event(&mut self) {
match self.active_lidarr_block {
ActiveLidarrBlock::EditIndexerNameInput => {
handle_text_box_keys!(
self,
self.key,
self
.app
.data
.lidarr_data
.edit_indexer_modal
.as_mut()
.unwrap()
.name
);
}
ActiveLidarrBlock::EditIndexerUrlInput => {
handle_text_box_keys!(
self,
self.key,
self
.app
.data
.lidarr_data
.edit_indexer_modal
.as_mut()
.unwrap()
.url
);
}
ActiveLidarrBlock::EditIndexerApiKeyInput => {
handle_text_box_keys!(
self,
self.key,
self
.app
.data
.lidarr_data
.edit_indexer_modal
.as_mut()
.unwrap()
.api_key
);
}
ActiveLidarrBlock::EditIndexerSeedRatioInput => {
handle_text_box_keys!(
self,
self.key,
self
.app
.data
.lidarr_data
.edit_indexer_modal
.as_mut()
.unwrap()
.seed_ratio
);
}
ActiveLidarrBlock::EditIndexerTagsInput => {
handle_text_box_keys!(
self,
self.key,
self
.app
.data
.lidarr_data
.edit_indexer_modal
.as_mut()
.unwrap()
.tags
);
}
ActiveLidarrBlock::EditIndexerPrompt => {
if self.app.data.lidarr_data.selected_block.get_active_block()
== ActiveLidarrBlock::EditIndexerConfirmPrompt
&& matches_key!(confirm, self.key)
{
self.app.data.lidarr_data.prompt_confirm = true;
self.app.data.lidarr_data.prompt_confirm_action =
Some(LidarrEvent::EditIndexer(self.build_edit_indexer_params()));
self.app.should_refresh = true;
self.app.pop_navigation_stack();
}
}
_ => (),
}
}
fn app_mut(&mut self) -> &mut App<'b> {
self.app
}
fn current_route(&self) -> Route {
self.app.get_current_route()
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,209 @@
use crate::app::App;
use crate::event::Key;
use crate::handlers::{KeyEventHandler, handle_prompt_toggle};
use crate::models::Route;
use crate::models::servarr_data::lidarr::lidarr_data::{
ActiveLidarrBlock, INDEXER_SETTINGS_BLOCKS,
};
use crate::models::servarr_models::IndexerSettings;
use crate::network::lidarr_network::LidarrEvent;
use crate::{handle_prompt_left_right_keys, matches_key};
#[cfg(test)]
#[path = "edit_indexer_settings_handler_tests.rs"]
mod edit_indexer_settings_handler_tests;
pub(super) struct IndexerSettingsHandler<'a, 'b> {
key: Key,
app: &'a mut App<'b>,
active_lidarr_block: ActiveLidarrBlock,
_context: Option<ActiveLidarrBlock>,
}
impl IndexerSettingsHandler<'_, '_> {
fn build_edit_indexer_settings_params(&mut self) -> IndexerSettings {
self
.app
.data
.lidarr_data
.indexer_settings
.take()
.expect("IndexerSettings is None")
}
}
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveLidarrBlock> for IndexerSettingsHandler<'a, 'b> {
fn accepts(active_block: ActiveLidarrBlock) -> bool {
INDEXER_SETTINGS_BLOCKS.contains(&active_block)
}
fn ignore_special_keys(&self) -> bool {
self.app.ignore_special_keys_for_textbox_input
}
fn new(
key: Key,
app: &'a mut App<'b>,
active_block: ActiveLidarrBlock,
_context: Option<ActiveLidarrBlock>,
) -> IndexerSettingsHandler<'a, 'b> {
IndexerSettingsHandler {
key,
app,
active_lidarr_block: active_block,
_context,
}
}
fn get_key(&self) -> Key {
self.key
}
fn is_ready(&self) -> bool {
!self.app.is_loading && self.app.data.lidarr_data.indexer_settings.is_some()
}
fn handle_scroll_up(&mut self) {
let indexer_settings = self.app.data.lidarr_data.indexer_settings.as_mut().unwrap();
match self.active_lidarr_block {
ActiveLidarrBlock::AllIndexerSettingsPrompt => {
self.app.data.lidarr_data.selected_block.up();
}
ActiveLidarrBlock::IndexerSettingsMinimumAgeInput => {
indexer_settings.minimum_age += 1;
}
ActiveLidarrBlock::IndexerSettingsRetentionInput => {
indexer_settings.retention += 1;
}
ActiveLidarrBlock::IndexerSettingsMaximumSizeInput => {
indexer_settings.maximum_size += 1;
}
ActiveLidarrBlock::IndexerSettingsRssSyncIntervalInput => {
indexer_settings.rss_sync_interval += 1;
}
_ => (),
}
}
fn handle_scroll_down(&mut self) {
let indexer_settings = self.app.data.lidarr_data.indexer_settings.as_mut().unwrap();
match self.active_lidarr_block {
ActiveLidarrBlock::AllIndexerSettingsPrompt => {
self.app.data.lidarr_data.selected_block.down()
}
ActiveLidarrBlock::IndexerSettingsMinimumAgeInput => {
if indexer_settings.minimum_age > 0 {
indexer_settings.minimum_age -= 1;
}
}
ActiveLidarrBlock::IndexerSettingsRetentionInput => {
if indexer_settings.retention > 0 {
indexer_settings.retention -= 1;
}
}
ActiveLidarrBlock::IndexerSettingsMaximumSizeInput => {
if indexer_settings.maximum_size > 0 {
indexer_settings.maximum_size -= 1;
}
}
ActiveLidarrBlock::IndexerSettingsRssSyncIntervalInput => {
if indexer_settings.rss_sync_interval > 0 {
indexer_settings.rss_sync_interval -= 1;
}
}
_ => (),
}
}
fn handle_home(&mut self) {}
fn handle_end(&mut self) {}
fn handle_delete(&mut self) {}
fn handle_left_right_action(&mut self) {
if self.active_lidarr_block == ActiveLidarrBlock::AllIndexerSettingsPrompt {
handle_prompt_left_right_keys!(
self,
ActiveLidarrBlock::IndexerSettingsConfirmPrompt,
lidarr_data
);
}
}
fn handle_submit(&mut self) {
match self.active_lidarr_block {
ActiveLidarrBlock::AllIndexerSettingsPrompt => {
match self.app.data.lidarr_data.selected_block.get_active_block() {
ActiveLidarrBlock::IndexerSettingsConfirmPrompt => {
if self.app.data.lidarr_data.prompt_confirm {
self.app.data.lidarr_data.prompt_confirm_action = Some(
LidarrEvent::EditAllIndexerSettings(self.build_edit_indexer_settings_params()),
);
self.app.should_refresh = true;
} else {
self.app.data.lidarr_data.indexer_settings = None;
}
self.app.pop_navigation_stack();
}
ActiveLidarrBlock::IndexerSettingsMinimumAgeInput
| ActiveLidarrBlock::IndexerSettingsRetentionInput
| ActiveLidarrBlock::IndexerSettingsMaximumSizeInput
| ActiveLidarrBlock::IndexerSettingsRssSyncIntervalInput => {
self.app.push_navigation_stack(
(
self.app.data.lidarr_data.selected_block.get_active_block(),
None,
)
.into(),
)
}
_ => (),
}
}
ActiveLidarrBlock::IndexerSettingsMinimumAgeInput
| ActiveLidarrBlock::IndexerSettingsRetentionInput
| ActiveLidarrBlock::IndexerSettingsMaximumSizeInput
| ActiveLidarrBlock::IndexerSettingsRssSyncIntervalInput => self.app.pop_navigation_stack(),
_ => (),
}
}
fn handle_esc(&mut self) {
match self.active_lidarr_block {
ActiveLidarrBlock::AllIndexerSettingsPrompt => {
self.app.pop_navigation_stack();
self.app.data.lidarr_data.prompt_confirm = false;
self.app.data.lidarr_data.indexer_settings = None;
}
_ => self.app.pop_navigation_stack(),
}
}
fn handle_char_key_event(&mut self) {
if self.active_lidarr_block == ActiveLidarrBlock::AllIndexerSettingsPrompt
&& self.app.data.lidarr_data.selected_block.get_active_block()
== ActiveLidarrBlock::IndexerSettingsConfirmPrompt
&& matches_key!(confirm, self.key)
{
self.app.data.lidarr_data.prompt_confirm = true;
self.app.data.lidarr_data.prompt_confirm_action = Some(LidarrEvent::EditAllIndexerSettings(
self.build_edit_indexer_settings_params(),
));
self.app.should_refresh = true;
self.app.pop_navigation_stack();
}
}
fn app_mut(&mut self) -> &mut App<'b> {
self.app
}
fn current_route(&self) -> Route {
self.app.get_current_route()
}
}
@@ -0,0 +1,609 @@
#[cfg(test)]
mod tests {
use pretty_assertions::assert_eq;
use rstest::rstest;
use strum::IntoEnumIterator;
use crate::app::App;
use crate::app::key_binding::DEFAULT_KEYBINDINGS;
use crate::assert_modal_absent;
use crate::assert_navigation_pushed;
use crate::event::Key;
use crate::handlers::KeyEventHandler;
use crate::handlers::lidarr_handlers::indexers::edit_indexer_settings_handler::IndexerSettingsHandler;
use crate::models::servarr_data::lidarr::lidarr_data::{
ActiveLidarrBlock, INDEXER_SETTINGS_BLOCKS,
};
use crate::models::servarr_models::IndexerSettings;
use crate::network::lidarr_network::lidarr_network_test_utils::test_utils::indexer_settings;
mod test_handle_scroll_up_and_down {
use pretty_assertions::assert_eq;
use rstest::rstest;
use crate::models::BlockSelectionState;
use crate::models::servarr_data::lidarr::lidarr_data::INDEXER_SETTINGS_SELECTION_BLOCKS;
use crate::models::servarr_models::IndexerSettings;
use super::*;
macro_rules! test_i64_counter_scroll_value {
($block:expr, $key:expr, $data_ref:ident, $negatives:literal) => {
let mut app = App::test_default();
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
app.data.lidarr_data.indexer_settings = Some(IndexerSettings::default());
IndexerSettingsHandler::new($key, &mut app, $block, None).handle();
if $key == Key::Up {
assert_eq!(
app
.data
.lidarr_data
.indexer_settings
.as_ref()
.unwrap()
.$data_ref,
1
);
} else {
if $negatives {
assert_eq!(
app
.data
.lidarr_data
.indexer_settings
.as_ref()
.unwrap()
.$data_ref,
-1
);
} else {
assert_eq!(
app
.data
.lidarr_data
.indexer_settings
.as_ref()
.unwrap()
.$data_ref,
0
);
IndexerSettingsHandler::new(Key::Up, &mut app, $block, None).handle();
assert_eq!(
app
.data
.lidarr_data
.indexer_settings
.as_ref()
.unwrap()
.$data_ref,
1
);
IndexerSettingsHandler::new($key, &mut app, $block, None).handle();
assert_eq!(
app
.data
.lidarr_data
.indexer_settings
.as_ref()
.unwrap()
.$data_ref,
0
);
}
}
};
}
#[rstest]
fn test_edit_indexer_settings_prompt_scroll(#[values(Key::Up, Key::Down)] key: Key) {
let mut app = App::test_default();
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
app.data.lidarr_data.indexer_settings = Some(IndexerSettings::default());
app.data.lidarr_data.selected_block =
BlockSelectionState::new(INDEXER_SETTINGS_SELECTION_BLOCKS);
app.data.lidarr_data.selected_block.down();
IndexerSettingsHandler::new(
key,
&mut app,
ActiveLidarrBlock::AllIndexerSettingsPrompt,
None,
)
.handle();
if key == Key::Up {
assert_eq!(
app.data.lidarr_data.selected_block.get_active_block(),
ActiveLidarrBlock::IndexerSettingsMinimumAgeInput
);
} else {
assert_eq!(
app.data.lidarr_data.selected_block.get_active_block(),
ActiveLidarrBlock::IndexerSettingsMaximumSizeInput
);
}
}
#[rstest]
fn test_edit_indexer_settings_prompt_scroll_no_op_when_not_ready(
#[values(Key::Up, Key::Down)] key: Key,
) {
let mut app = App::test_default();
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
app.is_loading = true;
app.data.lidarr_data.indexer_settings = Some(IndexerSettings::default());
app.data.lidarr_data.selected_block =
BlockSelectionState::new(INDEXER_SETTINGS_SELECTION_BLOCKS);
app.data.lidarr_data.selected_block.down();
IndexerSettingsHandler::new(
key,
&mut app,
ActiveLidarrBlock::AllIndexerSettingsPrompt,
None,
)
.handle();
assert_eq!(
app.data.lidarr_data.selected_block.get_active_block(),
ActiveLidarrBlock::IndexerSettingsRetentionInput
);
}
#[rstest]
fn test_edit_indexer_settings_minimum_age_scroll(#[values(Key::Up, Key::Down)] key: Key) {
test_i64_counter_scroll_value!(
ActiveLidarrBlock::IndexerSettingsMinimumAgeInput,
key,
minimum_age,
false
);
}
#[rstest]
fn test_edit_indexer_settings_retention_scroll(#[values(Key::Up, Key::Down)] key: Key) {
test_i64_counter_scroll_value!(
ActiveLidarrBlock::IndexerSettingsRetentionInput,
key,
retention,
false
);
}
#[rstest]
fn test_edit_indexer_settings_maximum_size_scroll(#[values(Key::Up, Key::Down)] key: Key) {
test_i64_counter_scroll_value!(
ActiveLidarrBlock::IndexerSettingsMaximumSizeInput,
key,
maximum_size,
false
);
}
#[rstest]
fn test_edit_indexer_settings_rss_sync_interval_scroll(#[values(Key::Up, Key::Down)] key: Key) {
test_i64_counter_scroll_value!(
ActiveLidarrBlock::IndexerSettingsRssSyncIntervalInput,
key,
rss_sync_interval,
false
);
}
}
mod test_handle_left_right_action {
use crate::models::servarr_data::lidarr::lidarr_data::INDEXER_SETTINGS_SELECTION_BLOCKS;
use crate::models::BlockSelectionState;
use rstest::rstest;
use super::*;
#[rstest]
fn test_left_right_prompt_toggle(#[values(Key::Left, Key::Right)] key: Key) {
let mut app = App::test_default();
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
app.data.lidarr_data.selected_block =
BlockSelectionState::new(INDEXER_SETTINGS_SELECTION_BLOCKS);
app.data.lidarr_data.selected_block.y = INDEXER_SETTINGS_SELECTION_BLOCKS.len() - 1;
IndexerSettingsHandler::new(
key,
&mut app,
ActiveLidarrBlock::AllIndexerSettingsPrompt,
None,
)
.handle();
assert!(app.data.lidarr_data.prompt_confirm);
IndexerSettingsHandler::new(
key,
&mut app,
ActiveLidarrBlock::AllIndexerSettingsPrompt,
None,
)
.handle();
assert!(!app.data.lidarr_data.prompt_confirm);
}
}
mod test_handle_submit {
use pretty_assertions::assert_eq;
use rstest::rstest;
use crate::{
assert_navigation_popped,
models::{
BlockSelectionState, servarr_data::lidarr::lidarr_data::INDEXER_SETTINGS_SELECTION_BLOCKS,
servarr_models::IndexerSettings,
},
network::lidarr_network::LidarrEvent,
};
use super::*;
const SUBMIT_KEY: Key = DEFAULT_KEYBINDINGS.submit.key;
#[test]
fn test_edit_indexer_settings_prompt_prompt_decline_submit() {
let mut app = App::test_default();
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
app.push_navigation_stack(ActiveLidarrBlock::AllIndexerSettingsPrompt.into());
app.data.lidarr_data.selected_block =
BlockSelectionState::new(INDEXER_SETTINGS_SELECTION_BLOCKS);
app
.data
.lidarr_data
.selected_block
.set_index(0, INDEXER_SETTINGS_SELECTION_BLOCKS.len() - 1);
app.data.lidarr_data.indexer_settings = Some(IndexerSettings::default());
IndexerSettingsHandler::new(
SUBMIT_KEY,
&mut app,
ActiveLidarrBlock::AllIndexerSettingsPrompt,
None,
)
.handle();
assert_navigation_popped!(app, ActiveLidarrBlock::Indexers.into());
assert_none!(app.data.lidarr_data.prompt_confirm_action);
assert!(!app.should_refresh);
assert_none!(app.data.lidarr_data.indexer_settings);
}
#[test]
fn test_edit_indexer_settings_prompt_prompt_confirmation_submit() {
let mut app = App::test_default();
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
app.push_navigation_stack(ActiveLidarrBlock::AllIndexerSettingsPrompt.into());
app.data.lidarr_data.selected_block =
BlockSelectionState::new(INDEXER_SETTINGS_SELECTION_BLOCKS);
app
.data
.lidarr_data
.selected_block
.set_index(0, INDEXER_SETTINGS_SELECTION_BLOCKS.len() - 1);
app.data.lidarr_data.indexer_settings = Some(indexer_settings());
app.data.lidarr_data.prompt_confirm = true;
IndexerSettingsHandler::new(
SUBMIT_KEY,
&mut app,
ActiveLidarrBlock::AllIndexerSettingsPrompt,
None,
)
.handle();
assert_navigation_popped!(app, ActiveLidarrBlock::Indexers.into());
assert_some_eq_x!(
&app.data.lidarr_data.prompt_confirm_action,
&LidarrEvent::EditAllIndexerSettings(indexer_settings())
);
assert_modal_absent!(app.data.lidarr_data.indexer_settings);
assert!(app.should_refresh);
}
#[test]
fn test_edit_indexer_settings_prompt_prompt_confirmation_submit_no_op_when_not_ready() {
let mut app = App::test_default();
app.is_loading = true;
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
app.push_navigation_stack(ActiveLidarrBlock::AllIndexerSettingsPrompt.into());
app.data.lidarr_data.indexer_settings = Some(IndexerSettings::default());
app.data.lidarr_data.prompt_confirm = true;
IndexerSettingsHandler::new(
SUBMIT_KEY,
&mut app,
ActiveLidarrBlock::AllIndexerSettingsPrompt,
None,
)
.handle();
assert_eq!(
app.get_current_route(),
ActiveLidarrBlock::AllIndexerSettingsPrompt.into()
);
assert!(!app.should_refresh);
}
#[rstest]
#[case(ActiveLidarrBlock::IndexerSettingsMinimumAgeInput, 0)]
#[case(ActiveLidarrBlock::IndexerSettingsRetentionInput, 1)]
#[case(ActiveLidarrBlock::IndexerSettingsMaximumSizeInput, 2)]
#[case(ActiveLidarrBlock::IndexerSettingsRssSyncIntervalInput, 3)]
fn test_edit_indexer_settings_prompt_submit_selected_block(
#[case] selected_block: ActiveLidarrBlock,
#[case] y_index: usize,
) {
let mut app = App::test_default();
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
app.data.lidarr_data.indexer_settings = Some(IndexerSettings::default());
app.push_navigation_stack(ActiveLidarrBlock::AllIndexerSettingsPrompt.into());
app.data.lidarr_data.selected_block =
BlockSelectionState::new(INDEXER_SETTINGS_SELECTION_BLOCKS);
app.data.lidarr_data.selected_block.set_index(0, y_index);
IndexerSettingsHandler::new(
SUBMIT_KEY,
&mut app,
ActiveLidarrBlock::AllIndexerSettingsPrompt,
None,
)
.handle();
assert_navigation_pushed!(app, selected_block.into());
}
#[rstest]
fn test_edit_indexer_settings_prompt_submit_selected_block_no_op_when_not_ready(
#[values(0, 1, 2, 3, 4)] y_index: usize,
) {
let mut app = App::test_default();
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
app.is_loading = true;
app.data.lidarr_data.indexer_settings = Some(IndexerSettings::default());
app.push_navigation_stack(ActiveLidarrBlock::AllIndexerSettingsPrompt.into());
app.data.lidarr_data.selected_block =
BlockSelectionState::new(INDEXER_SETTINGS_SELECTION_BLOCKS);
app.data.lidarr_data.selected_block.set_index(0, y_index);
IndexerSettingsHandler::new(
SUBMIT_KEY,
&mut app,
ActiveLidarrBlock::AllIndexerSettingsPrompt,
None,
)
.handle();
assert_eq!(
app.get_current_route(),
ActiveLidarrBlock::AllIndexerSettingsPrompt.into()
);
}
#[rstest]
fn test_edit_indexer_settings_selected_block_submit(
#[values(
ActiveLidarrBlock::IndexerSettingsMinimumAgeInput,
ActiveLidarrBlock::IndexerSettingsRetentionInput,
ActiveLidarrBlock::IndexerSettingsMaximumSizeInput,
ActiveLidarrBlock::IndexerSettingsRssSyncIntervalInput
)]
active_lidarr_block: ActiveLidarrBlock,
) {
let mut app = App::test_default();
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
app.data.lidarr_data.indexer_settings = Some(IndexerSettings::default());
app.push_navigation_stack(ActiveLidarrBlock::AllIndexerSettingsPrompt.into());
app.push_navigation_stack(active_lidarr_block.into());
IndexerSettingsHandler::new(SUBMIT_KEY, &mut app, active_lidarr_block, None).handle();
assert_navigation_popped!(app, ActiveLidarrBlock::AllIndexerSettingsPrompt.into());
}
}
mod test_handle_esc {
use rstest::rstest;
use crate::models::servarr_models::IndexerSettings;
use super::*;
use crate::assert_navigation_popped;
const ESC_KEY: Key = DEFAULT_KEYBINDINGS.esc.key;
#[rstest]
fn test_edit_indexer_settings_prompt_esc(#[values(true, false)] is_ready: bool) {
let mut app = App::test_default();
app.is_loading = is_ready;
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
app.push_navigation_stack(ActiveLidarrBlock::AllIndexerSettingsPrompt.into());
app.data.lidarr_data.indexer_settings = Some(IndexerSettings::default());
IndexerSettingsHandler::new(
ESC_KEY,
&mut app,
ActiveLidarrBlock::AllIndexerSettingsPrompt,
None,
)
.handle();
assert_navigation_popped!(app, ActiveLidarrBlock::Indexers.into());
assert!(!app.data.lidarr_data.prompt_confirm);
assert_none!(app.data.lidarr_data.indexer_settings);
}
#[rstest]
fn test_edit_indexer_settings_selected_blocks_esc(
#[values(
ActiveLidarrBlock::IndexerSettingsMinimumAgeInput,
ActiveLidarrBlock::IndexerSettingsRetentionInput,
ActiveLidarrBlock::IndexerSettingsMaximumSizeInput,
ActiveLidarrBlock::IndexerSettingsRssSyncIntervalInput
)]
active_lidarr_block: ActiveLidarrBlock,
) {
let mut app = App::test_default();
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
app.push_navigation_stack(active_lidarr_block.into());
app.data.lidarr_data.indexer_settings = Some(IndexerSettings::default());
IndexerSettingsHandler::new(ESC_KEY, &mut app, active_lidarr_block, None).handle();
assert_navigation_popped!(app, ActiveLidarrBlock::Indexers.into());
assert_some_eq_x!(
&app.data.lidarr_data.indexer_settings,
&IndexerSettings::default()
);
}
}
mod test_handle_key_char {
use crate::{
assert_navigation_popped,
models::{
BlockSelectionState, servarr_data::lidarr::lidarr_data::INDEXER_SETTINGS_SELECTION_BLOCKS,
},
network::lidarr_network::LidarrEvent,
};
use super::*;
#[test]
fn test_edit_indexer_settings_prompt_prompt_confirmation_confirm() {
let mut app = App::test_default();
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
app.push_navigation_stack(ActiveLidarrBlock::AllIndexerSettingsPrompt.into());
app.data.lidarr_data.selected_block =
BlockSelectionState::new(INDEXER_SETTINGS_SELECTION_BLOCKS);
app
.data
.lidarr_data
.selected_block
.set_index(0, INDEXER_SETTINGS_SELECTION_BLOCKS.len() - 1);
app.data.lidarr_data.indexer_settings = Some(indexer_settings());
IndexerSettingsHandler::new(
DEFAULT_KEYBINDINGS.confirm.key,
&mut app,
ActiveLidarrBlock::AllIndexerSettingsPrompt,
None,
)
.handle();
assert_navigation_popped!(app, ActiveLidarrBlock::Indexers.into());
assert_some_eq_x!(
&app.data.lidarr_data.prompt_confirm_action,
&LidarrEvent::EditAllIndexerSettings(indexer_settings())
);
assert_modal_absent!(app.data.lidarr_data.indexer_settings);
assert!(app.should_refresh);
}
}
#[test]
fn test_indexer_settings_handler_accepts() {
ActiveLidarrBlock::iter().for_each(|active_lidarr_block| {
if INDEXER_SETTINGS_BLOCKS.contains(&active_lidarr_block) {
assert!(IndexerSettingsHandler::accepts(active_lidarr_block));
} else {
assert!(!IndexerSettingsHandler::accepts(active_lidarr_block));
}
})
}
#[rstest]
fn test_indexer_settings_handler_ignore_special_keys(
#[values(true, false)] ignore_special_keys_for_textbox_input: bool,
) {
let mut app = App::test_default();
app.ignore_special_keys_for_textbox_input = ignore_special_keys_for_textbox_input;
let handler = IndexerSettingsHandler::new(
DEFAULT_KEYBINDINGS.esc.key,
&mut app,
ActiveLidarrBlock::default(),
None,
);
assert_eq!(
handler.ignore_special_keys(),
ignore_special_keys_for_textbox_input
);
}
#[test]
fn test_build_edit_indexer_settings_params() {
let mut app = App::test_default();
app.data.lidarr_data.indexer_settings = Some(indexer_settings());
let actual_indexer_settings = IndexerSettingsHandler::new(
DEFAULT_KEYBINDINGS.esc.key,
&mut app,
ActiveLidarrBlock::AllIndexerSettingsPrompt,
None,
)
.build_edit_indexer_settings_params();
assert_eq!(actual_indexer_settings, indexer_settings());
assert_modal_absent!(app.data.lidarr_data.indexer_settings);
}
#[test]
fn test_edit_indexer_settings_handler_not_ready_when_loading() {
let mut app = App::test_default();
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
app.is_loading = true;
let handler = IndexerSettingsHandler::new(
DEFAULT_KEYBINDINGS.esc.key,
&mut app,
ActiveLidarrBlock::AllIndexerSettingsPrompt,
None,
);
assert!(!handler.is_ready());
}
#[test]
fn test_edit_indexer_settings_handler_not_ready_when_indexer_settings_is_none() {
let mut app = App::test_default();
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
app.is_loading = false;
let handler = IndexerSettingsHandler::new(
DEFAULT_KEYBINDINGS.esc.key,
&mut app,
ActiveLidarrBlock::AllIndexerSettingsPrompt,
None,
);
assert!(!handler.is_ready());
}
#[test]
fn test_edit_indexer_settings_handler_ready_when_not_loading_and_indexer_settings_is_some() {
let mut app = App::test_default();
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
app.is_loading = false;
app.data.lidarr_data.indexer_settings = Some(IndexerSettings::default());
let handler = IndexerSettingsHandler::new(
DEFAULT_KEYBINDINGS.esc.key,
&mut app,
ActiveLidarrBlock::AllIndexerSettingsPrompt,
None,
);
assert!(handler.is_ready());
}
}
@@ -0,0 +1,717 @@
#[cfg(test)]
mod tests {
use pretty_assertions::assert_eq;
use rstest::rstest;
use strum::IntoEnumIterator;
use crate::app::App;
use crate::app::key_binding::DEFAULT_KEYBINDINGS;
use crate::assert_navigation_pushed;
use crate::event::Key;
use crate::handlers::KeyEventHandler;
use crate::handlers::lidarr_handlers::indexers::IndexersHandler;
use crate::models::servarr_data::lidarr::lidarr_data::{
ActiveLidarrBlock, EDIT_INDEXER_BLOCKS, INDEXER_SETTINGS_BLOCKS, INDEXERS_BLOCKS,
};
use crate::models::servarr_models::Indexer;
use crate::network::lidarr_network::lidarr_network_test_utils::test_utils::indexer;
use crate::test_handler_delegation;
mod test_handle_delete {
use pretty_assertions::assert_eq;
use super::*;
const DELETE_KEY: Key = DEFAULT_KEYBINDINGS.delete.key;
#[test]
fn test_delete_indexer_prompt() {
let mut app = App::test_default();
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
app
.data
.lidarr_data
.indexers
.set_items(vec![Indexer::default()]);
IndexersHandler::new(DELETE_KEY, &mut app, ActiveLidarrBlock::Indexers, None).handle();
assert_navigation_pushed!(app, ActiveLidarrBlock::DeleteIndexerPrompt.into());
}
#[test]
fn test_delete_indexer_prompt_no_op_when_not_ready() {
let mut app = App::test_default();
app.is_loading = true;
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
app
.data
.lidarr_data
.indexers
.set_items(vec![Indexer::default()]);
IndexersHandler::new(DELETE_KEY, &mut app, ActiveLidarrBlock::Indexers, None).handle();
assert_eq!(app.get_current_route(), ActiveLidarrBlock::Indexers.into());
}
}
mod test_handle_left_right_action {
use pretty_assertions::assert_eq;
use rstest::rstest;
use super::*;
#[rstest]
fn test_indexers_tab_left(#[values(true, false)] is_ready: bool) {
let mut app = App::test_default();
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
app.is_loading = is_ready;
app.data.lidarr_data.main_tabs.set_index(4);
IndexersHandler::new(
DEFAULT_KEYBINDINGS.left.key,
&mut app,
ActiveLidarrBlock::Indexers,
None,
)
.handle();
assert_eq!(
app.data.lidarr_data.main_tabs.get_active_route(),
ActiveLidarrBlock::RootFolders.into()
);
assert_navigation_pushed!(app, ActiveLidarrBlock::RootFolders.into());
}
#[rstest]
fn test_indexers_tab_right(#[values(true, false)] is_ready: bool) {
let mut app = App::test_default();
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
app.is_loading = is_ready;
app.data.lidarr_data.main_tabs.set_index(4);
IndexersHandler::new(
DEFAULT_KEYBINDINGS.right.key,
&mut app,
ActiveLidarrBlock::Indexers,
None,
)
.handle();
assert_eq!(
app.data.lidarr_data.main_tabs.get_active_route(),
ActiveLidarrBlock::Artists.into()
);
assert_navigation_pushed!(app, ActiveLidarrBlock::Artists.into());
}
#[rstest]
fn test_left_right_delete_indexer_prompt_toggle(
#[values(DEFAULT_KEYBINDINGS.left.key, DEFAULT_KEYBINDINGS.right.key)] key: Key,
) {
let mut app = App::test_default();
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
IndexersHandler::new(key, &mut app, ActiveLidarrBlock::DeleteIndexerPrompt, None).handle();
assert!(app.data.lidarr_data.prompt_confirm);
IndexersHandler::new(key, &mut app, ActiveLidarrBlock::DeleteIndexerPrompt, None).handle();
assert!(!app.data.lidarr_data.prompt_confirm);
}
}
mod test_handle_submit {
use super::*;
use crate::assert_navigation_popped;
use crate::models::servarr_data::lidarr::lidarr_data::{
EDIT_INDEXER_NZB_SELECTION_BLOCKS, EDIT_INDEXER_TORRENT_SELECTION_BLOCKS, LidarrData,
};
use crate::models::servarr_data::modals::EditIndexerModal;
use crate::models::servarr_models::{Indexer, IndexerField};
use crate::network::lidarr_network::LidarrEvent;
use crate::network::lidarr_network::lidarr_network_test_utils::test_utils::indexer;
use bimap::BiMap;
use pretty_assertions::assert_eq;
use serde_json::{Number, Value};
const SUBMIT_KEY: Key = DEFAULT_KEYBINDINGS.submit.key;
#[rstest]
fn test_edit_indexer_submit(#[values(true, false)] torrent_protocol: bool) {
let mut app = App::test_default();
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
let protocol = if torrent_protocol {
"torrent".to_owned()
} else {
"usenet".to_owned()
};
let mut expected_edit_indexer_modal = EditIndexerModal {
name: "Test".into(),
enable_rss: Some(true),
enable_automatic_search: Some(true),
enable_interactive_search: Some(true),
url: "https://test.com".into(),
api_key: "1234".into(),
tags: "usenet, test".into(),
..EditIndexerModal::default()
};
let mut lidarr_data = LidarrData {
tags_map: BiMap::from_iter([(1, "usenet".to_owned()), (2, "test".to_owned())]),
..LidarrData::default()
};
let mut fields = vec![
IndexerField {
name: Some("baseUrl".to_owned()),
value: Some(Value::String("https://test.com".to_owned())),
},
IndexerField {
name: Some("apiKey".to_owned()),
value: Some(Value::String("1234".to_owned())),
},
];
if torrent_protocol {
fields.push(IndexerField {
name: Some("seedCriteria.seedRatio".to_owned()),
value: Some(Value::from(1.2f64)),
});
expected_edit_indexer_modal.seed_ratio = "1.2".into();
}
let indexer = Indexer {
name: Some("Test".to_owned()),
enable_rss: true,
enable_automatic_search: true,
enable_interactive_search: true,
protocol,
tags: vec![Number::from(1), Number::from(2)],
fields: Some(fields),
..Indexer::default()
};
lidarr_data.indexers.set_items(vec![indexer]);
app.data.lidarr_data = lidarr_data;
IndexersHandler::new(SUBMIT_KEY, &mut app, ActiveLidarrBlock::Indexers, None).handle();
assert_navigation_pushed!(app, ActiveLidarrBlock::EditIndexerPrompt.into());
assert_some_eq_x!(
&app.data.lidarr_data.edit_indexer_modal,
&EditIndexerModal::from(&app.data.lidarr_data)
);
assert_some_eq_x!(
&app.data.lidarr_data.edit_indexer_modal,
&expected_edit_indexer_modal
);
if torrent_protocol {
assert_eq!(
app.data.lidarr_data.selected_block.blocks,
EDIT_INDEXER_TORRENT_SELECTION_BLOCKS
);
} else {
assert_eq!(
app.data.lidarr_data.selected_block.blocks,
EDIT_INDEXER_NZB_SELECTION_BLOCKS
);
}
}
#[test]
fn test_edit_indexer_submit_no_op_when_not_ready() {
let mut app = App::test_default();
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
app.is_loading = true;
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
app
.data
.lidarr_data
.indexers
.set_items(vec![Indexer::default()]);
IndexersHandler::new(SUBMIT_KEY, &mut app, ActiveLidarrBlock::Indexers, None).handle();
assert_eq!(app.get_current_route(), ActiveLidarrBlock::Indexers.into());
assert_none!(app.data.lidarr_data.edit_indexer_modal);
}
#[test]
fn test_delete_indexer_prompt_confirm_submit() {
let mut app = App::test_default();
app.data.lidarr_data.indexers.set_items(vec![indexer()]);
app.data.lidarr_data.prompt_confirm = true;
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
app.push_navigation_stack(ActiveLidarrBlock::DeleteIndexerPrompt.into());
IndexersHandler::new(
SUBMIT_KEY,
&mut app,
ActiveLidarrBlock::DeleteIndexerPrompt,
None,
)
.handle();
assert!(app.data.lidarr_data.prompt_confirm);
assert_some_eq_x!(
&app.data.lidarr_data.prompt_confirm_action,
&LidarrEvent::DeleteIndexer(1)
);
assert_navigation_popped!(app, ActiveLidarrBlock::Indexers.into());
}
#[test]
fn test_prompt_decline_submit() {
let mut app = App::test_default();
app
.data
.lidarr_data
.indexers
.set_items(vec![Indexer::default()]);
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
app.push_navigation_stack(ActiveLidarrBlock::DeleteIndexerPrompt.into());
IndexersHandler::new(
SUBMIT_KEY,
&mut app,
ActiveLidarrBlock::DeleteIndexerPrompt,
None,
)
.handle();
assert!(!app.data.lidarr_data.prompt_confirm);
assert_none!(app.data.lidarr_data.prompt_confirm_action);
assert_navigation_popped!(app, ActiveLidarrBlock::Indexers.into());
}
}
mod test_handle_esc {
use super::*;
use crate::assert_navigation_popped;
const ESC_KEY: Key = DEFAULT_KEYBINDINGS.esc.key;
#[rstest]
fn test_delete_indexer_prompt_block_esc(#[values(true, false)] is_ready: bool) {
let mut app = App::test_default();
app.is_loading = is_ready;
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
app.push_navigation_stack(ActiveLidarrBlock::DeleteIndexerPrompt.into());
app.data.lidarr_data.prompt_confirm = true;
IndexersHandler::new(
ESC_KEY,
&mut app,
ActiveLidarrBlock::DeleteIndexerPrompt,
None,
)
.handle();
assert_navigation_popped!(app, ActiveLidarrBlock::Indexers.into());
assert!(!app.data.lidarr_data.prompt_confirm);
}
#[rstest]
fn test_test_indexer_esc(#[values(true, false)] is_ready: bool) {
let mut app = App::test_default();
app.is_loading = is_ready;
app.data.lidarr_data.indexer_test_errors = Some("test result".to_owned());
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
app.push_navigation_stack(ActiveLidarrBlock::TestIndexer.into());
IndexersHandler::new(ESC_KEY, &mut app, ActiveLidarrBlock::TestIndexer, None).handle();
assert_navigation_popped!(app, ActiveLidarrBlock::Indexers.into());
assert_none!(app.data.lidarr_data.indexer_test_errors);
}
#[rstest]
fn test_default_esc(#[values(true, false)] is_ready: bool) {
let mut app = App::test_default();
app.is_loading = is_ready;
app.error = "test error".to_owned().into();
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
IndexersHandler::new(ESC_KEY, &mut app, ActiveLidarrBlock::Indexers, None).handle();
assert_navigation_popped!(app, ActiveLidarrBlock::Indexers.into());
assert_is_empty!(app.error.text);
}
}
mod test_handle_key_char {
use pretty_assertions::assert_eq;
use super::*;
use crate::network::lidarr_network::lidarr_network_test_utils::test_utils::indexer;
use crate::{
assert_navigation_popped,
models::servarr_data::lidarr::lidarr_data::INDEXER_SETTINGS_SELECTION_BLOCKS,
network::lidarr_network::LidarrEvent,
};
#[test]
fn test_refresh_indexers_key() {
let mut app = App::test_default();
app
.data
.lidarr_data
.indexers
.set_items(vec![Indexer::default()]);
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
IndexersHandler::new(
DEFAULT_KEYBINDINGS.refresh.key,
&mut app,
ActiveLidarrBlock::Indexers,
None,
)
.handle();
assert_navigation_pushed!(app, ActiveLidarrBlock::Indexers.into());
assert!(app.should_refresh);
}
#[test]
fn test_refresh_indexers_key_no_op_when_not_ready() {
let mut app = App::test_default();
app.is_loading = true;
app
.data
.lidarr_data
.indexers
.set_items(vec![Indexer::default()]);
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
IndexersHandler::new(
DEFAULT_KEYBINDINGS.refresh.key,
&mut app,
ActiveLidarrBlock::Indexers,
None,
)
.handle();
assert_eq!(app.get_current_route(), ActiveLidarrBlock::Indexers.into());
assert!(!app.should_refresh);
}
#[test]
fn test_indexer_settings_key() {
let mut app = App::test_default();
app
.data
.lidarr_data
.indexers
.set_items(vec![Indexer::default()]);
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
app
.data
.lidarr_data
.indexers
.set_items(vec![Indexer::default()]);
IndexersHandler::new(
DEFAULT_KEYBINDINGS.settings.key,
&mut app,
ActiveLidarrBlock::Indexers,
None,
)
.handle();
assert_navigation_pushed!(app, ActiveLidarrBlock::AllIndexerSettingsPrompt.into());
assert_eq!(
app.data.lidarr_data.selected_block.blocks,
INDEXER_SETTINGS_SELECTION_BLOCKS
);
}
#[test]
fn test_indexer_settings_key_no_op_when_not_ready() {
let mut app = App::test_default();
app.is_loading = true;
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
app
.data
.lidarr_data
.indexers
.set_items(vec![Indexer::default()]);
IndexersHandler::new(
DEFAULT_KEYBINDINGS.settings.key,
&mut app,
ActiveLidarrBlock::Indexers,
None,
)
.handle();
assert_eq!(app.get_current_route(), ActiveLidarrBlock::Indexers.into());
}
#[test]
fn test_test_key() {
let mut app = App::test_default();
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
app
.data
.lidarr_data
.indexers
.set_items(vec![Indexer::default()]);
IndexersHandler::new(
DEFAULT_KEYBINDINGS.test.key,
&mut app,
ActiveLidarrBlock::Indexers,
None,
)
.handle();
assert_navigation_pushed!(app, ActiveLidarrBlock::TestIndexer.into());
}
#[test]
fn test_test_key_no_op_when_not_ready() {
let mut app = App::test_default();
app.is_loading = true;
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
app
.data
.lidarr_data
.indexers
.set_items(vec![Indexer::default()]);
IndexersHandler::new(
DEFAULT_KEYBINDINGS.test.key,
&mut app,
ActiveLidarrBlock::Indexers,
None,
)
.handle();
assert_eq!(app.get_current_route(), ActiveLidarrBlock::Indexers.into());
}
#[test]
fn test_test_all_key() {
let mut app = App::test_default();
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
app
.data
.lidarr_data
.indexers
.set_items(vec![Indexer::default()]);
IndexersHandler::new(
DEFAULT_KEYBINDINGS.test_all.key,
&mut app,
ActiveLidarrBlock::Indexers,
None,
)
.handle();
assert_navigation_pushed!(app, ActiveLidarrBlock::TestAllIndexers.into());
}
#[test]
fn test_test_all_key_no_op_when_not_ready() {
let mut app = App::test_default();
app.is_loading = true;
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
app
.data
.lidarr_data
.indexers
.set_items(vec![Indexer::default()]);
IndexersHandler::new(
DEFAULT_KEYBINDINGS.test_all.key,
&mut app,
ActiveLidarrBlock::Indexers,
None,
)
.handle();
assert_eq!(app.get_current_route(), ActiveLidarrBlock::Indexers.into());
}
#[test]
fn test_delete_indexer_prompt_confirm() {
let mut app = App::test_default();
app.data.lidarr_data.indexers.set_items(vec![indexer()]);
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
app.push_navigation_stack(ActiveLidarrBlock::DeleteIndexerPrompt.into());
IndexersHandler::new(
DEFAULT_KEYBINDINGS.confirm.key,
&mut app,
ActiveLidarrBlock::DeleteIndexerPrompt,
None,
)
.handle();
assert!(app.data.lidarr_data.prompt_confirm);
assert_some_eq_x!(
&app.data.lidarr_data.prompt_confirm_action,
&LidarrEvent::DeleteIndexer(1)
);
assert_navigation_popped!(app, ActiveLidarrBlock::Indexers.into());
}
}
#[rstest]
fn test_delegates_edit_indexer_blocks_to_edit_indexer_handler(
#[values(
ActiveLidarrBlock::EditIndexerPrompt,
ActiveLidarrBlock::EditIndexerConfirmPrompt,
ActiveLidarrBlock::EditIndexerApiKeyInput,
ActiveLidarrBlock::EditIndexerNameInput,
ActiveLidarrBlock::EditIndexerSeedRatioInput,
ActiveLidarrBlock::EditIndexerToggleEnableRss,
ActiveLidarrBlock::EditIndexerToggleEnableAutomaticSearch,
ActiveLidarrBlock::EditIndexerToggleEnableInteractiveSearch,
ActiveLidarrBlock::EditIndexerUrlInput,
ActiveLidarrBlock::EditIndexerTagsInput
)]
active_lidarr_block: ActiveLidarrBlock,
) {
test_handler_delegation!(
IndexersHandler,
ActiveLidarrBlock::Indexers,
active_lidarr_block
);
}
#[rstest]
fn test_delegates_indexer_settings_blocks_to_indexer_settings_handler(
#[values(
ActiveLidarrBlock::AllIndexerSettingsPrompt,
ActiveLidarrBlock::IndexerSettingsConfirmPrompt,
ActiveLidarrBlock::IndexerSettingsMaximumSizeInput,
ActiveLidarrBlock::IndexerSettingsMinimumAgeInput,
ActiveLidarrBlock::IndexerSettingsRetentionInput,
ActiveLidarrBlock::IndexerSettingsRssSyncIntervalInput
)]
active_lidarr_block: ActiveLidarrBlock,
) {
test_handler_delegation!(
IndexersHandler,
ActiveLidarrBlock::Indexers,
active_lidarr_block
);
}
#[test]
fn test_delegates_test_all_indexers_block_to_test_all_indexers_handler() {
test_handler_delegation!(
IndexersHandler,
ActiveLidarrBlock::Indexers,
ActiveLidarrBlock::TestAllIndexers
);
}
#[test]
fn test_indexers_handler_accepts() {
let mut indexers_blocks = Vec::new();
indexers_blocks.extend(INDEXERS_BLOCKS);
indexers_blocks.extend(INDEXER_SETTINGS_BLOCKS);
indexers_blocks.extend(EDIT_INDEXER_BLOCKS);
indexers_blocks.push(ActiveLidarrBlock::TestAllIndexers);
ActiveLidarrBlock::iter().for_each(|active_lidarr_block| {
if indexers_blocks.contains(&active_lidarr_block) {
assert!(IndexersHandler::accepts(active_lidarr_block));
} else {
assert!(!IndexersHandler::accepts(active_lidarr_block));
}
})
}
#[rstest]
fn test_indexers_handler_ignore_special_keys(
#[values(true, false)] ignore_special_keys_for_textbox_input: bool,
) {
let mut app = App::test_default();
app.ignore_special_keys_for_textbox_input = ignore_special_keys_for_textbox_input;
let handler = IndexersHandler::new(
DEFAULT_KEYBINDINGS.esc.key,
&mut app,
ActiveLidarrBlock::default(),
None,
);
assert_eq!(
handler.ignore_special_keys(),
ignore_special_keys_for_textbox_input
);
}
#[test]
fn test_extract_indexer_id() {
let mut app = App::test_default();
app.data.lidarr_data.indexers.set_items(vec![indexer()]);
let indexer_id = IndexersHandler::new(
DEFAULT_KEYBINDINGS.esc.key,
&mut app,
ActiveLidarrBlock::Indexers,
None,
)
.extract_indexer_id();
assert_eq!(indexer_id, 1);
}
#[test]
fn test_indexers_handler_not_ready_when_loading() {
let mut app = App::test_default();
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
app.is_loading = true;
let handler = IndexersHandler::new(
DEFAULT_KEYBINDINGS.esc.key,
&mut app,
ActiveLidarrBlock::Indexers,
None,
);
assert!(!handler.is_ready());
}
#[test]
fn test_indexers_handler_not_ready_when_indexers_is_empty() {
let mut app = App::test_default();
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
app.is_loading = false;
let handler = IndexersHandler::new(
DEFAULT_KEYBINDINGS.esc.key,
&mut app,
ActiveLidarrBlock::Indexers,
None,
);
assert!(!handler.is_ready());
}
#[test]
fn test_indexers_handler_ready_when_not_loading_and_indexers_is_not_empty() {
let mut app = App::test_default();
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
app.is_loading = false;
app
.data
.lidarr_data
.indexers
.set_items(vec![Indexer::default()]);
let handler = IndexersHandler::new(
DEFAULT_KEYBINDINGS.esc.key,
&mut app,
ActiveLidarrBlock::Indexers,
None,
);
assert!(handler.is_ready());
}
}
@@ -0,0 +1,217 @@
use crate::app::App;
use crate::event::Key;
use crate::handlers::lidarr_handlers::handle_change_tab_left_right_keys;
use crate::handlers::lidarr_handlers::indexers::edit_indexer_handler::EditIndexerHandler;
use crate::handlers::lidarr_handlers::indexers::edit_indexer_settings_handler::IndexerSettingsHandler;
use crate::handlers::lidarr_handlers::indexers::test_all_indexers_handler::TestAllIndexersHandler;
use crate::handlers::table_handler::{TableHandlingConfig, handle_table};
use crate::handlers::{KeyEventHandler, handle_clear_errors, handle_prompt_toggle};
use crate::matches_key;
use crate::models::servarr_data::lidarr::lidarr_data::{
ActiveLidarrBlock, EDIT_INDEXER_NZB_SELECTION_BLOCKS, EDIT_INDEXER_TORRENT_SELECTION_BLOCKS,
INDEXER_SETTINGS_SELECTION_BLOCKS, INDEXERS_BLOCKS,
};
use crate::models::{BlockSelectionState, Route};
use crate::network::lidarr_network::LidarrEvent;
mod edit_indexer_handler;
mod edit_indexer_settings_handler;
mod test_all_indexers_handler;
#[cfg(test)]
#[path = "indexers_handler_tests.rs"]
mod indexers_handler_tests;
pub(super) struct IndexersHandler<'a, 'b> {
key: Key,
app: &'a mut App<'b>,
active_lidarr_block: ActiveLidarrBlock,
context: Option<ActiveLidarrBlock>,
}
impl IndexersHandler<'_, '_> {
fn extract_indexer_id(&self) -> i64 {
self.app.data.lidarr_data.indexers.current_selection().id
}
}
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveLidarrBlock> for IndexersHandler<'a, 'b> {
fn handle(&mut self) {
let indexers_table_handling_config =
TableHandlingConfig::new(ActiveLidarrBlock::Indexers.into());
if !handle_table(
self,
|app| &mut app.data.lidarr_data.indexers,
indexers_table_handling_config,
) {
match self.active_lidarr_block {
_ if EditIndexerHandler::accepts(self.active_lidarr_block) => {
EditIndexerHandler::new(self.key, self.app, self.active_lidarr_block, self.context)
.handle()
}
_ if IndexerSettingsHandler::accepts(self.active_lidarr_block) => {
IndexerSettingsHandler::new(self.key, self.app, self.active_lidarr_block, self.context)
.handle()
}
_ if TestAllIndexersHandler::accepts(self.active_lidarr_block) => {
TestAllIndexersHandler::new(self.key, self.app, self.active_lidarr_block, self.context)
.handle()
}
_ => self.handle_key_event(),
}
}
}
fn accepts(active_block: ActiveLidarrBlock) -> bool {
EditIndexerHandler::accepts(active_block)
|| IndexerSettingsHandler::accepts(active_block)
|| TestAllIndexersHandler::accepts(active_block)
|| INDEXERS_BLOCKS.contains(&active_block)
}
fn ignore_special_keys(&self) -> bool {
self.app.ignore_special_keys_for_textbox_input
}
fn new(
key: Key,
app: &'a mut App<'b>,
active_block: ActiveLidarrBlock,
context: Option<ActiveLidarrBlock>,
) -> IndexersHandler<'a, 'b> {
IndexersHandler {
key,
app,
active_lidarr_block: active_block,
context,
}
}
fn get_key(&self) -> Key {
self.key
}
fn is_ready(&self) -> bool {
!self.app.is_loading && !self.app.data.lidarr_data.indexers.is_empty()
}
fn handle_scroll_up(&mut self) {}
fn handle_scroll_down(&mut self) {}
fn handle_home(&mut self) {}
fn handle_end(&mut self) {}
fn handle_delete(&mut self) {
if self.active_lidarr_block == ActiveLidarrBlock::Indexers {
self
.app
.push_navigation_stack(ActiveLidarrBlock::DeleteIndexerPrompt.into());
}
}
fn handle_left_right_action(&mut self) {
match self.active_lidarr_block {
ActiveLidarrBlock::Indexers => handle_change_tab_left_right_keys(self.app, self.key),
ActiveLidarrBlock::DeleteIndexerPrompt => handle_prompt_toggle(self.app, self.key),
_ => (),
}
}
fn handle_submit(&mut self) {
match self.active_lidarr_block {
ActiveLidarrBlock::DeleteIndexerPrompt => {
if self.app.data.lidarr_data.prompt_confirm {
self.app.data.lidarr_data.prompt_confirm_action =
Some(LidarrEvent::DeleteIndexer(self.extract_indexer_id()));
}
self.app.pop_navigation_stack();
}
ActiveLidarrBlock::Indexers => {
self
.app
.push_navigation_stack(ActiveLidarrBlock::EditIndexerPrompt.into());
self.app.data.lidarr_data.edit_indexer_modal = Some((&self.app.data.lidarr_data).into());
let protocol = &self
.app
.data
.lidarr_data
.indexers
.current_selection()
.protocol;
if protocol == "torrent" {
self.app.data.lidarr_data.selected_block =
BlockSelectionState::new(EDIT_INDEXER_TORRENT_SELECTION_BLOCKS);
} else {
self.app.data.lidarr_data.selected_block =
BlockSelectionState::new(EDIT_INDEXER_NZB_SELECTION_BLOCKS);
}
}
_ => (),
}
}
fn handle_esc(&mut self) {
match self.active_lidarr_block {
ActiveLidarrBlock::DeleteIndexerPrompt => {
self.app.pop_navigation_stack();
self.app.data.lidarr_data.prompt_confirm = false;
}
ActiveLidarrBlock::TestIndexer => {
self.app.pop_navigation_stack();
self.app.data.lidarr_data.indexer_test_errors = None;
}
_ => handle_clear_errors(self.app),
}
}
fn handle_char_key_event(&mut self) {
let key = self.key;
match self.active_lidarr_block {
ActiveLidarrBlock::Indexers => match self.key {
_ if matches_key!(refresh, key) => {
self.app.should_refresh = true;
}
_ if matches_key!(test, key) => {
self
.app
.push_navigation_stack(ActiveLidarrBlock::TestIndexer.into());
}
_ if matches_key!(test_all, key) => {
self
.app
.push_navigation_stack(ActiveLidarrBlock::TestAllIndexers.into());
}
_ if matches_key!(settings, key) => {
self
.app
.push_navigation_stack(ActiveLidarrBlock::AllIndexerSettingsPrompt.into());
self.app.data.lidarr_data.selected_block =
BlockSelectionState::new(INDEXER_SETTINGS_SELECTION_BLOCKS);
}
_ => (),
},
ActiveLidarrBlock::DeleteIndexerPrompt => {
if matches_key!(confirm, key) {
self.app.data.lidarr_data.prompt_confirm = true;
self.app.data.lidarr_data.prompt_confirm_action =
Some(LidarrEvent::DeleteIndexer(self.extract_indexer_id()));
self.app.pop_navigation_stack();
}
}
_ => (),
}
}
fn app_mut(&mut self) -> &mut App<'b> {
self.app
}
fn current_route(&self) -> Route {
self.app.get_current_route()
}
}
@@ -0,0 +1,108 @@
use crate::app::App;
use crate::event::Key;
use crate::handlers::KeyEventHandler;
use crate::handlers::table_handler::{TableHandlingConfig, handle_table};
use crate::models::Route;
use crate::models::servarr_data::lidarr::lidarr_data::ActiveLidarrBlock;
#[cfg(test)]
#[path = "test_all_indexers_handler_tests.rs"]
mod test_all_indexers_handler_tests;
pub(super) struct TestAllIndexersHandler<'a, 'b> {
key: Key,
app: &'a mut App<'b>,
active_lidarr_block: ActiveLidarrBlock,
_context: Option<ActiveLidarrBlock>,
}
impl TestAllIndexersHandler<'_, '_> {}
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveLidarrBlock> for TestAllIndexersHandler<'a, 'b> {
fn handle(&mut self) {
let indexer_test_all_results_table_handling_config =
TableHandlingConfig::new(ActiveLidarrBlock::TestAllIndexers.into());
if !handle_table(
self,
|app| {
app
.data
.lidarr_data
.indexer_test_all_results
.as_mut()
.unwrap()
},
indexer_test_all_results_table_handling_config,
) {
self.handle_key_event();
}
}
fn accepts(active_block: ActiveLidarrBlock) -> bool {
active_block == ActiveLidarrBlock::TestAllIndexers
}
fn ignore_special_keys(&self) -> bool {
self.app.ignore_special_keys_for_textbox_input
}
fn new(
key: Key,
app: &'a mut App<'b>,
active_block: ActiveLidarrBlock,
_context: Option<ActiveLidarrBlock>,
) -> TestAllIndexersHandler<'a, 'b> {
TestAllIndexersHandler {
key,
app,
active_lidarr_block: active_block,
_context,
}
}
fn get_key(&self) -> Key {
self.key
}
fn is_ready(&self) -> bool {
let table_is_ready = if let Some(table) = &self.app.data.lidarr_data.indexer_test_all_results {
!table.is_empty()
} else {
false
};
!self.app.is_loading && table_is_ready
}
fn handle_scroll_up(&mut self) {}
fn handle_scroll_down(&mut self) {}
fn handle_home(&mut self) {}
fn handle_end(&mut self) {}
fn handle_delete(&mut self) {}
fn handle_left_right_action(&mut self) {}
fn handle_submit(&mut self) {}
fn handle_esc(&mut self) {
if self.active_lidarr_block == ActiveLidarrBlock::TestAllIndexers {
self.app.pop_navigation_stack();
self.app.data.lidarr_data.indexer_test_all_results = None;
}
}
fn handle_char_key_event(&mut self) {}
fn app_mut(&mut self) -> &mut App<'b> {
self.app
}
fn current_route(&self) -> Route {
self.app.get_current_route()
}
}
@@ -0,0 +1,133 @@
#[cfg(test)]
mod tests {
use crate::app::App;
use crate::app::key_binding::DEFAULT_KEYBINDINGS;
use crate::assert_navigation_popped;
use crate::handlers::KeyEventHandler;
use crate::handlers::lidarr_handlers::indexers::test_all_indexers_handler::TestAllIndexersHandler;
use crate::models::servarr_data::lidarr::lidarr_data::ActiveLidarrBlock;
use crate::models::servarr_data::modals::IndexerTestResultModalItem;
use crate::models::stateful_table::StatefulTable;
use pretty_assertions::assert_eq;
use rstest::rstest;
use strum::IntoEnumIterator;
mod test_handle_esc {
use super::*;
const ESC_KEY: crate::event::Key = DEFAULT_KEYBINDINGS.esc.key;
#[rstest]
fn test_test_all_indexers_prompt_esc(#[values(true, false)] is_ready: bool) {
let mut app = App::test_default();
app.is_loading = is_ready;
app.push_navigation_stack(ActiveLidarrBlock::Indexers.into());
app.push_navigation_stack(ActiveLidarrBlock::TestAllIndexers.into());
app.data.lidarr_data.indexer_test_all_results = Some(StatefulTable::default());
TestAllIndexersHandler::new(ESC_KEY, &mut app, ActiveLidarrBlock::TestAllIndexers, None)
.handle();
assert_navigation_popped!(app, ActiveLidarrBlock::Indexers.into());
assert_none!(app.data.lidarr_data.indexer_test_all_results);
}
}
#[test]
fn test_test_all_indexers_handler_accepts() {
ActiveLidarrBlock::iter().for_each(|active_lidarr_block| {
if active_lidarr_block == ActiveLidarrBlock::TestAllIndexers {
assert!(TestAllIndexersHandler::accepts(active_lidarr_block));
} else {
assert!(!TestAllIndexersHandler::accepts(active_lidarr_block));
}
})
}
#[rstest]
fn test_test_all_indexers_handler_ignore_special_keys(
#[values(true, false)] ignore_special_keys_for_textbox_input: bool,
) {
let mut app = App::test_default();
app.ignore_special_keys_for_textbox_input = ignore_special_keys_for_textbox_input;
let handler = TestAllIndexersHandler::new(
DEFAULT_KEYBINDINGS.esc.key,
&mut app,
ActiveLidarrBlock::default(),
None,
);
assert_eq!(
handler.ignore_special_keys(),
ignore_special_keys_for_textbox_input
);
}
#[test]
fn test_test_all_indexers_handler_not_ready_when_loading() {
let mut app = App::test_default();
app.push_navigation_stack(ActiveLidarrBlock::TestAllIndexers.into());
app.is_loading = true;
let handler = TestAllIndexersHandler::new(
DEFAULT_KEYBINDINGS.esc.key,
&mut app,
ActiveLidarrBlock::TestAllIndexers,
None,
);
assert!(!handler.is_ready());
}
#[test]
fn test_test_all_indexers_handler_not_ready_when_results_is_none() {
let mut app = App::test_default();
app.push_navigation_stack(ActiveLidarrBlock::TestAllIndexers.into());
app.is_loading = false;
let handler = TestAllIndexersHandler::new(
DEFAULT_KEYBINDINGS.esc.key,
&mut app,
ActiveLidarrBlock::TestAllIndexers,
None,
);
assert!(!handler.is_ready());
}
#[test]
fn test_test_all_indexers_handler_not_ready_when_results_is_empty() {
let mut app = App::test_default();
app.push_navigation_stack(ActiveLidarrBlock::TestAllIndexers.into());
app.is_loading = false;
app.data.lidarr_data.indexer_test_all_results = Some(StatefulTable::default());
let handler = TestAllIndexersHandler::new(
DEFAULT_KEYBINDINGS.esc.key,
&mut app,
ActiveLidarrBlock::TestAllIndexers,
None,
);
assert!(!handler.is_ready());
}
#[test]
fn test_test_all_indexers_handler_ready_when_not_loading_and_results_is_not_empty() {
let mut app = App::test_default();
app.push_navigation_stack(ActiveLidarrBlock::TestAllIndexers.into());
app.is_loading = false;
let mut results = StatefulTable::default();
results.set_items(vec![IndexerTestResultModalItem::default()]);
app.data.lidarr_data.indexer_test_all_results = Some(results);
let handler = TestAllIndexersHandler::new(
DEFAULT_KEYBINDINGS.esc.key,
&mut app,
ActiveLidarrBlock::TestAllIndexers,
None,
);
assert!(handler.is_ready());
}
}
@@ -52,10 +52,11 @@ mod tests {
}
#[rstest]
#[case(0, ActiveLidarrBlock::RootFolders, ActiveLidarrBlock::Downloads)]
#[case(0, ActiveLidarrBlock::Indexers, ActiveLidarrBlock::Downloads)]
#[case(1, ActiveLidarrBlock::Artists, ActiveLidarrBlock::History)]
#[case(2, ActiveLidarrBlock::Downloads, ActiveLidarrBlock::RootFolders)]
#[case(3, ActiveLidarrBlock::History, ActiveLidarrBlock::Artists)]
#[case(3, ActiveLidarrBlock::History, ActiveLidarrBlock::Indexers)]
#[case(4, ActiveLidarrBlock::RootFolders, ActiveLidarrBlock::Artists)]
fn test_lidarr_handler_change_tab_left_right_keys(
#[case] index: usize,
#[case] left_block: ActiveLidarrBlock,
@@ -84,10 +85,11 @@ mod tests {
}
#[rstest]
#[case(0, ActiveLidarrBlock::RootFolders, ActiveLidarrBlock::Downloads)]
#[case(0, ActiveLidarrBlock::Indexers, ActiveLidarrBlock::Downloads)]
#[case(1, ActiveLidarrBlock::Artists, ActiveLidarrBlock::History)]
#[case(2, ActiveLidarrBlock::Downloads, ActiveLidarrBlock::RootFolders)]
#[case(3, ActiveLidarrBlock::History, ActiveLidarrBlock::Artists)]
#[case(3, ActiveLidarrBlock::History, ActiveLidarrBlock::Indexers)]
#[case(4, ActiveLidarrBlock::RootFolders, ActiveLidarrBlock::Artists)]
fn test_lidarr_handler_change_tab_left_right_keys_alt_navigation(
#[case] index: usize,
#[case] left_block: ActiveLidarrBlock,
@@ -120,6 +122,7 @@ mod tests {
#[case(1, ActiveLidarrBlock::Downloads)]
#[case(2, ActiveLidarrBlock::History)]
#[case(3, ActiveLidarrBlock::RootFolders)]
#[case(4, ActiveLidarrBlock::Indexers)]
fn test_lidarr_handler_change_tab_left_right_keys_alt_navigation_no_op_when_ignoring_quit_key(
#[case] index: usize,
#[case] block: ActiveLidarrBlock,
@@ -226,4 +229,25 @@ mod tests {
active_lidarr_block
);
}
#[rstest]
fn test_delegates_indexers_blocks_to_indexers_handler(
#[values(
ActiveLidarrBlock::DeleteIndexerPrompt,
ActiveLidarrBlock::Indexers,
ActiveLidarrBlock::AllIndexerSettingsPrompt,
ActiveLidarrBlock::IndexerSettingsConfirmPrompt,
ActiveLidarrBlock::IndexerSettingsMaximumSizeInput,
ActiveLidarrBlock::IndexerSettingsMinimumAgeInput,
ActiveLidarrBlock::IndexerSettingsRetentionInput,
ActiveLidarrBlock::IndexerSettingsRssSyncIntervalInput
)]
active_sonarr_block: ActiveLidarrBlock,
) {
test_handler_delegation!(
LidarrHandler,
ActiveLidarrBlock::Indexers,
active_sonarr_block
);
}
}
+6 -1
View File
@@ -1,4 +1,5 @@
use history::HistoryHandler;
use indexers::IndexersHandler;
use library::LibraryHandler;
use super::KeyEventHandler;
@@ -9,10 +10,11 @@ use crate::{
app::App, event::Key, matches_key, models::servarr_data::lidarr::lidarr_data::ActiveLidarrBlock,
};
mod downloads;
mod history;
mod indexers;
mod library;
mod downloads;
#[cfg(test)]
#[path = "lidarr_handler_tests.rs"]
mod lidarr_handler_tests;
@@ -41,6 +43,9 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveLidarrBlock> for LidarrHandler<'a, 'b
RootFoldersHandler::new(self.key, self.app, self.active_lidarr_block, self.context)
.handle();
}
_ if IndexersHandler::accepts(self.active_lidarr_block) => {
IndexersHandler::new(self.key, self.app, self.active_lidarr_block, self.context).handle();
}
_ => self.handle_key_event(),
}
}
@@ -105,9 +105,9 @@ mod tests {
assert_eq!(
app.data.lidarr_data.main_tabs.get_active_route(),
ActiveLidarrBlock::Artists.into()
ActiveLidarrBlock::Indexers.into()
);
assert_navigation_pushed!(app, ActiveLidarrBlock::Artists.into());
assert_navigation_pushed!(app, ActiveLidarrBlock::Indexers.into());
}
#[rstest]
@@ -125,7 +125,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for EditIndexerHandler<'
.edit_indexer_modal
.as_mut()
.unwrap();
if edit_indexer_modal.priority > 0 {
if edit_indexer_modal.priority > 1 {
edit_indexer_modal.priority -= 1;
}
}
@@ -50,7 +50,7 @@ mod tests {
.as_ref()
.unwrap()
.priority,
1
2
);
} else {
assert_eq!(
@@ -61,7 +61,7 @@ mod tests {
.as_ref()
.unwrap()
.priority,
0
1
);
EditIndexerHandler::new(
@@ -80,7 +80,7 @@ mod tests {
.as_ref()
.unwrap()
.priority,
1
2
);
EditIndexerHandler::new(
@@ -98,7 +98,7 @@ mod tests {
.as_ref()
.unwrap()
.priority,
0
1
);
}
}
@@ -124,7 +124,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for EditIndexerHandler<'
.edit_indexer_modal
.as_mut()
.unwrap();
if edit_indexer_modal.priority > 0 {
if edit_indexer_modal.priority > 1 {
edit_indexer_modal.priority -= 1;
}
}
@@ -50,7 +50,7 @@ mod tests {
.as_ref()
.unwrap()
.priority,
1
2
);
} else {
assert_eq!(
@@ -61,7 +61,7 @@ mod tests {
.as_ref()
.unwrap()
.priority,
0
1
);
EditIndexerHandler::new(
@@ -80,7 +80,7 @@ mod tests {
.as_ref()
.unwrap()
.priority,
1
2
);
EditIndexerHandler::new(
@@ -98,7 +98,7 @@ mod tests {
.as_ref()
.unwrap()
.priority,
0
1
);
}
}
@@ -5,7 +5,7 @@ use crate::models::Route;
use crate::models::servarr_data::sonarr::sonarr_data::{
ActiveSonarrBlock, INDEXER_SETTINGS_BLOCKS,
};
use crate::models::sonarr_models::IndexerSettings;
use crate::models::servarr_models::IndexerSettings;
use crate::network::sonarr_network::SonarrEvent;
use crate::{handle_prompt_left_right_keys, matches_key};
@@ -15,7 +15,7 @@ mod tests {
use crate::models::servarr_data::sonarr::sonarr_data::{
ActiveSonarrBlock, INDEXER_SETTINGS_BLOCKS,
};
use crate::models::sonarr_models::IndexerSettings;
use crate::models::servarr_models::IndexerSettings;
mod test_handle_scroll_up_and_down {
use pretty_assertions::assert_eq;
@@ -23,7 +23,7 @@ mod tests {
use crate::models::BlockSelectionState;
use crate::models::servarr_data::sonarr::sonarr_data::INDEXER_SETTINGS_SELECTION_BLOCKS;
use crate::models::sonarr_models::IndexerSettings;
use crate::models::servarr_models::IndexerSettings;
use super::*;
@@ -242,7 +242,7 @@ mod tests {
assert_navigation_popped,
models::{
BlockSelectionState, servarr_data::sonarr::sonarr_data::INDEXER_SETTINGS_SELECTION_BLOCKS,
sonarr_models::IndexerSettings,
servarr_models::IndexerSettings,
},
network::sonarr_network::SonarrEvent,
};
@@ -415,7 +415,7 @@ mod tests {
mod test_handle_esc {
use rstest::rstest;
use crate::models::sonarr_models::IndexerSettings;
use crate::models::servarr_models::IndexerSettings;
use super::*;
use crate::assert_navigation_popped;
@@ -2,13 +2,14 @@
#[macro_use]
pub(in crate::handlers::sonarr_handlers) mod utils {
use crate::models::HorizontallyScrollableText;
use crate::models::servarr_models::IndexerSettings;
use crate::models::servarr_models::{
Indexer, IndexerField, Language, Quality, QualityWrapper, RootFolder,
};
use crate::models::sonarr_models::{
AddSeriesSearchResult, AddSeriesSearchResultStatistics, DownloadRecord, DownloadStatus,
Episode, EpisodeFile, IndexerSettings, MediaInfo, Rating, Season, SeasonStatistics, Series,
SeriesStatistics, SeriesStatus, SeriesType,
Episode, EpisodeFile, MediaInfo, Rating, Season, SeasonStatistics, Series, SeriesStatistics,
SeriesStatus, SeriesType,
};
use chrono::DateTime;
use serde_json::{Number, json};