feat: Created a History tab in the Radarr UI and created a list history command and mark-history-item-as-failed command for Radarr
This commit is contained in:
@@ -356,6 +356,9 @@ mod test_utils {
|
||||
.radarr_data
|
||||
.movies
|
||||
.set_items(vec![$crate::models::radarr_models::Movie::default()]);
|
||||
app.data.radarr_data.history.set_items(vec![
|
||||
$crate::models::radarr_models::RadarrHistoryItem::default(),
|
||||
]);
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
|
||||
@@ -91,9 +91,9 @@ mod tests {
|
||||
|
||||
assert_eq!(
|
||||
app.data.radarr_data.main_tabs.get_active_route(),
|
||||
ActiveRadarrBlock::RootFolders.into()
|
||||
ActiveRadarrBlock::History.into()
|
||||
);
|
||||
assert_navigation_pushed!(app, ActiveRadarrBlock::RootFolders.into());
|
||||
assert_navigation_pushed!(app, ActiveRadarrBlock::History.into());
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
|
||||
@@ -0,0 +1,438 @@
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::cmp::Ordering;
|
||||
|
||||
use chrono::DateTime;
|
||||
use pretty_assertions::{assert_eq, assert_str_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::radarr_handlers::history::{HistoryHandler, history_sorting_options};
|
||||
use crate::models::radarr_models::{RadarrHistoryEventType, RadarrHistoryItem};
|
||||
use crate::models::servarr_data::radarr::radarr_data::{ActiveRadarrBlock, HISTORY_BLOCKS};
|
||||
use crate::models::servarr_models::{Language, Quality, QualityWrapper};
|
||||
|
||||
mod test_handle_left_right_action {
|
||||
use pretty_assertions::assert_eq;
|
||||
use rstest::rstest;
|
||||
|
||||
use super::*;
|
||||
use crate::assert_navigation_pushed;
|
||||
|
||||
#[rstest]
|
||||
fn test_history_tab_left(#[values(true, false)] is_ready: bool) {
|
||||
let mut app = App::test_default();
|
||||
app.push_navigation_stack(ActiveRadarrBlock::History.into());
|
||||
app.is_loading = is_ready;
|
||||
app.data.radarr_data.main_tabs.set_index(4);
|
||||
|
||||
HistoryHandler::new(
|
||||
DEFAULT_KEYBINDINGS.left.key,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::History,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app.data.radarr_data.main_tabs.get_active_route(),
|
||||
ActiveRadarrBlock::Blocklist.into()
|
||||
);
|
||||
assert_navigation_pushed!(app, ActiveRadarrBlock::Blocklist.into());
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_history_tab_right(#[values(true, false)] is_ready: bool) {
|
||||
let mut app = App::test_default();
|
||||
app.push_navigation_stack(ActiveRadarrBlock::History.into());
|
||||
app.is_loading = is_ready;
|
||||
app.data.radarr_data.main_tabs.set_index(4);
|
||||
|
||||
HistoryHandler::new(
|
||||
DEFAULT_KEYBINDINGS.right.key,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::History,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app.data.radarr_data.main_tabs.get_active_route(),
|
||||
ActiveRadarrBlock::RootFolders.into()
|
||||
);
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
ActiveRadarrBlock::RootFolders.into()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_submit {
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
use super::*;
|
||||
|
||||
const SUBMIT_KEY: Key = DEFAULT_KEYBINDINGS.submit.key;
|
||||
|
||||
#[test]
|
||||
fn test_history_submit() {
|
||||
let mut app = App::test_default();
|
||||
app.data.radarr_data.history.set_items(history_vec());
|
||||
app.push_navigation_stack(ActiveRadarrBlock::History.into());
|
||||
|
||||
HistoryHandler::new(SUBMIT_KEY, &mut app, ActiveRadarrBlock::History, None).handle();
|
||||
|
||||
assert_navigation_pushed!(app, ActiveRadarrBlock::HistoryItemDetails.into());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_history_submit_no_op_when_not_ready() {
|
||||
let mut app = App::test_default();
|
||||
app.is_loading = true;
|
||||
app.data.radarr_data.history.set_items(history_vec());
|
||||
app.push_navigation_stack(ActiveRadarrBlock::History.into());
|
||||
|
||||
HistoryHandler::new(SUBMIT_KEY, &mut app, ActiveRadarrBlock::History, None).handle();
|
||||
|
||||
assert_eq!(app.get_current_route(), ActiveRadarrBlock::History.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 super::*;
|
||||
use crate::assert_navigation_popped;
|
||||
|
||||
const ESC_KEY: Key = DEFAULT_KEYBINDINGS.esc.key;
|
||||
|
||||
#[test]
|
||||
fn test_esc_history_item_details() {
|
||||
let mut app = App::test_default();
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.history
|
||||
.set_items(vec![RadarrHistoryItem::default()]);
|
||||
app.push_navigation_stack(ActiveRadarrBlock::History.into());
|
||||
app.push_navigation_stack(ActiveRadarrBlock::HistoryItemDetails.into());
|
||||
|
||||
HistoryHandler::new(
|
||||
ESC_KEY,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::HistoryItemDetails,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_navigation_popped!(app, ActiveRadarrBlock::History.into());
|
||||
}
|
||||
|
||||
#[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(ActiveRadarrBlock::History.into());
|
||||
app.push_navigation_stack(ActiveRadarrBlock::History.into());
|
||||
app.data.radarr_data = create_test_radarr_data();
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.history
|
||||
.set_items(vec![RadarrHistoryItem::default()]);
|
||||
|
||||
HistoryHandler::new(ESC_KEY, &mut app, ActiveRadarrBlock::History, None).handle();
|
||||
|
||||
assert_eq!(app.get_current_route(), ActiveRadarrBlock::History.into());
|
||||
assert_is_empty!(app.error.text);
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_key_char {
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
use super::*;
|
||||
use crate::assert_navigation_pushed;
|
||||
|
||||
#[test]
|
||||
fn test_refresh_history_key() {
|
||||
let mut app = App::test_default();
|
||||
app.data.radarr_data.history.set_items(history_vec());
|
||||
app.push_navigation_stack(ActiveRadarrBlock::History.into());
|
||||
|
||||
HistoryHandler::new(
|
||||
DEFAULT_KEYBINDINGS.refresh.key,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::History,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_navigation_pushed!(app, ActiveRadarrBlock::History.into());
|
||||
assert!(app.should_refresh);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_refresh_history_key_no_op_when_not_ready() {
|
||||
let mut app = App::test_default();
|
||||
app.is_loading = true;
|
||||
app.data.radarr_data.history.set_items(history_vec());
|
||||
app.push_navigation_stack(ActiveRadarrBlock::History.into());
|
||||
|
||||
HistoryHandler::new(
|
||||
DEFAULT_KEYBINDINGS.refresh.key,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::History,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(app.get_current_route(), ActiveRadarrBlock::History.into());
|
||||
assert!(!app.should_refresh);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_history_sorting_options_source_title() {
|
||||
let expected_cmp_fn: fn(&RadarrHistoryItem, &RadarrHistoryItem) -> Ordering = |a, b| {
|
||||
a.source_title
|
||||
.text
|
||||
.to_lowercase()
|
||||
.cmp(&b.source_title.text.to_lowercase())
|
||||
};
|
||||
let mut expected_history_vec = history_vec();
|
||||
expected_history_vec.sort_by(expected_cmp_fn);
|
||||
|
||||
let sort_option = history_sorting_options()[0].clone();
|
||||
let mut sorted_history_vec = history_vec();
|
||||
sorted_history_vec.sort_by(sort_option.cmp_fn.unwrap());
|
||||
|
||||
assert_eq!(sorted_history_vec, expected_history_vec);
|
||||
assert_str_eq!(sort_option.name, "Source Title");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_history_sorting_options_event_type() {
|
||||
let expected_cmp_fn: fn(&RadarrHistoryItem, &RadarrHistoryItem) -> Ordering = |a, b| {
|
||||
a.event_type
|
||||
.to_string()
|
||||
.to_lowercase()
|
||||
.cmp(&b.event_type.to_string().to_lowercase())
|
||||
};
|
||||
let mut expected_history_vec = history_vec();
|
||||
expected_history_vec.sort_by(expected_cmp_fn);
|
||||
|
||||
let sort_option = history_sorting_options()[1].clone();
|
||||
let mut sorted_history_vec = history_vec();
|
||||
sorted_history_vec.sort_by(sort_option.cmp_fn.unwrap());
|
||||
|
||||
assert_eq!(sorted_history_vec, expected_history_vec);
|
||||
assert_str_eq!(sort_option.name, "Event Type");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_history_sorting_options_language() {
|
||||
let expected_cmp_fn: fn(&RadarrHistoryItem, &RadarrHistoryItem) -> Ordering = |a, b| {
|
||||
let default_language = Language {
|
||||
id: 1,
|
||||
name: "_".to_owned(),
|
||||
};
|
||||
let language_a = a.languages.first().unwrap_or(&default_language);
|
||||
let language_b = b.languages.first().unwrap_or(&default_language);
|
||||
|
||||
language_a.cmp(language_b)
|
||||
};
|
||||
let mut expected_history_vec = history_vec();
|
||||
expected_history_vec.sort_by(expected_cmp_fn);
|
||||
|
||||
let sort_option = history_sorting_options()[2].clone();
|
||||
let mut sorted_history_vec = history_vec();
|
||||
sorted_history_vec.sort_by(sort_option.cmp_fn.unwrap());
|
||||
|
||||
assert_eq!(sorted_history_vec, expected_history_vec);
|
||||
assert_str_eq!(sort_option.name, "Language");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_history_sorting_options_quality() {
|
||||
let expected_cmp_fn: fn(&RadarrHistoryItem, &RadarrHistoryItem) -> Ordering = |a, b| {
|
||||
a.quality
|
||||
.quality
|
||||
.name
|
||||
.to_lowercase()
|
||||
.cmp(&b.quality.quality.name.to_lowercase())
|
||||
};
|
||||
let mut expected_history_vec = history_vec();
|
||||
expected_history_vec.sort_by(expected_cmp_fn);
|
||||
|
||||
let sort_option = history_sorting_options()[3].clone();
|
||||
let mut sorted_history_vec = history_vec();
|
||||
sorted_history_vec.sort_by(sort_option.cmp_fn.unwrap());
|
||||
|
||||
assert_eq!(sorted_history_vec, expected_history_vec);
|
||||
assert_str_eq!(sort_option.name, "Quality");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_history_sorting_options_date() {
|
||||
let expected_cmp_fn: fn(&RadarrHistoryItem, &RadarrHistoryItem) -> Ordering =
|
||||
|a, b| a.date.cmp(&b.date);
|
||||
let mut expected_history_vec = history_vec();
|
||||
expected_history_vec.sort_by(expected_cmp_fn);
|
||||
|
||||
let sort_option = history_sorting_options()[4].clone();
|
||||
let mut sorted_history_vec = history_vec();
|
||||
sorted_history_vec.sort_by(sort_option.cmp_fn.unwrap());
|
||||
|
||||
assert_eq!(sorted_history_vec, expected_history_vec);
|
||||
assert_str_eq!(sort_option.name, "Date");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_history_handler_accepts() {
|
||||
ActiveRadarrBlock::iter().for_each(|active_radarr_block| {
|
||||
if HISTORY_BLOCKS.contains(&active_radarr_block) {
|
||||
assert!(HistoryHandler::accepts(active_radarr_block));
|
||||
} else {
|
||||
assert!(!HistoryHandler::accepts(active_radarr_block));
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_history_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 = HistoryHandler::new(
|
||||
DEFAULT_KEYBINDINGS.esc.key,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::default(),
|
||||
None,
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
handler.ignore_special_keys(),
|
||||
ignore_special_keys_for_textbox_input
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_history_handler_not_ready_when_loading() {
|
||||
let mut app = App::test_default();
|
||||
app.push_navigation_stack(ActiveRadarrBlock::History.into());
|
||||
app.is_loading = true;
|
||||
|
||||
let handler = HistoryHandler::new(
|
||||
DEFAULT_KEYBINDINGS.esc.key,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::History,
|
||||
None,
|
||||
);
|
||||
|
||||
assert!(!handler.is_ready());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_history_handler_not_ready_when_history_is_empty() {
|
||||
let mut app = App::test_default();
|
||||
app.push_navigation_stack(ActiveRadarrBlock::History.into());
|
||||
app.is_loading = false;
|
||||
|
||||
let handler = HistoryHandler::new(
|
||||
DEFAULT_KEYBINDINGS.esc.key,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::History,
|
||||
None,
|
||||
);
|
||||
|
||||
assert!(!handler.is_ready());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_history_handler_ready_when_not_loading_and_history_is_not_empty() {
|
||||
let mut app = App::test_default();
|
||||
app.push_navigation_stack(ActiveRadarrBlock::History.into());
|
||||
app.is_loading = false;
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.history
|
||||
.set_items(vec![RadarrHistoryItem::default()]);
|
||||
|
||||
let handler = HistoryHandler::new(
|
||||
DEFAULT_KEYBINDINGS.esc.key,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::History,
|
||||
None,
|
||||
);
|
||||
|
||||
assert!(handler.is_ready());
|
||||
}
|
||||
|
||||
fn history_vec() -> Vec<RadarrHistoryItem> {
|
||||
vec![
|
||||
RadarrHistoryItem {
|
||||
id: 3,
|
||||
source_title: "test 1".into(),
|
||||
movie_id: 1,
|
||||
event_type: RadarrHistoryEventType::Grabbed,
|
||||
languages: vec![Language {
|
||||
id: 1,
|
||||
name: "telgu".to_owned(),
|
||||
}],
|
||||
quality: QualityWrapper {
|
||||
quality: Quality {
|
||||
name: "HD - 1080p".to_owned(),
|
||||
},
|
||||
},
|
||||
date: DateTime::from(DateTime::parse_from_rfc3339("2024-01-10T07:28:45Z").unwrap()),
|
||||
..RadarrHistoryItem::default()
|
||||
},
|
||||
RadarrHistoryItem {
|
||||
id: 2,
|
||||
source_title: "test 2".into(),
|
||||
movie_id: 2,
|
||||
event_type: RadarrHistoryEventType::DownloadFolderImported,
|
||||
languages: vec![Language {
|
||||
id: 3,
|
||||
name: "chinese".to_owned(),
|
||||
}],
|
||||
quality: QualityWrapper {
|
||||
quality: Quality {
|
||||
name: "SD - 720p".to_owned(),
|
||||
},
|
||||
},
|
||||
date: DateTime::from(DateTime::parse_from_rfc3339("2024-02-10T07:28:45Z").unwrap()),
|
||||
..RadarrHistoryItem::default()
|
||||
},
|
||||
RadarrHistoryItem {
|
||||
id: 1,
|
||||
source_title: "test 3".into(),
|
||||
movie_id: 3,
|
||||
event_type: RadarrHistoryEventType::MovieFileDeleted,
|
||||
languages: vec![Language {
|
||||
id: 1,
|
||||
name: "english".to_owned(),
|
||||
}],
|
||||
quality: QualityWrapper {
|
||||
quality: Quality {
|
||||
name: "HD - 1080p".to_owned(),
|
||||
},
|
||||
},
|
||||
date: DateTime::from(DateTime::parse_from_rfc3339("2024-03-10T07:28:45Z").unwrap()),
|
||||
..RadarrHistoryItem::default()
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
use crate::app::App;
|
||||
use crate::event::Key;
|
||||
use crate::handlers::radarr_handlers::handle_change_tab_left_right_keys;
|
||||
use crate::handlers::table_handler::{TableHandlingConfig, handle_table};
|
||||
use crate::handlers::{KeyEventHandler, handle_clear_errors};
|
||||
use crate::matches_key;
|
||||
use crate::models::Route;
|
||||
use crate::models::radarr_models::RadarrHistoryItem;
|
||||
use crate::models::servarr_data::radarr::radarr_data::{ActiveRadarrBlock, HISTORY_BLOCKS};
|
||||
use crate::models::servarr_models::Language;
|
||||
use crate::models::stateful_table::SortOption;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "history_handler_tests.rs"]
|
||||
mod history_handler_tests;
|
||||
|
||||
pub(super) struct HistoryHandler<'a, 'b> {
|
||||
key: Key,
|
||||
app: &'a mut App<'b>,
|
||||
active_radarr_block: ActiveRadarrBlock,
|
||||
_context: Option<ActiveRadarrBlock>,
|
||||
}
|
||||
|
||||
impl HistoryHandler<'_, '_> {}
|
||||
|
||||
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for HistoryHandler<'a, 'b> {
|
||||
fn handle(&mut self) {
|
||||
let history_table_handling_config = TableHandlingConfig::new(ActiveRadarrBlock::History.into())
|
||||
.sorting_block(ActiveRadarrBlock::HistorySortPrompt.into())
|
||||
.sort_options(history_sorting_options())
|
||||
.searching_block(ActiveRadarrBlock::SearchHistory.into())
|
||||
.search_error_block(ActiveRadarrBlock::SearchHistoryError.into())
|
||||
.search_field_fn(|history| &history.source_title.text)
|
||||
.filtering_block(ActiveRadarrBlock::FilterHistory.into())
|
||||
.filter_error_block(ActiveRadarrBlock::FilterHistoryError.into())
|
||||
.filter_field_fn(|history| &history.source_title.text);
|
||||
|
||||
if !handle_table(
|
||||
self,
|
||||
|app| &mut app.data.radarr_data.history,
|
||||
history_table_handling_config,
|
||||
) {
|
||||
self.handle_key_event();
|
||||
}
|
||||
}
|
||||
|
||||
fn accepts(active_block: ActiveRadarrBlock) -> bool {
|
||||
HISTORY_BLOCKS.contains(&active_block)
|
||||
}
|
||||
|
||||
fn new(
|
||||
key: Key,
|
||||
app: &'a mut App<'b>,
|
||||
active_block: ActiveRadarrBlock,
|
||||
context: Option<ActiveRadarrBlock>,
|
||||
) -> Self {
|
||||
HistoryHandler {
|
||||
key,
|
||||
app,
|
||||
active_radarr_block: active_block,
|
||||
_context: context,
|
||||
}
|
||||
}
|
||||
|
||||
fn get_key(&self) -> Key {
|
||||
self.key
|
||||
}
|
||||
|
||||
fn ignore_special_keys(&self) -> bool {
|
||||
self.app.ignore_special_keys_for_textbox_input
|
||||
}
|
||||
|
||||
fn is_ready(&self) -> bool {
|
||||
!self.app.is_loading && !self.app.data.radarr_data.history.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) {}
|
||||
|
||||
fn handle_left_right_action(&mut self) {
|
||||
if self.active_radarr_block == ActiveRadarrBlock::History {
|
||||
handle_change_tab_left_right_keys(self.app, self.key)
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_submit(&mut self) {
|
||||
if self.active_radarr_block == ActiveRadarrBlock::History {
|
||||
self
|
||||
.app
|
||||
.push_navigation_stack(ActiveRadarrBlock::HistoryItemDetails.into());
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_esc(&mut self) {
|
||||
if self.active_radarr_block == ActiveRadarrBlock::HistoryItemDetails {
|
||||
self.app.pop_navigation_stack();
|
||||
} else {
|
||||
handle_clear_errors(self.app);
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_char_key_event(&mut self) {
|
||||
let key = self.key;
|
||||
if self.active_radarr_block == ActiveRadarrBlock::History {
|
||||
match self.key {
|
||||
_ if matches_key!(refresh, key) => {
|
||||
self.app.should_refresh = true;
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn app_mut(&mut self) -> &mut App<'b> {
|
||||
self.app
|
||||
}
|
||||
|
||||
fn current_route(&self) -> Route {
|
||||
self.app.get_current_route()
|
||||
}
|
||||
}
|
||||
|
||||
pub(in crate::handlers::radarr_handlers) fn history_sorting_options()
|
||||
-> Vec<SortOption<RadarrHistoryItem>> {
|
||||
vec![
|
||||
SortOption {
|
||||
name: "Source Title",
|
||||
cmp_fn: Some(|a, b| {
|
||||
a.source_title
|
||||
.text
|
||||
.to_lowercase()
|
||||
.cmp(&b.source_title.text.to_lowercase())
|
||||
}),
|
||||
},
|
||||
SortOption {
|
||||
name: "Event Type",
|
||||
cmp_fn: Some(|a, b| {
|
||||
a.event_type
|
||||
.to_string()
|
||||
.to_lowercase()
|
||||
.cmp(&b.event_type.to_string().to_lowercase())
|
||||
}),
|
||||
},
|
||||
SortOption {
|
||||
name: "Language",
|
||||
cmp_fn: Some(|a, b| {
|
||||
let default_language = Language {
|
||||
id: 1,
|
||||
name: "_".to_owned(),
|
||||
};
|
||||
let language_a = a.languages.first().unwrap_or(&default_language);
|
||||
let language_b = b.languages.first().unwrap_or(&default_language);
|
||||
|
||||
language_a.cmp(language_b)
|
||||
}),
|
||||
},
|
||||
SortOption {
|
||||
name: "Quality",
|
||||
cmp_fn: Some(|a, b| {
|
||||
a.quality
|
||||
.quality
|
||||
.name
|
||||
.to_lowercase()
|
||||
.cmp(&b.quality.quality.name.to_lowercase())
|
||||
}),
|
||||
},
|
||||
SortOption {
|
||||
name: "Date",
|
||||
cmp_fn: Some(|a, b| a.date.cmp(&b.date)),
|
||||
},
|
||||
]
|
||||
}
|
||||
@@ -65,7 +65,7 @@ mod tests {
|
||||
fn test_indexers_tab_left(#[values(true, false)] is_ready: bool) {
|
||||
let mut app = App::test_default();
|
||||
app.is_loading = is_ready;
|
||||
app.data.radarr_data.main_tabs.set_index(5);
|
||||
app.data.radarr_data.main_tabs.set_index(6);
|
||||
|
||||
IndexersHandler::new(
|
||||
DEFAULT_KEYBINDINGS.left.key,
|
||||
@@ -86,7 +86,7 @@ mod tests {
|
||||
fn test_indexers_tab_right(#[values(true, false)] is_ready: bool) {
|
||||
let mut app = App::test_default();
|
||||
app.is_loading = is_ready;
|
||||
app.data.radarr_data.main_tabs.set_index(5);
|
||||
app.data.radarr_data.main_tabs.set_index(6);
|
||||
|
||||
IndexersHandler::new(
|
||||
DEFAULT_KEYBINDINGS.right.key,
|
||||
|
||||
@@ -2,6 +2,7 @@ use crate::handlers::KeyEventHandler;
|
||||
use crate::handlers::radarr_handlers::blocklist::BlocklistHandler;
|
||||
use crate::handlers::radarr_handlers::collections::CollectionsHandler;
|
||||
use crate::handlers::radarr_handlers::downloads::DownloadsHandler;
|
||||
use crate::handlers::radarr_handlers::history::HistoryHandler;
|
||||
use crate::handlers::radarr_handlers::indexers::IndexersHandler;
|
||||
use crate::handlers::radarr_handlers::library::LibraryHandler;
|
||||
use crate::handlers::radarr_handlers::root_folders::RootFoldersHandler;
|
||||
@@ -13,6 +14,7 @@ use crate::{App, Key, matches_key};
|
||||
mod blocklist;
|
||||
mod collections;
|
||||
mod downloads;
|
||||
mod history;
|
||||
mod indexers;
|
||||
mod library;
|
||||
mod root_folders;
|
||||
@@ -51,6 +53,9 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for RadarrHandler<'a, 'b
|
||||
_ if DownloadsHandler::accepts(self.active_radarr_block) => {
|
||||
DownloadsHandler::new(self.key, self.app, self.active_radarr_block, self.context).handle()
|
||||
}
|
||||
_ if HistoryHandler::accepts(self.active_radarr_block) => {
|
||||
HistoryHandler::new(self.key, self.app, self.active_radarr_block, self.context).handle()
|
||||
}
|
||||
_ if RootFoldersHandler::accepts(self.active_radarr_block) => {
|
||||
RootFoldersHandler::new(self.key, self.app, self.active_radarr_block, self.context).handle()
|
||||
}
|
||||
|
||||
@@ -16,10 +16,11 @@ mod tests {
|
||||
#[case(0, ActiveRadarrBlock::System, ActiveRadarrBlock::Collections)]
|
||||
#[case(1, ActiveRadarrBlock::Movies, ActiveRadarrBlock::Downloads)]
|
||||
#[case(2, ActiveRadarrBlock::Collections, ActiveRadarrBlock::Blocklist)]
|
||||
#[case(3, ActiveRadarrBlock::Downloads, ActiveRadarrBlock::RootFolders)]
|
||||
#[case(4, ActiveRadarrBlock::Blocklist, ActiveRadarrBlock::Indexers)]
|
||||
#[case(5, ActiveRadarrBlock::RootFolders, ActiveRadarrBlock::System)]
|
||||
#[case(6, ActiveRadarrBlock::Indexers, ActiveRadarrBlock::Movies)]
|
||||
#[case(3, ActiveRadarrBlock::Downloads, ActiveRadarrBlock::History)]
|
||||
#[case(4, ActiveRadarrBlock::Blocklist, ActiveRadarrBlock::RootFolders)]
|
||||
#[case(5, ActiveRadarrBlock::History, ActiveRadarrBlock::Indexers)]
|
||||
#[case(6, ActiveRadarrBlock::RootFolders, ActiveRadarrBlock::System)]
|
||||
#[case(7, ActiveRadarrBlock::Indexers, ActiveRadarrBlock::Movies)]
|
||||
fn test_radarr_handler_change_tab_left_right_keys(
|
||||
#[case] index: usize,
|
||||
#[case] left_block: ActiveRadarrBlock,
|
||||
@@ -51,10 +52,11 @@ mod tests {
|
||||
#[case(0, ActiveRadarrBlock::System, ActiveRadarrBlock::Collections)]
|
||||
#[case(1, ActiveRadarrBlock::Movies, ActiveRadarrBlock::Downloads)]
|
||||
#[case(2, ActiveRadarrBlock::Collections, ActiveRadarrBlock::Blocklist)]
|
||||
#[case(3, ActiveRadarrBlock::Downloads, ActiveRadarrBlock::RootFolders)]
|
||||
#[case(4, ActiveRadarrBlock::Blocklist, ActiveRadarrBlock::Indexers)]
|
||||
#[case(5, ActiveRadarrBlock::RootFolders, ActiveRadarrBlock::System)]
|
||||
#[case(6, ActiveRadarrBlock::Indexers, ActiveRadarrBlock::Movies)]
|
||||
#[case(3, ActiveRadarrBlock::Downloads, ActiveRadarrBlock::History)]
|
||||
#[case(4, ActiveRadarrBlock::Blocklist, ActiveRadarrBlock::RootFolders)]
|
||||
#[case(5, ActiveRadarrBlock::History, ActiveRadarrBlock::Indexers)]
|
||||
#[case(6, ActiveRadarrBlock::RootFolders, ActiveRadarrBlock::System)]
|
||||
#[case(7, ActiveRadarrBlock::Indexers, ActiveRadarrBlock::Movies)]
|
||||
fn test_radarr_handler_change_tab_left_right_keys_alt_navigation(
|
||||
#[case] index: usize,
|
||||
#[case] left_block: ActiveRadarrBlock,
|
||||
@@ -88,9 +90,10 @@ mod tests {
|
||||
#[case(1, ActiveRadarrBlock::Collections)]
|
||||
#[case(2, ActiveRadarrBlock::Downloads)]
|
||||
#[case(3, ActiveRadarrBlock::Blocklist)]
|
||||
#[case(4, ActiveRadarrBlock::RootFolders)]
|
||||
#[case(5, ActiveRadarrBlock::Indexers)]
|
||||
#[case(6, ActiveRadarrBlock::System)]
|
||||
#[case(4, ActiveRadarrBlock::History)]
|
||||
#[case(5, ActiveRadarrBlock::RootFolders)]
|
||||
#[case(6, ActiveRadarrBlock::Indexers)]
|
||||
#[case(7, ActiveRadarrBlock::System)]
|
||||
fn test_radarr_handler_change_tab_left_right_keys_alt_navigation_no_op_when_ignoring_quit_key(
|
||||
#[case] index: usize,
|
||||
#[case] block: ActiveRadarrBlock,
|
||||
@@ -281,6 +284,26 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_delegates_history_blocks_to_history_handler(
|
||||
#[values(
|
||||
ActiveRadarrBlock::History,
|
||||
ActiveRadarrBlock::HistoryItemDetails,
|
||||
ActiveRadarrBlock::HistorySortPrompt,
|
||||
ActiveRadarrBlock::FilterHistory,
|
||||
ActiveRadarrBlock::FilterHistoryError,
|
||||
ActiveRadarrBlock::SearchHistory,
|
||||
ActiveRadarrBlock::SearchHistoryError
|
||||
)]
|
||||
active_radarr_block: ActiveRadarrBlock,
|
||||
) {
|
||||
test_handler_delegation!(
|
||||
RadarrHandler,
|
||||
ActiveRadarrBlock::History,
|
||||
active_radarr_block
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_radarr_handler_accepts() {
|
||||
ActiveRadarrBlock::iter().for_each(|active_radarr_block| {
|
||||
|
||||
@@ -130,7 +130,7 @@ mod tests {
|
||||
fn test_root_folders_tab_left(#[values(true, false)] is_ready: bool) {
|
||||
let mut app = App::test_default();
|
||||
app.is_loading = is_ready;
|
||||
app.data.radarr_data.main_tabs.set_index(4);
|
||||
app.data.radarr_data.main_tabs.set_index(5);
|
||||
|
||||
RootFoldersHandler::new(
|
||||
DEFAULT_KEYBINDINGS.left.key,
|
||||
@@ -142,16 +142,16 @@ mod tests {
|
||||
|
||||
assert_eq!(
|
||||
app.data.radarr_data.main_tabs.get_active_route(),
|
||||
ActiveRadarrBlock::Blocklist.into()
|
||||
ActiveRadarrBlock::History.into()
|
||||
);
|
||||
assert_navigation_pushed!(app, ActiveRadarrBlock::Blocklist.into());
|
||||
assert_navigation_pushed!(app, ActiveRadarrBlock::History.into());
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_root_folders_tab_right(#[values(true, false)] is_ready: bool) {
|
||||
let mut app = App::test_default();
|
||||
app.is_loading = is_ready;
|
||||
app.data.radarr_data.main_tabs.set_index(4);
|
||||
app.data.radarr_data.main_tabs.set_index(5);
|
||||
|
||||
RootFoldersHandler::new(
|
||||
DEFAULT_KEYBINDINGS.right.key,
|
||||
|
||||
@@ -26,7 +26,7 @@ mod tests {
|
||||
fn test_system_tab_left(#[values(true, false)] is_ready: bool) {
|
||||
let mut app = App::test_default();
|
||||
app.is_loading = is_ready;
|
||||
app.data.radarr_data.main_tabs.set_index(6);
|
||||
app.data.radarr_data.main_tabs.set_index(7);
|
||||
|
||||
SystemHandler::new(
|
||||
DEFAULT_KEYBINDINGS.left.key,
|
||||
@@ -47,7 +47,7 @@ mod tests {
|
||||
fn test_system_tab_right(#[values(true, false)] is_ready: bool) {
|
||||
let mut app = App::test_default();
|
||||
app.is_loading = is_ready;
|
||||
app.data.radarr_data.main_tabs.set_index(6);
|
||||
app.data.radarr_data.main_tabs.set_index(7);
|
||||
|
||||
SystemHandler::new(
|
||||
DEFAULT_KEYBINDINGS.right.key,
|
||||
|
||||
Reference in New Issue
Block a user