Added support for editing all indexer settings (finally)!
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
use crate::app::key_binding::DEFAULT_KEYBINDINGS;
|
||||
use crate::app::App;
|
||||
use crate::event::Key;
|
||||
use crate::handlers::KeyEventHandler;
|
||||
use crate::handlers::{handle_prompt_toggle, KeyEventHandler};
|
||||
use crate::models::servarr_data::radarr::radarr_data::{
|
||||
ActiveRadarrBlock, INDEXER_SETTINGS_BLOCKS,
|
||||
};
|
||||
use crate::network::radarr_network::RadarrEvent;
|
||||
use crate::{handle_text_box_keys, handle_text_box_left_right_keys};
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "./edit_indexer_settings_handler_tests.rs"]
|
||||
@@ -40,26 +43,181 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for IndexerSettingsHandl
|
||||
}
|
||||
|
||||
fn handle_scroll_up(&mut self) {
|
||||
if self.active_radarr_block == &ActiveRadarrBlock::IndexerSettingsPrompt {
|
||||
self.app.data.radarr_data.selected_block.previous()
|
||||
let indexer_settings = self.app.data.radarr_data.indexer_settings.as_mut().unwrap();
|
||||
match self.active_radarr_block {
|
||||
ActiveRadarrBlock::IndexerSettingsPrompt => {
|
||||
self.app.data.radarr_data.selected_block.previous()
|
||||
}
|
||||
ActiveRadarrBlock::IndexerSettingsMinimumAgeInput => {
|
||||
indexer_settings.minimum_age += 1;
|
||||
}
|
||||
ActiveRadarrBlock::IndexerSettingsRetentionInput => {
|
||||
indexer_settings.retention += 1;
|
||||
}
|
||||
ActiveRadarrBlock::IndexerSettingsMaximumSizeInput => {
|
||||
indexer_settings.maximum_size += 1;
|
||||
}
|
||||
ActiveRadarrBlock::IndexerSettingsAvailabilityDelayInput => {
|
||||
indexer_settings.availability_delay += 1;
|
||||
}
|
||||
ActiveRadarrBlock::IndexerSettingsRssSyncIntervalInput => {
|
||||
indexer_settings.rss_sync_interval += 1;
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_scroll_down(&mut self) {
|
||||
if self.active_radarr_block == &ActiveRadarrBlock::IndexerSettingsPrompt {
|
||||
self.app.data.radarr_data.selected_block.next()
|
||||
let indexer_settings = self.app.data.radarr_data.indexer_settings.as_mut().unwrap();
|
||||
match self.active_radarr_block {
|
||||
ActiveRadarrBlock::IndexerSettingsPrompt => self.app.data.radarr_data.selected_block.next(),
|
||||
ActiveRadarrBlock::IndexerSettingsMinimumAgeInput => {
|
||||
if indexer_settings.minimum_age > 0 {
|
||||
indexer_settings.minimum_age -= 1;
|
||||
}
|
||||
}
|
||||
ActiveRadarrBlock::IndexerSettingsRetentionInput => {
|
||||
if indexer_settings.retention > 0 {
|
||||
indexer_settings.retention -= 1;
|
||||
}
|
||||
}
|
||||
ActiveRadarrBlock::IndexerSettingsMaximumSizeInput => {
|
||||
if indexer_settings.maximum_size > 0 {
|
||||
indexer_settings.maximum_size -= 1;
|
||||
}
|
||||
}
|
||||
ActiveRadarrBlock::IndexerSettingsAvailabilityDelayInput => {
|
||||
indexer_settings.availability_delay -= 1;
|
||||
}
|
||||
ActiveRadarrBlock::IndexerSettingsRssSyncIntervalInput => {
|
||||
if indexer_settings.rss_sync_interval > 0 {
|
||||
indexer_settings.rss_sync_interval -= 1;
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_home(&mut self) {}
|
||||
fn handle_home(&mut self) {
|
||||
if self.active_radarr_block == &ActiveRadarrBlock::IndexerSettingsWhitelistedSubtitleTagsInput {
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.indexer_settings
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.whitelisted_hardcoded_subs
|
||||
.scroll_home();
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_end(&mut self) {}
|
||||
fn handle_end(&mut self) {
|
||||
if self.active_radarr_block == &ActiveRadarrBlock::IndexerSettingsWhitelistedSubtitleTagsInput {
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.indexer_settings
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.whitelisted_hardcoded_subs
|
||||
.reset_offset();
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_delete(&mut self) {}
|
||||
|
||||
fn handle_left_right_action(&mut self) {}
|
||||
fn handle_left_right_action(&mut self) {
|
||||
match self.active_radarr_block {
|
||||
ActiveRadarrBlock::IndexerSettingsPrompt => {
|
||||
if self.app.data.radarr_data.selected_block.get_active_block()
|
||||
== &ActiveRadarrBlock::IndexerSettingsConfirmPrompt
|
||||
{
|
||||
handle_prompt_toggle(self.app, self.key);
|
||||
} else {
|
||||
let len = self.app.data.radarr_data.selected_block.blocks.len();
|
||||
let idx = self.app.data.radarr_data.selected_block.index;
|
||||
self.app.data.radarr_data.selected_block.index = (idx + 5) % len;
|
||||
}
|
||||
}
|
||||
ActiveRadarrBlock::IndexerSettingsWhitelistedSubtitleTagsInput => {
|
||||
handle_text_box_left_right_keys!(
|
||||
self,
|
||||
self.key,
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.indexer_settings
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.whitelisted_hardcoded_subs
|
||||
)
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_submit(&mut self) {}
|
||||
fn handle_submit(&mut self) {
|
||||
match self.active_radarr_block {
|
||||
ActiveRadarrBlock::IndexerSettingsPrompt => {
|
||||
match self.app.data.radarr_data.selected_block.get_active_block() {
|
||||
ActiveRadarrBlock::IndexerSettingsConfirmPrompt => {
|
||||
let radarr_data = &mut self.app.data.radarr_data;
|
||||
if radarr_data.prompt_confirm {
|
||||
radarr_data.prompt_confirm_action = Some(RadarrEvent::UpdateIndexerSettings);
|
||||
self.app.should_refresh = true;
|
||||
} else {
|
||||
radarr_data.indexer_settings = None;
|
||||
}
|
||||
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
ActiveRadarrBlock::IndexerSettingsMinimumAgeInput
|
||||
| ActiveRadarrBlock::IndexerSettingsRetentionInput
|
||||
| ActiveRadarrBlock::IndexerSettingsMaximumSizeInput
|
||||
| ActiveRadarrBlock::IndexerSettingsAvailabilityDelayInput
|
||||
| ActiveRadarrBlock::IndexerSettingsRssSyncIntervalInput => {
|
||||
self.app.push_navigation_stack(
|
||||
(
|
||||
*self.app.data.radarr_data.selected_block.get_active_block(),
|
||||
None,
|
||||
)
|
||||
.into(),
|
||||
)
|
||||
}
|
||||
ActiveRadarrBlock::IndexerSettingsWhitelistedSubtitleTagsInput => {
|
||||
self.app.push_navigation_stack(
|
||||
ActiveRadarrBlock::IndexerSettingsWhitelistedSubtitleTagsInput.into(),
|
||||
);
|
||||
self.app.should_ignore_quit_key = true;
|
||||
}
|
||||
ActiveRadarrBlock::IndexerSettingsTogglePreferIndexerFlags => {
|
||||
let indexer_settings = self.app.data.radarr_data.indexer_settings.as_mut().unwrap();
|
||||
|
||||
indexer_settings.prefer_indexer_flags = !indexer_settings.prefer_indexer_flags;
|
||||
}
|
||||
ActiveRadarrBlock::IndexerSettingsToggleAllowHardcodedSubs => {
|
||||
let indexer_settings = self.app.data.radarr_data.indexer_settings.as_mut().unwrap();
|
||||
|
||||
indexer_settings.allow_hardcoded_subs = !indexer_settings.allow_hardcoded_subs;
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
ActiveRadarrBlock::IndexerSettingsWhitelistedSubtitleTagsInput => {
|
||||
self.app.pop_navigation_stack();
|
||||
self.app.should_ignore_quit_key = false;
|
||||
}
|
||||
ActiveRadarrBlock::IndexerSettingsMinimumAgeInput
|
||||
| ActiveRadarrBlock::IndexerSettingsRetentionInput
|
||||
| ActiveRadarrBlock::IndexerSettingsMaximumSizeInput
|
||||
| ActiveRadarrBlock::IndexerSettingsAvailabilityDelayInput
|
||||
| ActiveRadarrBlock::IndexerSettingsRssSyncIntervalInput => self.app.pop_navigation_stack(),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_esc(&mut self) {
|
||||
match self.active_radarr_block {
|
||||
@@ -68,9 +226,28 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for IndexerSettingsHandl
|
||||
self.app.data.radarr_data.prompt_confirm = false;
|
||||
self.app.data.radarr_data.indexer_settings = None;
|
||||
}
|
||||
_ => self.app.pop_navigation_stack(), // Need to tweak this still and add unit tests
|
||||
ActiveRadarrBlock::IndexerSettingsWhitelistedSubtitleTagsInput => {
|
||||
self.app.pop_navigation_stack();
|
||||
self.app.should_ignore_quit_key = false;
|
||||
}
|
||||
_ => self.app.pop_navigation_stack(),
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_char_key_event(&mut self) {}
|
||||
fn handle_char_key_event(&mut self) {
|
||||
if self.active_radarr_block == &ActiveRadarrBlock::IndexerSettingsWhitelistedSubtitleTagsInput {
|
||||
handle_text_box_keys!(
|
||||
self,
|
||||
self.key,
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.indexer_settings
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.whitelisted_hardcoded_subs
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,14 +15,87 @@ mod tests {
|
||||
use pretty_assertions::assert_eq;
|
||||
use rstest::rstest;
|
||||
|
||||
use crate::models::radarr_models::IndexerSettings;
|
||||
use crate::models::servarr_data::radarr::radarr_data::INDEXER_SETTINGS_SELECTION_BLOCKS;
|
||||
use crate::models::BlockSelectionState;
|
||||
|
||||
use super::*;
|
||||
|
||||
macro_rules! test_i64_counter_scroll_value {
|
||||
($block:expr, $key:expr, $data_ref:ident, $negatives:literal) => {
|
||||
let mut app = App::default();
|
||||
app.data.radarr_data.indexer_settings = Some(IndexerSettings::default());
|
||||
|
||||
IndexerSettingsHandler::with(&$key, &mut app, &$block, &None).handle();
|
||||
|
||||
if $key == Key::Up {
|
||||
assert_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.indexer_settings
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.$data_ref,
|
||||
1
|
||||
);
|
||||
} else {
|
||||
if $negatives {
|
||||
assert_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.indexer_settings
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.$data_ref,
|
||||
-1
|
||||
);
|
||||
} else {
|
||||
assert_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.indexer_settings
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.$data_ref,
|
||||
0
|
||||
);
|
||||
|
||||
IndexerSettingsHandler::with(&Key::Up, &mut app, &$block, &None).handle();
|
||||
|
||||
assert_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.indexer_settings
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.$data_ref,
|
||||
1
|
||||
);
|
||||
|
||||
IndexerSettingsHandler::with(&$key, &mut app, &$block, &None).handle();
|
||||
assert_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_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::default();
|
||||
app.data.radarr_data.indexer_settings = Some(IndexerSettings::default());
|
||||
app.data.radarr_data.selected_block =
|
||||
BlockSelectionState::new(&INDEXER_SETTINGS_SELECTION_BLOCKS);
|
||||
app.data.radarr_data.selected_block.next();
|
||||
@@ -47,18 +120,572 @@ mod tests {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_edit_indexer_settings_minimum_age_scroll(#[values(Key::Up, Key::Down)] key: Key) {
|
||||
test_i64_counter_scroll_value!(
|
||||
ActiveRadarrBlock::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!(
|
||||
ActiveRadarrBlock::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!(
|
||||
ActiveRadarrBlock::IndexerSettingsMaximumSizeInput,
|
||||
key,
|
||||
maximum_size,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_edit_indexer_settings_availability_delay_scroll(
|
||||
#[values(Key::Up, Key::Down)] key: Key,
|
||||
) {
|
||||
test_i64_counter_scroll_value!(
|
||||
ActiveRadarrBlock::IndexerSettingsAvailabilityDelayInput,
|
||||
key,
|
||||
availability_delay,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_edit_indexer_settings_rss_sync_interval_scroll(#[values(Key::Up, Key::Down)] key: Key) {
|
||||
test_i64_counter_scroll_value!(
|
||||
ActiveRadarrBlock::IndexerSettingsRssSyncIntervalInput,
|
||||
key,
|
||||
rss_sync_interval,
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_home_end {}
|
||||
mod test_handle_home_end {
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
mod test_handle_left_right_action {}
|
||||
use crate::models::radarr_models::IndexerSettings;
|
||||
|
||||
mod test_handle_submit {}
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_edit_indexer_settings_whiteliested_subtitle_tags_input_home_end() {
|
||||
let mut app = App::default();
|
||||
app.data.radarr_data.indexer_settings = Some(IndexerSettings {
|
||||
whitelisted_hardcoded_subs: "Test".into(),
|
||||
..IndexerSettings::default()
|
||||
});
|
||||
|
||||
IndexerSettingsHandler::with(
|
||||
&DEFAULT_KEYBINDINGS.home.key,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::IndexerSettingsWhitelistedSubtitleTagsInput,
|
||||
&None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
*app
|
||||
.data
|
||||
.radarr_data
|
||||
.indexer_settings
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.whitelisted_hardcoded_subs
|
||||
.offset
|
||||
.borrow(),
|
||||
4
|
||||
);
|
||||
|
||||
IndexerSettingsHandler::with(
|
||||
&DEFAULT_KEYBINDINGS.end.key,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::IndexerSettingsWhitelistedSubtitleTagsInput,
|
||||
&None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
*app
|
||||
.data
|
||||
.radarr_data
|
||||
.indexer_settings
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.whitelisted_hardcoded_subs
|
||||
.offset
|
||||
.borrow(),
|
||||
0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_left_right_action {
|
||||
use crate::models::radarr_models::IndexerSettings;
|
||||
use crate::models::servarr_data::radarr::radarr_data::INDEXER_SETTINGS_SELECTION_BLOCKS;
|
||||
use crate::models::BlockSelectionState;
|
||||
use pretty_assertions::assert_eq;
|
||||
use rstest::rstest;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[rstest]
|
||||
fn test_left_right_prompt_toggle(#[values(Key::Left, Key::Right)] key: Key) {
|
||||
let mut app = App::default();
|
||||
app.data.radarr_data.selected_block =
|
||||
BlockSelectionState::new(&INDEXER_SETTINGS_SELECTION_BLOCKS);
|
||||
app.data.radarr_data.selected_block.index = INDEXER_SETTINGS_SELECTION_BLOCKS.len() - 1;
|
||||
|
||||
IndexerSettingsHandler::with(
|
||||
&key,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::IndexerSettingsPrompt,
|
||||
&None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert!(app.data.radarr_data.prompt_confirm);
|
||||
|
||||
IndexerSettingsHandler::with(
|
||||
&key,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::IndexerSettingsPrompt,
|
||||
&None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert!(!app.data.radarr_data.prompt_confirm);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
#[case(
|
||||
0,
|
||||
ActiveRadarrBlock::IndexerSettingsMinimumAgeInput,
|
||||
ActiveRadarrBlock::IndexerSettingsAvailabilityDelayInput
|
||||
)]
|
||||
#[case(
|
||||
1,
|
||||
ActiveRadarrBlock::IndexerSettingsRetentionInput,
|
||||
ActiveRadarrBlock::IndexerSettingsRssSyncIntervalInput
|
||||
)]
|
||||
#[case(
|
||||
2,
|
||||
ActiveRadarrBlock::IndexerSettingsMaximumSizeInput,
|
||||
ActiveRadarrBlock::IndexerSettingsWhitelistedSubtitleTagsInput
|
||||
)]
|
||||
#[case(
|
||||
3,
|
||||
ActiveRadarrBlock::IndexerSettingsTogglePreferIndexerFlags,
|
||||
ActiveRadarrBlock::IndexerSettingsToggleAllowHardcodedSubs
|
||||
)]
|
||||
fn test_left_right_block_toggle(
|
||||
#[values(Key::Left, Key::Right)] key: Key,
|
||||
#[case] starting_index: usize,
|
||||
#[case] left_block: ActiveRadarrBlock,
|
||||
#[case] right_block: ActiveRadarrBlock,
|
||||
) {
|
||||
let mut app = App::default();
|
||||
app.data.radarr_data.selected_block =
|
||||
BlockSelectionState::new(&INDEXER_SETTINGS_SELECTION_BLOCKS);
|
||||
app.data.radarr_data.selected_block.index = starting_index;
|
||||
|
||||
assert_eq!(
|
||||
app.data.radarr_data.selected_block.get_active_block(),
|
||||
&left_block
|
||||
);
|
||||
|
||||
IndexerSettingsHandler::with(
|
||||
&key,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::IndexerSettingsPrompt,
|
||||
&None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app.data.radarr_data.selected_block.get_active_block(),
|
||||
&right_block
|
||||
);
|
||||
|
||||
IndexerSettingsHandler::with(
|
||||
&key,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::IndexerSettingsPrompt,
|
||||
&None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app.data.radarr_data.selected_block.get_active_block(),
|
||||
&left_block
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_edit_indexer_settings_whitelisted_subtitle_tags_input_left_right_keys() {
|
||||
let mut app = App::default();
|
||||
app.data.radarr_data.indexer_settings = Some(IndexerSettings {
|
||||
whitelisted_hardcoded_subs: "Test".into(),
|
||||
..IndexerSettings::default()
|
||||
});
|
||||
|
||||
IndexerSettingsHandler::with(
|
||||
&DEFAULT_KEYBINDINGS.left.key,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::IndexerSettingsWhitelistedSubtitleTagsInput,
|
||||
&None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
*app
|
||||
.data
|
||||
.radarr_data
|
||||
.indexer_settings
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.whitelisted_hardcoded_subs
|
||||
.offset
|
||||
.borrow(),
|
||||
1
|
||||
);
|
||||
|
||||
IndexerSettingsHandler::with(
|
||||
&DEFAULT_KEYBINDINGS.right.key,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::IndexerSettingsWhitelistedSubtitleTagsInput,
|
||||
&None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
*app
|
||||
.data
|
||||
.radarr_data
|
||||
.indexer_settings
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.whitelisted_hardcoded_subs
|
||||
.offset
|
||||
.borrow(),
|
||||
0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_submit {
|
||||
use pretty_assertions::assert_eq;
|
||||
use rstest::rstest;
|
||||
|
||||
use crate::{
|
||||
models::{
|
||||
radarr_models::IndexerSettings,
|
||||
servarr_data::radarr::radarr_data::INDEXER_SETTINGS_SELECTION_BLOCKS, BlockSelectionState,
|
||||
},
|
||||
network::radarr_network::RadarrEvent,
|
||||
};
|
||||
|
||||
use super::*;
|
||||
|
||||
const SUBMIT_KEY: Key = DEFAULT_KEYBINDINGS.submit.key;
|
||||
|
||||
#[test]
|
||||
fn test_edit_indexer_settings_prompt_prompt_decline_submit() {
|
||||
let mut app = App::default();
|
||||
app.push_navigation_stack(ActiveRadarrBlock::Indexers.into());
|
||||
app.push_navigation_stack(ActiveRadarrBlock::IndexerSettingsPrompt.into());
|
||||
app.data.radarr_data.selected_block =
|
||||
BlockSelectionState::new(&INDEXER_SETTINGS_SELECTION_BLOCKS);
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.selected_block
|
||||
.set_index(INDEXER_SETTINGS_SELECTION_BLOCKS.len() - 1);
|
||||
app.data.radarr_data.indexer_settings = Some(IndexerSettings::default());
|
||||
|
||||
IndexerSettingsHandler::with(
|
||||
&SUBMIT_KEY,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::IndexerSettingsPrompt,
|
||||
&None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(app.get_current_route(), &ActiveRadarrBlock::Indexers.into());
|
||||
assert_eq!(app.data.radarr_data.prompt_confirm_action, None);
|
||||
assert!(!app.should_refresh);
|
||||
assert_eq!(app.data.radarr_data.indexer_settings, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_edit_indexer_settings_prompt_prompt_confirmation_submit() {
|
||||
let mut app = App::default();
|
||||
app.push_navigation_stack(ActiveRadarrBlock::Indexers.into());
|
||||
app.push_navigation_stack(ActiveRadarrBlock::IndexerSettingsPrompt.into());
|
||||
app.data.radarr_data.selected_block =
|
||||
BlockSelectionState::new(&INDEXER_SETTINGS_SELECTION_BLOCKS);
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.selected_block
|
||||
.set_index(INDEXER_SETTINGS_SELECTION_BLOCKS.len() - 1);
|
||||
app.data.radarr_data.indexer_settings = Some(IndexerSettings::default());
|
||||
app.data.radarr_data.prompt_confirm = true;
|
||||
|
||||
IndexerSettingsHandler::with(
|
||||
&SUBMIT_KEY,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::IndexerSettingsPrompt,
|
||||
&None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(app.get_current_route(), &ActiveRadarrBlock::Indexers.into());
|
||||
assert_eq!(
|
||||
app.data.radarr_data.prompt_confirm_action,
|
||||
Some(RadarrEvent::UpdateIndexerSettings)
|
||||
);
|
||||
assert!(app.data.radarr_data.indexer_settings.is_some());
|
||||
assert!(app.should_refresh);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
#[case(ActiveRadarrBlock::IndexerSettingsMinimumAgeInput, 0)]
|
||||
#[case(ActiveRadarrBlock::IndexerSettingsRetentionInput, 1)]
|
||||
#[case(ActiveRadarrBlock::IndexerSettingsMaximumSizeInput, 2)]
|
||||
#[case(ActiveRadarrBlock::IndexerSettingsAvailabilityDelayInput, 5)]
|
||||
#[case(ActiveRadarrBlock::IndexerSettingsRssSyncIntervalInput, 6)]
|
||||
fn test_edit_indexer_settings_prompt_submit_selected_block(
|
||||
#[case] selected_block: ActiveRadarrBlock,
|
||||
#[case] index: usize,
|
||||
) {
|
||||
let mut app = App::default();
|
||||
app.push_navigation_stack(ActiveRadarrBlock::IndexerSettingsPrompt.into());
|
||||
app.data.radarr_data.selected_block =
|
||||
BlockSelectionState::new(&INDEXER_SETTINGS_SELECTION_BLOCKS);
|
||||
app.data.radarr_data.selected_block.set_index(index);
|
||||
|
||||
IndexerSettingsHandler::with(
|
||||
&SUBMIT_KEY,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::IndexerSettingsPrompt,
|
||||
&None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(app.get_current_route(), &selected_block.into());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_edit_indexer_settings_prompt_submit_whitelisted_subtitle_tags_input() {
|
||||
let mut app = App::default();
|
||||
app.push_navigation_stack(ActiveRadarrBlock::IndexerSettingsPrompt.into());
|
||||
app.data.radarr_data.selected_block =
|
||||
BlockSelectionState::new(&INDEXER_SETTINGS_SELECTION_BLOCKS);
|
||||
app.data.radarr_data.selected_block.set_index(7);
|
||||
|
||||
IndexerSettingsHandler::with(
|
||||
&SUBMIT_KEY,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::IndexerSettingsPrompt,
|
||||
&None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
&ActiveRadarrBlock::IndexerSettingsWhitelistedSubtitleTagsInput.into()
|
||||
);
|
||||
assert!(app.should_ignore_quit_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_edit_indexer_settings_toggle_prefer_indexer_flags_submit() {
|
||||
let mut app = App::default();
|
||||
app.data.radarr_data.indexer_settings = Some(IndexerSettings::default());
|
||||
app.data.radarr_data.selected_block =
|
||||
BlockSelectionState::new(&INDEXER_SETTINGS_SELECTION_BLOCKS);
|
||||
app.data.radarr_data.selected_block.set_index(3);
|
||||
app.push_navigation_stack(ActiveRadarrBlock::IndexerSettingsPrompt.into());
|
||||
|
||||
IndexerSettingsHandler::with(
|
||||
&SUBMIT_KEY,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::IndexerSettingsPrompt,
|
||||
&None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
&ActiveRadarrBlock::IndexerSettingsPrompt.into()
|
||||
);
|
||||
assert!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.indexer_settings
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.prefer_indexer_flags
|
||||
);
|
||||
|
||||
IndexerSettingsHandler::with(
|
||||
&SUBMIT_KEY,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::IndexerSettingsPrompt,
|
||||
&None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
&ActiveRadarrBlock::IndexerSettingsPrompt.into()
|
||||
);
|
||||
assert!(
|
||||
!app
|
||||
.data
|
||||
.radarr_data
|
||||
.indexer_settings
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.prefer_indexer_flags
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_edit_indexer_settings_toggle_allow_hardcoded_subs_submit() {
|
||||
let mut app = App::default();
|
||||
app.data.radarr_data.indexer_settings = Some(IndexerSettings::default());
|
||||
app.data.radarr_data.selected_block =
|
||||
BlockSelectionState::new(&INDEXER_SETTINGS_SELECTION_BLOCKS);
|
||||
app.data.radarr_data.selected_block.set_index(8);
|
||||
app.push_navigation_stack(ActiveRadarrBlock::IndexerSettingsPrompt.into());
|
||||
|
||||
IndexerSettingsHandler::with(
|
||||
&SUBMIT_KEY,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::IndexerSettingsPrompt,
|
||||
&None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
&ActiveRadarrBlock::IndexerSettingsPrompt.into()
|
||||
);
|
||||
assert!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.indexer_settings
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.allow_hardcoded_subs
|
||||
);
|
||||
|
||||
IndexerSettingsHandler::with(
|
||||
&SUBMIT_KEY,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::IndexerSettingsPrompt,
|
||||
&None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
&ActiveRadarrBlock::IndexerSettingsPrompt.into()
|
||||
);
|
||||
assert!(
|
||||
!app
|
||||
.data
|
||||
.radarr_data
|
||||
.indexer_settings
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.allow_hardcoded_subs
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_edit_indexer_settings_whitelisted_subtitle_tags_input_submit() {
|
||||
let mut app = App::default();
|
||||
app.should_ignore_quit_key = true;
|
||||
app.data.radarr_data.indexer_settings = Some(IndexerSettings {
|
||||
whitelisted_hardcoded_subs: "Test tags".into(),
|
||||
..IndexerSettings::default()
|
||||
});
|
||||
app.push_navigation_stack(ActiveRadarrBlock::IndexerSettingsPrompt.into());
|
||||
app.push_navigation_stack(
|
||||
ActiveRadarrBlock::IndexerSettingsWhitelistedSubtitleTagsInput.into(),
|
||||
);
|
||||
|
||||
IndexerSettingsHandler::with(
|
||||
&SUBMIT_KEY,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::IndexerSettingsWhitelistedSubtitleTagsInput,
|
||||
&None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert!(!app.should_ignore_quit_key);
|
||||
assert!(!app
|
||||
.data
|
||||
.radarr_data
|
||||
.indexer_settings
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.whitelisted_hardcoded_subs
|
||||
.text
|
||||
.is_empty());
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
&ActiveRadarrBlock::IndexerSettingsPrompt.into()
|
||||
);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_edit_indexer_settings_selected_block_submit(
|
||||
#[values(
|
||||
ActiveRadarrBlock::IndexerSettingsMinimumAgeInput,
|
||||
ActiveRadarrBlock::IndexerSettingsRetentionInput,
|
||||
ActiveRadarrBlock::IndexerSettingsMaximumSizeInput,
|
||||
ActiveRadarrBlock::IndexerSettingsAvailabilityDelayInput,
|
||||
ActiveRadarrBlock::IndexerSettingsRssSyncIntervalInput
|
||||
)]
|
||||
active_radarr_block: ActiveRadarrBlock,
|
||||
) {
|
||||
let mut app = App::default();
|
||||
app.push_navigation_stack(ActiveRadarrBlock::IndexerSettingsPrompt.into());
|
||||
app.push_navigation_stack(active_radarr_block.into());
|
||||
|
||||
IndexerSettingsHandler::with(&SUBMIT_KEY, &mut app, &active_radarr_block, &None).handle();
|
||||
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
&ActiveRadarrBlock::IndexerSettingsPrompt.into()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_esc {
|
||||
use pretty_assertions::assert_eq;
|
||||
use rstest::rstest;
|
||||
|
||||
use crate::models::servarr_data::radarr::radarr_data::radarr_test_utils::utils::create_test_radarr_data;
|
||||
use crate::models::radarr_models::IndexerSettings;
|
||||
|
||||
use super::*;
|
||||
|
||||
@@ -68,8 +695,8 @@ mod tests {
|
||||
fn test_edit_indexer_settings_prompt_esc() {
|
||||
let mut app = App::default();
|
||||
app.push_navigation_stack(ActiveRadarrBlock::Indexers.into());
|
||||
app.push_navigation_stack(ActiveRadarrBlock::EditMoviePrompt.into());
|
||||
app.data.radarr_data = create_test_radarr_data();
|
||||
app.push_navigation_stack(ActiveRadarrBlock::IndexerSettingsPrompt.into());
|
||||
app.data.radarr_data.indexer_settings = Some(IndexerSettings::default());
|
||||
|
||||
IndexerSettingsHandler::with(
|
||||
&ESC_KEY,
|
||||
@@ -83,9 +710,122 @@ mod tests {
|
||||
assert!(!app.data.radarr_data.prompt_confirm);
|
||||
assert_eq!(app.data.radarr_data.indexer_settings, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_edit_indexer_settings_whitelisted_subtitle_tags_input_esc() {
|
||||
let mut app = App::default();
|
||||
app.push_navigation_stack(ActiveRadarrBlock::Indexers.into());
|
||||
app.push_navigation_stack(
|
||||
ActiveRadarrBlock::IndexerSettingsWhitelistedSubtitleTagsInput.into(),
|
||||
);
|
||||
app.data.radarr_data.indexer_settings = Some(IndexerSettings::default());
|
||||
app.should_ignore_quit_key = true;
|
||||
|
||||
IndexerSettingsHandler::with(
|
||||
&ESC_KEY,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::IndexerSettingsWhitelistedSubtitleTagsInput,
|
||||
&None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(app.get_current_route(), &ActiveRadarrBlock::Indexers.into());
|
||||
assert!(!app.should_ignore_quit_key);
|
||||
assert_eq!(
|
||||
app.data.radarr_data.indexer_settings,
|
||||
Some(IndexerSettings::default())
|
||||
);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_edit_indexer_settings_selected_blocks_esc(
|
||||
#[values(
|
||||
ActiveRadarrBlock::IndexerSettingsMinimumAgeInput,
|
||||
ActiveRadarrBlock::IndexerSettingsRetentionInput,
|
||||
ActiveRadarrBlock::IndexerSettingsMaximumSizeInput,
|
||||
ActiveRadarrBlock::IndexerSettingsAvailabilityDelayInput,
|
||||
ActiveRadarrBlock::IndexerSettingsRssSyncIntervalInput,
|
||||
ActiveRadarrBlock::IndexerSettingsWhitelistedSubtitleTagsInput
|
||||
)]
|
||||
active_radarr_block: ActiveRadarrBlock,
|
||||
) {
|
||||
let mut app = App::default();
|
||||
app.push_navigation_stack(ActiveRadarrBlock::Indexers.into());
|
||||
app.push_navigation_stack(active_radarr_block.into());
|
||||
app.data.radarr_data.indexer_settings = Some(IndexerSettings::default());
|
||||
|
||||
IndexerSettingsHandler::with(&ESC_KEY, &mut app, &active_radarr_block, &None).handle();
|
||||
|
||||
assert_eq!(app.get_current_route(), &ActiveRadarrBlock::Indexers.into());
|
||||
assert_eq!(
|
||||
app.data.radarr_data.indexer_settings,
|
||||
Some(IndexerSettings::default())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_key_char {}
|
||||
mod test_handle_key_char {
|
||||
use pretty_assertions::assert_str_eq;
|
||||
|
||||
use crate::models::radarr_models::IndexerSettings;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_edit_indexer_settings_whitelisted_subtitle_tags_input_backspace() {
|
||||
let mut app = App::default();
|
||||
app.data.radarr_data.indexer_settings = Some(IndexerSettings {
|
||||
whitelisted_hardcoded_subs: "Test".into(),
|
||||
..IndexerSettings::default()
|
||||
});
|
||||
|
||||
IndexerSettingsHandler::with(
|
||||
&DEFAULT_KEYBINDINGS.backspace.key,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::IndexerSettingsWhitelistedSubtitleTagsInput,
|
||||
&None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.indexer_settings
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.whitelisted_hardcoded_subs
|
||||
.text,
|
||||
"Tes"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_edit_indexer_settings_whitelisted_subtitle_tags_input_char_key() {
|
||||
let mut app = App::default();
|
||||
app.data.radarr_data.indexer_settings = Some(IndexerSettings::default());
|
||||
|
||||
IndexerSettingsHandler::with(
|
||||
&Key::Char('h'),
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::IndexerSettingsWhitelistedSubtitleTagsInput,
|
||||
&None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.indexer_settings
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.whitelisted_hardcoded_subs
|
||||
.text,
|
||||
"h"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_indexer_settings_handler_accepts() {
|
||||
|
||||
@@ -99,8 +99,9 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for IndexersHandler<'a,
|
||||
fn handle_submit(&mut self) {
|
||||
match self.active_radarr_block {
|
||||
ActiveRadarrBlock::DeleteIndexerPrompt => {
|
||||
if self.app.data.radarr_data.prompt_confirm {
|
||||
self.app.data.radarr_data.prompt_confirm_action = Some(RadarrEvent::DeleteIndexer);
|
||||
let radarr_data = &mut self.app.data.radarr_data;
|
||||
if radarr_data.prompt_confirm {
|
||||
radarr_data.prompt_confirm_action = Some(RadarrEvent::DeleteIndexer);
|
||||
}
|
||||
|
||||
self.app.pop_navigation_stack();
|
||||
|
||||
Reference in New Issue
Block a user