feat: Support toggling Series monitoring directly from the Sonarr library view [#43]
This commit is contained in:
@@ -9,9 +9,13 @@ pub static ADD_SERIES_SEARCH_RESULTS_CONTEXT_CLUES: [ContextClue; 2] = [
|
||||
(DEFAULT_KEYBINDINGS.esc, "edit search"),
|
||||
];
|
||||
|
||||
pub static SERIES_CONTEXT_CLUES: [ContextClue; 10] = [
|
||||
pub static SERIES_CONTEXT_CLUES: [ContextClue; 11] = [
|
||||
(DEFAULT_KEYBINDINGS.add, DEFAULT_KEYBINDINGS.add.desc),
|
||||
(DEFAULT_KEYBINDINGS.edit, DEFAULT_KEYBINDINGS.edit.desc),
|
||||
(
|
||||
DEFAULT_KEYBINDINGS.toggle_monitoring,
|
||||
DEFAULT_KEYBINDINGS.toggle_monitoring.desc,
|
||||
),
|
||||
(DEFAULT_KEYBINDINGS.sort, DEFAULT_KEYBINDINGS.sort.desc),
|
||||
(DEFAULT_KEYBINDINGS.delete, DEFAULT_KEYBINDINGS.delete.desc),
|
||||
(DEFAULT_KEYBINDINGS.search, DEFAULT_KEYBINDINGS.search.desc),
|
||||
|
||||
@@ -46,6 +46,11 @@ mod tests {
|
||||
|
||||
let (key_binding, description) = series_context_clues_iter.next().unwrap();
|
||||
|
||||
assert_eq!(*key_binding, DEFAULT_KEYBINDINGS.toggle_monitoring);
|
||||
assert_str_eq!(*description, DEFAULT_KEYBINDINGS.toggle_monitoring.desc);
|
||||
|
||||
let (key_binding, description) = series_context_clues_iter.next().unwrap();
|
||||
|
||||
assert_eq!(*key_binding, DEFAULT_KEYBINDINGS.sort);
|
||||
assert_str_eq!(*description, DEFAULT_KEYBINDINGS.sort.desc);
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ mod tests {
|
||||
use crate::app::App;
|
||||
use crate::event::Key;
|
||||
use crate::handlers::sonarr_handlers::library::{series_sorting_options, LibraryHandler};
|
||||
use crate::handlers::sonarr_handlers::sonarr_handler_test_utils::utils::series;
|
||||
use crate::handlers::KeyEventHandler;
|
||||
use crate::models::servarr_data::sonarr::sonarr_data::{
|
||||
ActiveSonarrBlock, ADD_SERIES_BLOCKS, DELETE_SERIES_BLOCKS, EDIT_SERIES_BLOCKS,
|
||||
@@ -376,6 +377,51 @@ mod tests {
|
||||
assert!(app.data.sonarr_data.edit_series_modal.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_toggle_monitoring_key() {
|
||||
let mut app = App::test_default();
|
||||
app.data.sonarr_data = create_test_sonarr_data();
|
||||
app.push_navigation_stack(ActiveSonarrBlock::Series.into());
|
||||
app.is_routing = false;
|
||||
|
||||
LibraryHandler::new(
|
||||
DEFAULT_KEYBINDINGS.toggle_monitoring.key,
|
||||
&mut app,
|
||||
ActiveSonarrBlock::Series,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(app.get_current_route(), ActiveSonarrBlock::Series.into());
|
||||
assert!(app.data.sonarr_data.prompt_confirm);
|
||||
assert!(app.is_routing);
|
||||
assert_eq!(
|
||||
app.data.sonarr_data.prompt_confirm_action,
|
||||
Some(SonarrEvent::ToggleSeriesMonitoring(0))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_toggle_monitoring_key_no_op_when_not_ready() {
|
||||
let mut app = App::test_default();
|
||||
app.is_loading = true;
|
||||
app.push_navigation_stack(ActiveSonarrBlock::Series.into());
|
||||
app.is_routing = false;
|
||||
|
||||
LibraryHandler::new(
|
||||
DEFAULT_KEYBINDINGS.toggle_monitoring.key,
|
||||
&mut app,
|
||||
ActiveSonarrBlock::Series,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(app.get_current_route(), ActiveSonarrBlock::Series.into());
|
||||
assert!(!app.data.sonarr_data.prompt_confirm);
|
||||
assert!(app.data.sonarr_data.prompt_confirm_action.is_none());
|
||||
assert!(!app.is_routing);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_update_all_series_key() {
|
||||
let mut app = App::test_default();
|
||||
@@ -618,6 +664,22 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_series_id() {
|
||||
let mut app = App::test_default();
|
||||
app.data.sonarr_data.series.set_items(vec![series()]);
|
||||
|
||||
let series_id = LibraryHandler::new(
|
||||
DEFAULT_KEYBINDINGS.esc.key,
|
||||
&mut app,
|
||||
ActiveSonarrBlock::Series,
|
||||
None,
|
||||
)
|
||||
.extract_series_id();
|
||||
|
||||
assert_eq!(series_id, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_series_sorting_options_title() {
|
||||
let expected_cmp_fn: fn(&Series, &Series) -> Ordering = |a, b| {
|
||||
|
||||
@@ -46,6 +46,9 @@ pub(super) struct LibraryHandler<'a, 'b> {
|
||||
|
||||
impl LibraryHandler<'_, '_> {
|
||||
handle_table_events!(self, series, self.app.data.sonarr_data.series, Series);
|
||||
fn extract_series_id(&self) -> i64 {
|
||||
self.app.data.sonarr_data.series.current_selection().id
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for LibraryHandler<'a, 'b> {
|
||||
@@ -205,6 +208,16 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for LibraryHandler<'a, '
|
||||
self.app.data.sonarr_data.add_series_search = Some(HorizontallyScrollableText::default());
|
||||
self.app.ignore_special_keys_for_textbox_input = true;
|
||||
}
|
||||
_ if matches_key!(toggle_monitoring, key) => {
|
||||
self.app.data.sonarr_data.prompt_confirm = true;
|
||||
self.app.data.sonarr_data.prompt_confirm_action = Some(
|
||||
SonarrEvent::ToggleSeriesMonitoring(self.extract_series_id()),
|
||||
);
|
||||
|
||||
self
|
||||
.app
|
||||
.pop_and_push_navigation_stack(self.active_sonarr_block.into());
|
||||
}
|
||||
_ if matches_key!(update, key) => {
|
||||
self
|
||||
.app
|
||||
|
||||
Reference in New Issue
Block a user