feat: Added TUI and CLI support for viewing Artist history in Lidarr
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
use crate::app::App;
|
||||
use crate::event::Key;
|
||||
use crate::handlers::lidarr_handlers::history::history_sorting_options;
|
||||
use crate::handlers::lidarr_handlers::library::delete_album_handler::DeleteAlbumHandler;
|
||||
use crate::handlers::table_handler::{TableHandlingConfig, handle_table};
|
||||
use crate::handlers::{KeyEventHandler, handle_prompt_toggle};
|
||||
use crate::matches_key;
|
||||
use crate::models::lidarr_models::Album;
|
||||
use crate::models::lidarr_models::{Album, LidarrHistoryItem};
|
||||
use crate::models::servarr_data::lidarr::lidarr_data::{
|
||||
ARTIST_DETAILS_BLOCKS, ActiveLidarrBlock, DELETE_ALBUM_SELECTION_BLOCKS,
|
||||
EDIT_ARTIST_SELECTION_BLOCKS,
|
||||
@@ -41,10 +42,32 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveLidarrBlock> for ArtistDetailsHandler
|
||||
.search_error_block(ActiveLidarrBlock::SearchAlbumsError.into())
|
||||
.search_field_fn(|album: &Album| &album.title.text);
|
||||
|
||||
let artist_history_table_handling_config =
|
||||
TableHandlingConfig::new(ActiveLidarrBlock::ArtistHistory.into())
|
||||
.sorting_block(ActiveLidarrBlock::ArtistHistorySortPrompt.into())
|
||||
.sort_options(history_sorting_options())
|
||||
.searching_block(ActiveLidarrBlock::SearchArtistHistory.into())
|
||||
.search_error_block(ActiveLidarrBlock::SearchArtistHistoryError.into())
|
||||
.search_field_fn(|history_item: &LidarrHistoryItem| &history_item.source_title.text)
|
||||
.filtering_block(ActiveLidarrBlock::FilterArtistHistory.into())
|
||||
.filter_error_block(ActiveLidarrBlock::FilterArtistHistoryError.into())
|
||||
.filter_field_fn(|history_item: &LidarrHistoryItem| &history_item.source_title.text);
|
||||
|
||||
if !handle_table(
|
||||
self,
|
||||
|app| &mut app.data.lidarr_data.albums,
|
||||
albums_table_handling_config,
|
||||
) && !handle_table(
|
||||
self,
|
||||
|app| {
|
||||
app
|
||||
.data
|
||||
.lidarr_data
|
||||
.artist_history
|
||||
.as_mut()
|
||||
.expect("Artist history is undefined")
|
||||
},
|
||||
artist_history_table_handling_config,
|
||||
) {
|
||||
match self.active_lidarr_block {
|
||||
_ if DeleteAlbumHandler::accepts(self.active_lidarr_block) => {
|
||||
@@ -83,7 +106,11 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveLidarrBlock> for ArtistDetailsHandler
|
||||
}
|
||||
|
||||
fn is_ready(&self) -> bool {
|
||||
!self.app.is_loading
|
||||
if self.active_lidarr_block == ActiveLidarrBlock::ArtistHistory {
|
||||
!self.app.is_loading && self.app.data.lidarr_data.artist_history.is_some()
|
||||
} else {
|
||||
!self.app.is_loading
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_scroll_up(&mut self) {}
|
||||
@@ -106,6 +133,31 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveLidarrBlock> for ArtistDetailsHandler
|
||||
|
||||
fn handle_left_right_action(&mut self) {
|
||||
match self.active_lidarr_block {
|
||||
ActiveLidarrBlock::ArtistDetails | ActiveLidarrBlock::ArtistHistory => match self.key {
|
||||
_ if matches_key!(left, self.key) => {
|
||||
self.app.data.lidarr_data.artist_info_tabs.previous();
|
||||
self.app.pop_and_push_navigation_stack(
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.lidarr_data
|
||||
.artist_info_tabs
|
||||
.get_active_route(),
|
||||
);
|
||||
}
|
||||
_ if matches_key!(right, self.key) => {
|
||||
self.app.data.lidarr_data.artist_info_tabs.next();
|
||||
self.app.pop_and_push_navigation_stack(
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.lidarr_data
|
||||
.artist_info_tabs
|
||||
.get_active_route(),
|
||||
);
|
||||
}
|
||||
_ => (),
|
||||
},
|
||||
ActiveLidarrBlock::UpdateAndScanArtistPrompt
|
||||
| ActiveLidarrBlock::AutomaticallySearchArtistPrompt => {
|
||||
handle_prompt_toggle(self.app, self.key);
|
||||
@@ -116,6 +168,20 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveLidarrBlock> for ArtistDetailsHandler
|
||||
|
||||
fn handle_submit(&mut self) {
|
||||
match self.active_lidarr_block {
|
||||
ActiveLidarrBlock::ArtistHistory
|
||||
if !self
|
||||
.app
|
||||
.data
|
||||
.lidarr_data
|
||||
.artist_history
|
||||
.as_ref()
|
||||
.expect("Artist history should be Some")
|
||||
.is_empty() =>
|
||||
{
|
||||
self
|
||||
.app
|
||||
.push_navigation_stack(ActiveLidarrBlock::ArtistHistoryDetails.into());
|
||||
}
|
||||
ActiveLidarrBlock::AutomaticallySearchArtistPrompt => {
|
||||
if self.app.data.lidarr_data.prompt_confirm {
|
||||
self.app.data.lidarr_data.prompt_confirm_action = Some(
|
||||
@@ -144,6 +210,33 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveLidarrBlock> for ArtistDetailsHandler
|
||||
self.app.pop_navigation_stack();
|
||||
self.app.data.lidarr_data.prompt_confirm = false;
|
||||
}
|
||||
ActiveLidarrBlock::ArtistHistoryDetails => {
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
ActiveLidarrBlock::ArtistHistory => {
|
||||
if self
|
||||
.app
|
||||
.data
|
||||
.lidarr_data
|
||||
.artist_history
|
||||
.as_ref()
|
||||
.expect("Artist history is not populated")
|
||||
.filtered_items
|
||||
.is_some()
|
||||
{
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.lidarr_data
|
||||
.artist_history
|
||||
.as_mut()
|
||||
.expect("Artist history is not populated")
|
||||
.reset_filter();
|
||||
} else {
|
||||
self.app.pop_navigation_stack();
|
||||
self.app.data.lidarr_data.reset_artist_info_tabs();
|
||||
}
|
||||
}
|
||||
ActiveLidarrBlock::ArtistDetails => {
|
||||
self.app.pop_navigation_stack();
|
||||
self.app.data.lidarr_data.reset_artist_info_tabs();
|
||||
@@ -194,6 +287,34 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveLidarrBlock> for ArtistDetailsHandler
|
||||
}
|
||||
_ => (),
|
||||
},
|
||||
ActiveLidarrBlock::ArtistHistory => match self.key {
|
||||
_ if matches_key!(refresh, key) => self
|
||||
.app
|
||||
.pop_and_push_navigation_stack(self.active_lidarr_block.into()),
|
||||
_ if matches_key!(auto_search, key) => {
|
||||
self
|
||||
.app
|
||||
.push_navigation_stack(ActiveLidarrBlock::AutomaticallySearchArtistPrompt.into());
|
||||
}
|
||||
_ if matches_key!(edit, key) => {
|
||||
self.app.push_navigation_stack(
|
||||
(
|
||||
ActiveLidarrBlock::EditArtistPrompt,
|
||||
Some(self.active_lidarr_block),
|
||||
)
|
||||
.into(),
|
||||
);
|
||||
self.app.data.lidarr_data.edit_artist_modal = Some((&self.app.data.lidarr_data).into());
|
||||
self.app.data.lidarr_data.selected_block =
|
||||
BlockSelectionState::new(EDIT_ARTIST_SELECTION_BLOCKS);
|
||||
}
|
||||
_ if matches_key!(update, key) => {
|
||||
self
|
||||
.app
|
||||
.push_navigation_stack(ActiveLidarrBlock::UpdateAndScanArtistPrompt.into());
|
||||
}
|
||||
_ => (),
|
||||
},
|
||||
ActiveLidarrBlock::AutomaticallySearchArtistPrompt => {
|
||||
if matches_key!(confirm, key) {
|
||||
self.app.data.lidarr_data.prompt_confirm = true;
|
||||
|
||||
@@ -11,6 +11,7 @@ mod tests {
|
||||
use crate::models::servarr_data::lidarr::lidarr_data::{
|
||||
ARTIST_DETAILS_BLOCKS, ActiveLidarrBlock, DELETE_ALBUM_BLOCKS,
|
||||
};
|
||||
use crate::models::stateful_table::StatefulTable;
|
||||
|
||||
mod test_handle_delete {
|
||||
use super::*;
|
||||
@@ -80,13 +81,15 @@ mod tests {
|
||||
mod test_handle_submit {
|
||||
use crate::app::App;
|
||||
use crate::app::key_binding::DEFAULT_KEYBINDINGS;
|
||||
use crate::assert_navigation_popped;
|
||||
use crate::event::Key;
|
||||
use crate::handlers::KeyEventHandler;
|
||||
use crate::handlers::lidarr_handlers::library::artist_details_handler::ArtistDetailsHandler;
|
||||
use crate::models::lidarr_models::LidarrHistoryItem;
|
||||
use crate::models::servarr_data::lidarr::lidarr_data::ActiveLidarrBlock;
|
||||
use crate::models::stateful_table::StatefulTable;
|
||||
use crate::network::lidarr_network::LidarrEvent;
|
||||
use crate::network::lidarr_network::lidarr_network_test_utils::test_utils::artist;
|
||||
use crate::{assert_navigation_popped, assert_navigation_pushed};
|
||||
use rstest::rstest;
|
||||
|
||||
const SUBMIT_KEY: Key = DEFAULT_KEYBINDINGS.submit.key;
|
||||
@@ -138,6 +141,46 @@ mod tests {
|
||||
assert_navigation_popped!(app, ActiveLidarrBlock::ArtistDetails.into());
|
||||
assert_none!(app.data.lidarr_data.prompt_confirm_action);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_artist_history_submit() {
|
||||
let mut app = App::test_default();
|
||||
let mut artist_history = StatefulTable::default();
|
||||
artist_history.set_items(vec![LidarrHistoryItem::default()]);
|
||||
app.data.lidarr_data.artist_history = Some(artist_history);
|
||||
|
||||
ArtistDetailsHandler::new(SUBMIT_KEY, &mut app, ActiveLidarrBlock::ArtistHistory, None)
|
||||
.handle();
|
||||
|
||||
assert_navigation_pushed!(app, ActiveLidarrBlock::ArtistHistoryDetails.into());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_artist_history_submit_no_op_when_artist_history_is_empty() {
|
||||
let mut app = App::test_default();
|
||||
app.push_navigation_stack(ActiveLidarrBlock::ArtistHistory.into());
|
||||
app.data.lidarr_data.artist_history = Some(StatefulTable::default());
|
||||
|
||||
ArtistDetailsHandler::new(SUBMIT_KEY, &mut app, ActiveLidarrBlock::ArtistHistory, None)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
ActiveLidarrBlock::ArtistHistory.into()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_artist_history_submit_no_op_when_not_ready() {
|
||||
let mut app = App::test_default();
|
||||
app.is_loading = true;
|
||||
app.push_navigation_stack(ActiveLidarrBlock::Artists.into());
|
||||
|
||||
ArtistDetailsHandler::new(SUBMIT_KEY, &mut app, ActiveLidarrBlock::ArtistHistory, None)
|
||||
.handle();
|
||||
|
||||
assert_eq!(app.get_current_route(), ActiveLidarrBlock::Artists.into());
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_esc {
|
||||
@@ -147,11 +190,71 @@ mod tests {
|
||||
use crate::event::Key;
|
||||
use crate::handlers::KeyEventHandler;
|
||||
use crate::handlers::lidarr_handlers::library::artist_details_handler::ArtistDetailsHandler;
|
||||
use crate::models::lidarr_models::LidarrHistoryItem;
|
||||
use crate::models::servarr_data::lidarr::lidarr_data::ActiveLidarrBlock;
|
||||
use crate::models::stateful_table::StatefulTable;
|
||||
use ratatui::widgets::TableState;
|
||||
use rstest::rstest;
|
||||
|
||||
const ESC_KEY: Key = DEFAULT_KEYBINDINGS.esc.key;
|
||||
|
||||
#[test]
|
||||
fn test_artist_history_details_block_esc() {
|
||||
let mut app = App::test_default();
|
||||
app.push_navigation_stack(ActiveLidarrBlock::ArtistHistory.into());
|
||||
app.push_navigation_stack(ActiveLidarrBlock::ArtistHistoryDetails.into());
|
||||
|
||||
ArtistDetailsHandler::new(
|
||||
ESC_KEY,
|
||||
&mut app,
|
||||
ActiveLidarrBlock::ArtistHistoryDetails,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_navigation_popped!(app, ActiveLidarrBlock::ArtistHistory.into());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_artist_history_esc_resets_filter_if_one_is_set_instead_of_closing_the_window() {
|
||||
let mut app = App::test_default();
|
||||
let artist_history = StatefulTable {
|
||||
filter: Some("Test".into()),
|
||||
filtered_items: Some(vec![LidarrHistoryItem::default()]),
|
||||
filtered_state: Some(TableState::default()),
|
||||
..StatefulTable::default()
|
||||
};
|
||||
app.data.lidarr_data.artist_history = Some(artist_history);
|
||||
app.push_navigation_stack(ActiveLidarrBlock::Artists.into());
|
||||
app.push_navigation_stack(ActiveLidarrBlock::ArtistHistory.into());
|
||||
|
||||
ArtistDetailsHandler::new(ESC_KEY, &mut app, ActiveLidarrBlock::ArtistHistory, None).handle();
|
||||
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
ActiveLidarrBlock::ArtistHistory.into()
|
||||
);
|
||||
assert_none!(app.data.lidarr_data.artist_history.as_ref().unwrap().filter);
|
||||
assert_none!(
|
||||
app
|
||||
.data
|
||||
.lidarr_data
|
||||
.artist_history
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.filtered_items
|
||||
);
|
||||
assert_none!(
|
||||
app
|
||||
.data
|
||||
.lidarr_data
|
||||
.artist_history
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.filtered_state
|
||||
);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_artist_details_esc(
|
||||
#[values(
|
||||
@@ -191,7 +294,8 @@ mod tests {
|
||||
|
||||
#[rstest]
|
||||
fn test_artist_details_edit_key(
|
||||
#[values(ActiveLidarrBlock::ArtistDetails)] active_lidarr_block: ActiveLidarrBlock,
|
||||
#[values(ActiveLidarrBlock::ArtistDetails, ActiveLidarrBlock::ArtistHistory)]
|
||||
active_lidarr_block: ActiveLidarrBlock,
|
||||
) {
|
||||
let mut app = App::test_default_fully_populated();
|
||||
app.push_navigation_stack(ActiveLidarrBlock::ArtistDetails.into());
|
||||
@@ -209,12 +313,12 @@ mod tests {
|
||||
app,
|
||||
(
|
||||
ActiveLidarrBlock::EditArtistPrompt,
|
||||
Some(ActiveLidarrBlock::ArtistDetails)
|
||||
Some(active_lidarr_block)
|
||||
)
|
||||
.into()
|
||||
);
|
||||
assert_modal_present!(app.data.lidarr_data.edit_artist_modal);
|
||||
assert!(app.data.lidarr_data.edit_artist_modal.is_some());
|
||||
assert_some!(app.data.lidarr_data.edit_artist_modal);
|
||||
assert_eq!(
|
||||
app.data.lidarr_data.selected_block.blocks,
|
||||
EDIT_ARTIST_SELECTION_BLOCKS
|
||||
@@ -223,7 +327,8 @@ mod tests {
|
||||
|
||||
#[rstest]
|
||||
fn test_artist_details_edit_key_no_op_when_not_ready(
|
||||
#[values(ActiveLidarrBlock::ArtistDetails)] active_lidarr_block: ActiveLidarrBlock,
|
||||
#[values(ActiveLidarrBlock::ArtistDetails, ActiveLidarrBlock::ArtistHistory)]
|
||||
active_lidarr_block: ActiveLidarrBlock,
|
||||
) {
|
||||
let mut app = App::test_default();
|
||||
app.is_loading = true;
|
||||
@@ -315,7 +420,8 @@ mod tests {
|
||||
|
||||
#[rstest]
|
||||
fn test_artist_details_auto_search_key(
|
||||
#[values(ActiveLidarrBlock::ArtistDetails)] active_lidarr_block: ActiveLidarrBlock,
|
||||
#[values(ActiveLidarrBlock::ArtistDetails, ActiveLidarrBlock::ArtistHistory)]
|
||||
active_lidarr_block: ActiveLidarrBlock,
|
||||
) {
|
||||
let mut app = App::test_default_fully_populated();
|
||||
app.push_navigation_stack(active_lidarr_block.into());
|
||||
@@ -336,7 +442,8 @@ mod tests {
|
||||
|
||||
#[rstest]
|
||||
fn test_artist_details_auto_search_key_no_op_when_not_ready(
|
||||
#[values(ActiveLidarrBlock::ArtistDetails)] active_lidarr_block: ActiveLidarrBlock,
|
||||
#[values(ActiveLidarrBlock::ArtistDetails, ActiveLidarrBlock::ArtistHistory)]
|
||||
active_lidarr_block: ActiveLidarrBlock,
|
||||
) {
|
||||
let mut app = App::test_default_fully_populated();
|
||||
app.is_loading = true;
|
||||
@@ -355,7 +462,8 @@ mod tests {
|
||||
|
||||
#[rstest]
|
||||
fn test_artist_details_update_key(
|
||||
#[values(ActiveLidarrBlock::ArtistDetails)] active_lidarr_block: ActiveLidarrBlock,
|
||||
#[values(ActiveLidarrBlock::ArtistDetails, ActiveLidarrBlock::ArtistHistory)]
|
||||
active_lidarr_block: ActiveLidarrBlock,
|
||||
) {
|
||||
let mut app = App::test_default_fully_populated();
|
||||
app.push_navigation_stack(active_lidarr_block.into());
|
||||
@@ -373,7 +481,8 @@ mod tests {
|
||||
|
||||
#[rstest]
|
||||
fn test_artist_details_update_key_no_op_when_not_ready(
|
||||
#[values(ActiveLidarrBlock::ArtistDetails)] active_lidarr_block: ActiveLidarrBlock,
|
||||
#[values(ActiveLidarrBlock::ArtistDetails, ActiveLidarrBlock::ArtistHistory)]
|
||||
active_lidarr_block: ActiveLidarrBlock,
|
||||
) {
|
||||
let mut app = App::test_default_fully_populated();
|
||||
app.is_loading = true;
|
||||
@@ -392,7 +501,8 @@ mod tests {
|
||||
|
||||
#[rstest]
|
||||
fn test_artist_details_refresh_key(
|
||||
#[values(ActiveLidarrBlock::ArtistDetails)] active_lidarr_block: ActiveLidarrBlock,
|
||||
#[values(ActiveLidarrBlock::ArtistDetails, ActiveLidarrBlock::ArtistHistory)]
|
||||
active_lidarr_block: ActiveLidarrBlock,
|
||||
) {
|
||||
let mut app = App::test_default_fully_populated();
|
||||
app.is_routing = false;
|
||||
@@ -413,7 +523,8 @@ mod tests {
|
||||
|
||||
#[rstest]
|
||||
fn test_artist_details_refresh_key_no_op_when_not_ready(
|
||||
#[values(ActiveLidarrBlock::ArtistDetails)] active_lidarr_block: ActiveLidarrBlock,
|
||||
#[values(ActiveLidarrBlock::ArtistDetails, ActiveLidarrBlock::ArtistHistory)]
|
||||
active_lidarr_block: ActiveLidarrBlock,
|
||||
) {
|
||||
let mut app = App::test_default();
|
||||
app.is_loading = true;
|
||||
@@ -444,7 +555,8 @@ mod tests {
|
||||
fn test_artist_details_prompt_confirm_key(
|
||||
#[case] prompt_block: ActiveLidarrBlock,
|
||||
#[case] expected_action: LidarrEvent,
|
||||
#[values(ActiveLidarrBlock::ArtistDetails)] active_lidarr_block: ActiveLidarrBlock,
|
||||
#[values(ActiveLidarrBlock::ArtistDetails, ActiveLidarrBlock::ArtistHistory)]
|
||||
active_lidarr_block: ActiveLidarrBlock,
|
||||
) {
|
||||
let mut app = App::test_default_fully_populated();
|
||||
app.push_navigation_stack(active_lidarr_block.into());
|
||||
@@ -562,4 +674,35 @@ mod tests {
|
||||
|
||||
assert!(handler.is_ready());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_artist_details_handler_is_not_ready_when_not_loading_and_artist_history_is_none() {
|
||||
let mut app = App::test_default();
|
||||
app.push_navigation_stack(ActiveLidarrBlock::Artists.into());
|
||||
|
||||
let handler = ArtistDetailsHandler::new(
|
||||
DEFAULT_KEYBINDINGS.esc.key,
|
||||
&mut app,
|
||||
ActiveLidarrBlock::ArtistHistory,
|
||||
None,
|
||||
);
|
||||
|
||||
assert!(!handler.is_ready());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_artist_details_handler_ready_when_not_loading_and_artist_history_is_some() {
|
||||
let mut app = App::test_default();
|
||||
app.push_navigation_stack(ActiveLidarrBlock::Artists.into());
|
||||
app.data.lidarr_data.artist_history = Some(StatefulTable::default());
|
||||
|
||||
let handler = ArtistDetailsHandler::new(
|
||||
DEFAULT_KEYBINDINGS.esc.key,
|
||||
&mut app,
|
||||
ActiveLidarrBlock::ArtistHistory,
|
||||
None,
|
||||
);
|
||||
|
||||
assert!(handler.is_ready());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user