feat: CLI and TUI support for track history and track details in Lidarr
This commit is contained in:
@@ -227,22 +227,22 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveLidarrBlock> for AlbumDetailsHandler<
|
||||
|
||||
fn handle_submit(&mut self) {
|
||||
match self.active_lidarr_block {
|
||||
// ActiveLidarrBlock::AlbumDetails
|
||||
// if self.app.data.lidarr_data.album_details_modal.is_some()
|
||||
// && !self
|
||||
// .app
|
||||
// .data
|
||||
// .lidarr_data
|
||||
// .album_details_modal
|
||||
// .as_ref()
|
||||
// .unwrap()
|
||||
// .tracks
|
||||
// .is_empty() =>
|
||||
// {
|
||||
// self
|
||||
// .app
|
||||
// .push_navigation_stack(ActiveLidarrBlock::TrackDetails.into())
|
||||
// }
|
||||
ActiveLidarrBlock::AlbumDetails
|
||||
if self.app.data.lidarr_data.album_details_modal.is_some()
|
||||
&& !self
|
||||
.app
|
||||
.data
|
||||
.lidarr_data
|
||||
.album_details_modal
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.tracks
|
||||
.is_empty() =>
|
||||
{
|
||||
self
|
||||
.app
|
||||
.push_navigation_stack(ActiveLidarrBlock::TrackDetails.into())
|
||||
}
|
||||
ActiveLidarrBlock::AlbumHistory => self
|
||||
.app
|
||||
.push_navigation_stack(ActiveLidarrBlock::AlbumHistoryDetails.into()),
|
||||
|
||||
@@ -155,37 +155,37 @@ mod tests {
|
||||
|
||||
const SUBMIT_KEY: Key = DEFAULT_KEYBINDINGS.submit.key;
|
||||
|
||||
// #[test]
|
||||
// fn test_album_details_submit() {
|
||||
// let mut app = App::test_default_fully_populated();
|
||||
// app.push_navigation_stack(ActiveLidarrBlock::AlbumDetails.into());
|
||||
//
|
||||
// AlbumDetailsHandler::new(SUBMIT_KEY, &mut app, ActiveLidarrBlock::AlbumDetails, None)
|
||||
// .handle();
|
||||
//
|
||||
// assert_navigation_pushed!(app, ActiveLidarrBlock::TrackDetails.into());
|
||||
// }
|
||||
#[test]
|
||||
fn test_album_details_submit() {
|
||||
let mut app = App::test_default_fully_populated();
|
||||
app.push_navigation_stack(ActiveLidarrBlock::AlbumDetails.into());
|
||||
|
||||
// #[test]
|
||||
// fn test_album_details_submit_no_op_on_empty_tracks_table() {
|
||||
// let mut app = App::test_default_fully_populated();
|
||||
// app
|
||||
// .data
|
||||
// .lidarr_data
|
||||
// .album_details_modal
|
||||
// .as_mut()
|
||||
// .unwrap()
|
||||
// .tracks = StatefulTable::default();
|
||||
// app.push_navigation_stack(ActiveLidarrBlock::AlbumDetails.into());
|
||||
//
|
||||
// AlbumDetailsHandler::new(SUBMIT_KEY, &mut app, ActiveLidarrBlock::AlbumDetails, None)
|
||||
// .handle();
|
||||
//
|
||||
// assert_eq!(
|
||||
// app.get_current_route(),
|
||||
// ActiveLidarrBlock::AlbumDetails.into()
|
||||
// );
|
||||
// }
|
||||
AlbumDetailsHandler::new(SUBMIT_KEY, &mut app, ActiveLidarrBlock::AlbumDetails, None)
|
||||
.handle();
|
||||
|
||||
assert_navigation_pushed!(app, ActiveLidarrBlock::TrackDetails.into());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_album_details_submit_no_op_on_empty_tracks_table() {
|
||||
let mut app = App::test_default_fully_populated();
|
||||
app
|
||||
.data
|
||||
.lidarr_data
|
||||
.album_details_modal
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.tracks = StatefulTable::default();
|
||||
app.push_navigation_stack(ActiveLidarrBlock::AlbumDetails.into());
|
||||
|
||||
AlbumDetailsHandler::new(SUBMIT_KEY, &mut app, ActiveLidarrBlock::AlbumDetails, None)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
ActiveLidarrBlock::AlbumDetails.into()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_album_details_submit_no_op_when_not_ready() {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
use crate::app::App;
|
||||
use crate::event::Key;
|
||||
use crate::handlers::lidarr_handlers::history::history_sorting_options;
|
||||
use crate::handlers::lidarr_handlers::library::album_details_handler::AlbumDetailsHandler;
|
||||
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;
|
||||
@@ -26,7 +24,7 @@ pub struct ArtistDetailsHandler<'a, 'b> {
|
||||
key: Key,
|
||||
app: &'a mut App<'b>,
|
||||
active_lidarr_block: ActiveLidarrBlock,
|
||||
context: Option<ActiveLidarrBlock>,
|
||||
_context: Option<ActiveLidarrBlock>,
|
||||
}
|
||||
|
||||
impl ArtistDetailsHandler<'_, '_> {
|
||||
@@ -76,24 +74,12 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveLidarrBlock> for ArtistDetailsHandler
|
||||
|app| &mut app.data.lidarr_data.discography_releases,
|
||||
artist_releases_table_handling_config,
|
||||
) {
|
||||
match self.active_lidarr_block {
|
||||
_ if DeleteAlbumHandler::accepts(self.active_lidarr_block) => {
|
||||
DeleteAlbumHandler::new(self.key, self.app, self.active_lidarr_block, self.context)
|
||||
.handle();
|
||||
}
|
||||
_ if AlbumDetailsHandler::accepts(self.active_lidarr_block) => {
|
||||
AlbumDetailsHandler::new(self.key, self.app, self.active_lidarr_block, self.context)
|
||||
.handle();
|
||||
}
|
||||
_ => self.handle_key_event(),
|
||||
};
|
||||
self.handle_key_event();
|
||||
}
|
||||
}
|
||||
|
||||
fn accepts(active_block: ActiveLidarrBlock) -> bool {
|
||||
DeleteAlbumHandler::accepts(active_block)
|
||||
|| AlbumDetailsHandler::accepts(active_block)
|
||||
|| ARTIST_DETAILS_BLOCKS.contains(&active_block)
|
||||
ARTIST_DETAILS_BLOCKS.contains(&active_block)
|
||||
}
|
||||
|
||||
fn ignore_special_keys(&self) -> bool {
|
||||
@@ -104,13 +90,13 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveLidarrBlock> for ArtistDetailsHandler
|
||||
key: Key,
|
||||
app: &'a mut App<'b>,
|
||||
active_block: ActiveLidarrBlock,
|
||||
context: Option<ActiveLidarrBlock>,
|
||||
_context: Option<ActiveLidarrBlock>,
|
||||
) -> ArtistDetailsHandler<'a, 'b> {
|
||||
ArtistDetailsHandler {
|
||||
key,
|
||||
app,
|
||||
active_lidarr_block: active_block,
|
||||
context,
|
||||
_context,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,12 +13,11 @@ mod tests {
|
||||
ArtistDetailsHandler, releases_sorting_options,
|
||||
};
|
||||
use crate::models::HorizontallyScrollableText;
|
||||
use crate::models::lidarr_models::{Album, LidarrHistoryItem, LidarrRelease};
|
||||
use crate::models::lidarr_models::{LidarrHistoryItem, LidarrRelease};
|
||||
use crate::models::servarr_data::lidarr::lidarr_data::{
|
||||
ALBUM_DETAILS_BLOCKS, ARTIST_DETAILS_BLOCKS, ActiveLidarrBlock, DELETE_ALBUM_BLOCKS,
|
||||
ARTIST_DETAILS_BLOCKS, ActiveLidarrBlock,
|
||||
};
|
||||
use crate::models::servarr_models::{Quality, QualityWrapper};
|
||||
use crate::test_handler_delegation;
|
||||
|
||||
mod test_handle_delete {
|
||||
use super::*;
|
||||
@@ -812,12 +811,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_artist_details_handler_accepts() {
|
||||
let mut artist_details_blocks = ARTIST_DETAILS_BLOCKS.clone().to_vec();
|
||||
artist_details_blocks.extend(DELETE_ALBUM_BLOCKS);
|
||||
artist_details_blocks.extend(ALBUM_DETAILS_BLOCKS);
|
||||
|
||||
ActiveLidarrBlock::iter().for_each(|active_lidarr_block| {
|
||||
if artist_details_blocks.contains(&active_lidarr_block) {
|
||||
if ARTIST_DETAILS_BLOCKS.contains(&active_lidarr_block) {
|
||||
assert!(ArtistDetailsHandler::accepts(active_lidarr_block));
|
||||
} else {
|
||||
assert!(!ArtistDetailsHandler::accepts(active_lidarr_block));
|
||||
@@ -977,58 +972,6 @@ mod tests {
|
||||
assert!(handler.is_ready());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_delegates_delete_album_blocks_to_delete_album_handler() {
|
||||
let mut app = App::test_default();
|
||||
app
|
||||
.data
|
||||
.lidarr_data
|
||||
.albums
|
||||
.set_items(vec![Album::default()]);
|
||||
app.push_navigation_stack(ActiveLidarrBlock::ArtistDetails.into());
|
||||
app.push_navigation_stack(ActiveLidarrBlock::DeleteAlbumPrompt.into());
|
||||
|
||||
ArtistDetailsHandler::new(
|
||||
DEFAULT_KEYBINDINGS.esc.key,
|
||||
&mut app,
|
||||
ActiveLidarrBlock::DeleteAlbumPrompt,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
ActiveLidarrBlock::ArtistDetails.into()
|
||||
);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_delegates_album_details_blocks_to_album_details_handler(
|
||||
#[values(
|
||||
ActiveLidarrBlock::AlbumDetails,
|
||||
ActiveLidarrBlock::AlbumHistory,
|
||||
ActiveLidarrBlock::SearchTracks,
|
||||
ActiveLidarrBlock::SearchTracksError,
|
||||
ActiveLidarrBlock::AutomaticallySearchAlbumPrompt,
|
||||
ActiveLidarrBlock::SearchAlbumHistory,
|
||||
ActiveLidarrBlock::SearchAlbumHistoryError,
|
||||
ActiveLidarrBlock::FilterAlbumHistory,
|
||||
ActiveLidarrBlock::FilterAlbumHistoryError,
|
||||
ActiveLidarrBlock::AlbumHistorySortPrompt,
|
||||
ActiveLidarrBlock::AlbumHistoryDetails,
|
||||
ActiveLidarrBlock::ManualAlbumSearch,
|
||||
ActiveLidarrBlock::ManualAlbumSearchSortPrompt,
|
||||
ActiveLidarrBlock::DeleteTrackFilePrompt
|
||||
)]
|
||||
active_sonarr_block: ActiveLidarrBlock,
|
||||
) {
|
||||
test_handler_delegation!(
|
||||
ArtistDetailsHandler,
|
||||
ActiveLidarrBlock::Artists,
|
||||
active_sonarr_block
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_releases_sorting_options_source() {
|
||||
let expected_cmp_fn: fn(&LidarrRelease, &LidarrRelease) -> Ordering =
|
||||
|
||||
@@ -15,7 +15,7 @@ mod tests {
|
||||
use crate::models::servarr_data::lidarr::lidarr_data::{
|
||||
ADD_ARTIST_BLOCKS, ALBUM_DETAILS_BLOCKS, ARTIST_DETAILS_BLOCKS, ActiveLidarrBlock,
|
||||
DELETE_ALBUM_BLOCKS, DELETE_ARTIST_BLOCKS, EDIT_ARTIST_BLOCKS, EDIT_ARTIST_SELECTION_BLOCKS,
|
||||
LIBRARY_BLOCKS,
|
||||
LIBRARY_BLOCKS, TRACK_DETAILS_BLOCKS,
|
||||
};
|
||||
use crate::models::servarr_data::lidarr::modals::EditArtistModal;
|
||||
use crate::network::lidarr_network::LidarrEvent;
|
||||
@@ -34,10 +34,14 @@ mod tests {
|
||||
library_handler_blocks.extend(EDIT_ARTIST_BLOCKS);
|
||||
library_handler_blocks.extend(ADD_ARTIST_BLOCKS);
|
||||
library_handler_blocks.extend(ALBUM_DETAILS_BLOCKS);
|
||||
library_handler_blocks.extend(TRACK_DETAILS_BLOCKS);
|
||||
|
||||
ActiveLidarrBlock::iter().for_each(|lidarr_block| {
|
||||
if library_handler_blocks.contains(&lidarr_block) {
|
||||
assert!(LibraryHandler::accepts(lidarr_block));
|
||||
assert!(
|
||||
LibraryHandler::accepts(lidarr_block),
|
||||
"{lidarr_block} is not accepted by the LibraryHandler"
|
||||
);
|
||||
} else {
|
||||
assert!(!LibraryHandler::accepts(lidarr_block));
|
||||
}
|
||||
@@ -670,6 +674,27 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_delegates_track_details_blocks_to_track_details_handler(
|
||||
#[values(
|
||||
ActiveLidarrBlock::TrackDetails,
|
||||
ActiveLidarrBlock::TrackHistory,
|
||||
ActiveLidarrBlock::TrackHistoryDetails,
|
||||
ActiveLidarrBlock::SearchTrackHistory,
|
||||
ActiveLidarrBlock::SearchTrackHistoryError,
|
||||
ActiveLidarrBlock::FilterTrackHistory,
|
||||
ActiveLidarrBlock::FilterTrackHistoryError,
|
||||
ActiveLidarrBlock::TrackHistorySortPrompt
|
||||
)]
|
||||
active_sonarr_block: ActiveLidarrBlock,
|
||||
) {
|
||||
test_handler_delegation!(
|
||||
LibraryHandler,
|
||||
ActiveLidarrBlock::AlbumDetails,
|
||||
active_sonarr_block
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_edit_key() {
|
||||
let mut app = App::test_default();
|
||||
|
||||
@@ -19,18 +19,22 @@ use super::handle_change_tab_left_right_keys;
|
||||
use crate::handlers::table_handler::{TableHandlingConfig, handle_table};
|
||||
|
||||
mod add_artist_handler;
|
||||
mod album_details_handler;
|
||||
mod artist_details_handler;
|
||||
mod delete_album_handler;
|
||||
mod delete_artist_handler;
|
||||
mod edit_artist_handler;
|
||||
mod track_details_handler;
|
||||
|
||||
use crate::handlers::lidarr_handlers::library::album_details_handler::AlbumDetailsHandler;
|
||||
use crate::handlers::lidarr_handlers::library::delete_album_handler::DeleteAlbumHandler;
|
||||
use crate::handlers::lidarr_handlers::library::track_details_handler::TrackDetailsHandler;
|
||||
use crate::models::Route;
|
||||
pub(in crate::handlers::lidarr_handlers) use add_artist_handler::AddArtistHandler;
|
||||
pub(in crate::handlers::lidarr_handlers) use artist_details_handler::ArtistDetailsHandler;
|
||||
pub(in crate::handlers::lidarr_handlers) use delete_artist_handler::DeleteArtistHandler;
|
||||
pub(in crate::handlers::lidarr_handlers) use edit_artist_handler::EditArtistHandler;
|
||||
|
||||
mod album_details_handler;
|
||||
#[cfg(test)]
|
||||
#[path = "library_handler_tests.rs"]
|
||||
mod library_handler_tests;
|
||||
@@ -82,6 +86,18 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveLidarrBlock> for LibraryHandler<'a, '
|
||||
ArtistDetailsHandler::new(self.key, self.app, self.active_lidarr_block, self.context)
|
||||
.handle();
|
||||
}
|
||||
_ if DeleteAlbumHandler::accepts(self.active_lidarr_block) => {
|
||||
DeleteAlbumHandler::new(self.key, self.app, self.active_lidarr_block, self.context)
|
||||
.handle();
|
||||
}
|
||||
_ if AlbumDetailsHandler::accepts(self.active_lidarr_block) => {
|
||||
AlbumDetailsHandler::new(self.key, self.app, self.active_lidarr_block, self.context)
|
||||
.handle();
|
||||
}
|
||||
_ if TrackDetailsHandler::accepts(self.active_lidarr_block) => {
|
||||
TrackDetailsHandler::new(self.key, self.app, self.active_lidarr_block, self.context)
|
||||
.handle();
|
||||
}
|
||||
_ => self.handle_key_event(),
|
||||
}
|
||||
}
|
||||
@@ -90,8 +106,11 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveLidarrBlock> for LibraryHandler<'a, '
|
||||
fn accepts(active_block: ActiveLidarrBlock) -> bool {
|
||||
AddArtistHandler::accepts(active_block)
|
||||
|| DeleteArtistHandler::accepts(active_block)
|
||||
|| DeleteAlbumHandler::accepts(active_block)
|
||||
|| EditArtistHandler::accepts(active_block)
|
||||
|| ArtistDetailsHandler::accepts(active_block)
|
||||
|| AlbumDetailsHandler::accepts(active_block)
|
||||
|| TrackDetailsHandler::accepts(active_block)
|
||||
|| LIBRARY_BLOCKS.contains(&active_block)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,225 @@
|
||||
use crate::app::App;
|
||||
use crate::event::Key;
|
||||
use crate::handlers::KeyEventHandler;
|
||||
use crate::handlers::lidarr_handlers::history::history_sorting_options;
|
||||
use crate::handlers::table_handler::{TableHandlingConfig, handle_table};
|
||||
use crate::matches_key;
|
||||
use crate::models::Route;
|
||||
use crate::models::lidarr_models::LidarrHistoryItem;
|
||||
use crate::models::servarr_data::lidarr::lidarr_data::{ActiveLidarrBlock, TRACK_DETAILS_BLOCKS};
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "track_details_handler_tests.rs"]
|
||||
mod track_details_handler_tests;
|
||||
|
||||
pub(super) struct TrackDetailsHandler<'a, 'b> {
|
||||
key: Key,
|
||||
app: &'a mut App<'b>,
|
||||
active_lidarr_block: ActiveLidarrBlock,
|
||||
_context: Option<ActiveLidarrBlock>,
|
||||
}
|
||||
|
||||
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveLidarrBlock> for TrackDetailsHandler<'a, 'b> {
|
||||
fn handle(&mut self) {
|
||||
let track_history_table_handling_config =
|
||||
TableHandlingConfig::new(ActiveLidarrBlock::TrackHistory.into())
|
||||
.sorting_block(ActiveLidarrBlock::TrackHistorySortPrompt.into())
|
||||
.sort_options(history_sorting_options())
|
||||
.searching_block(ActiveLidarrBlock::SearchTrackHistory.into())
|
||||
.search_error_block(ActiveLidarrBlock::SearchTrackHistoryError.into())
|
||||
.search_field_fn(|history_item: &LidarrHistoryItem| &history_item.source_title.text)
|
||||
.filtering_block(ActiveLidarrBlock::FilterTrackHistory.into())
|
||||
.filter_error_block(ActiveLidarrBlock::FilterTrackHistoryError.into())
|
||||
.filter_field_fn(|history_item: &LidarrHistoryItem| &history_item.source_title.text);
|
||||
|
||||
if !handle_table(
|
||||
self,
|
||||
|app| {
|
||||
&mut app
|
||||
.data
|
||||
.lidarr_data
|
||||
.album_details_modal
|
||||
.as_mut()
|
||||
.expect("Album details modal is undefined")
|
||||
.track_details_modal
|
||||
.as_mut()
|
||||
.expect("Track details modal is undefined")
|
||||
.track_history
|
||||
},
|
||||
track_history_table_handling_config,
|
||||
) {
|
||||
self.handle_key_event();
|
||||
}
|
||||
}
|
||||
|
||||
fn accepts(active_block: ActiveLidarrBlock) -> bool {
|
||||
TRACK_DETAILS_BLOCKS.contains(&active_block)
|
||||
}
|
||||
|
||||
fn new(
|
||||
key: Key,
|
||||
app: &'a mut App<'b>,
|
||||
active_lidarr_block: ActiveLidarrBlock,
|
||||
_context: Option<ActiveLidarrBlock>,
|
||||
) -> Self {
|
||||
Self {
|
||||
key,
|
||||
app,
|
||||
active_lidarr_block,
|
||||
_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 {
|
||||
if self.app.is_loading {
|
||||
return false;
|
||||
}
|
||||
|
||||
let Some(album_details_modal) = self.app.data.lidarr_data.album_details_modal.as_ref() else {
|
||||
return false;
|
||||
};
|
||||
|
||||
let Some(track_details_modal) = &album_details_modal.track_details_modal else {
|
||||
return false;
|
||||
};
|
||||
|
||||
match self.active_lidarr_block {
|
||||
ActiveLidarrBlock::TrackDetails => !track_details_modal.track_details.is_empty(),
|
||||
ActiveLidarrBlock::TrackHistory => !track_details_modal.track_history.is_empty(),
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
match self.active_lidarr_block {
|
||||
ActiveLidarrBlock::TrackDetails | ActiveLidarrBlock::TrackHistory => match self.key {
|
||||
_ if matches_key!(left, self.key) => {
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.lidarr_data
|
||||
.album_details_modal
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.track_details_modal
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.track_details_tabs
|
||||
.previous();
|
||||
self.app.pop_and_push_navigation_stack(
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.lidarr_data
|
||||
.album_details_modal
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.track_details_modal
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.track_details_tabs
|
||||
.get_active_route(),
|
||||
);
|
||||
}
|
||||
_ if matches_key!(right, self.key) => {
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.lidarr_data
|
||||
.album_details_modal
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.track_details_modal
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.track_details_tabs
|
||||
.next();
|
||||
self.app.pop_and_push_navigation_stack(
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.lidarr_data
|
||||
.album_details_modal
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.track_details_modal
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.track_details_tabs
|
||||
.get_active_route(),
|
||||
);
|
||||
}
|
||||
_ => (),
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_submit(&mut self) {
|
||||
if self.active_lidarr_block == ActiveLidarrBlock::TrackHistory {
|
||||
self
|
||||
.app
|
||||
.push_navigation_stack(ActiveLidarrBlock::TrackHistoryDetails.into());
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_esc(&mut self) {
|
||||
match self.active_lidarr_block {
|
||||
ActiveLidarrBlock::TrackDetails | ActiveLidarrBlock::TrackHistory => {
|
||||
self.app.pop_navigation_stack();
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.lidarr_data
|
||||
.album_details_modal
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.track_details_modal = None;
|
||||
}
|
||||
ActiveLidarrBlock::TrackHistoryDetails => {
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_char_key_event(&mut self) {
|
||||
match self.active_lidarr_block {
|
||||
ActiveLidarrBlock::TrackDetails | ActiveLidarrBlock::TrackHistory => match self.key {
|
||||
_ if matches_key!(refresh, self.key) => {
|
||||
self
|
||||
.app
|
||||
.pop_and_push_navigation_stack(self.active_lidarr_block.into());
|
||||
}
|
||||
_ => (),
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn app_mut(&mut self) -> &mut App<'b> {
|
||||
self.app
|
||||
}
|
||||
|
||||
fn current_route(&self) -> Route {
|
||||
self.app.get_current_route()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,407 @@
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::app::App;
|
||||
use crate::app::key_binding::DEFAULT_KEYBINDINGS;
|
||||
use crate::assert_navigation_pushed;
|
||||
use crate::handlers::KeyEventHandler;
|
||||
use crate::handlers::lidarr_handlers::library::track_details_handler::TrackDetailsHandler;
|
||||
use crate::models::ScrollableText;
|
||||
use crate::models::servarr_data::lidarr::lidarr_data::{ActiveLidarrBlock, TRACK_DETAILS_BLOCKS};
|
||||
use crate::models::stateful_table::StatefulTable;
|
||||
use pretty_assertions::assert_eq;
|
||||
use rstest::rstest;
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
mod test_handle_left_right_actions {
|
||||
use super::*;
|
||||
use pretty_assertions::assert_eq;
|
||||
use rstest::rstest;
|
||||
|
||||
#[rstest]
|
||||
#[case(ActiveLidarrBlock::TrackDetails, ActiveLidarrBlock::TrackHistory)]
|
||||
#[case(ActiveLidarrBlock::TrackHistory, ActiveLidarrBlock::TrackDetails)]
|
||||
fn test_track_details_tabs_left_right_action(
|
||||
#[case] left_block: ActiveLidarrBlock,
|
||||
#[case] right_block: ActiveLidarrBlock,
|
||||
#[values(true, false)] is_ready: bool,
|
||||
) {
|
||||
let mut app = App::test_default_fully_populated();
|
||||
app.push_navigation_stack(ActiveLidarrBlock::AlbumDetails.into());
|
||||
app.is_loading = is_ready;
|
||||
app.push_navigation_stack(right_block.into());
|
||||
app
|
||||
.data
|
||||
.lidarr_data
|
||||
.album_details_modal
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.track_details_modal
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.track_details_tabs
|
||||
.index = app
|
||||
.data
|
||||
.lidarr_data
|
||||
.album_details_modal
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.track_details_modal
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.track_details_tabs
|
||||
.tabs
|
||||
.iter()
|
||||
.position(|tab_route| tab_route.route == right_block.into())
|
||||
.unwrap_or_default();
|
||||
|
||||
TrackDetailsHandler::new(DEFAULT_KEYBINDINGS.left.key, &mut app, right_block, None).handle();
|
||||
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
app
|
||||
.data
|
||||
.lidarr_data
|
||||
.album_details_modal
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.track_details_modal
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.track_details_tabs
|
||||
.get_active_route()
|
||||
);
|
||||
assert_navigation_pushed!(app, left_block.into());
|
||||
|
||||
TrackDetailsHandler::new(DEFAULT_KEYBINDINGS.right.key, &mut app, left_block, None).handle();
|
||||
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
app
|
||||
.data
|
||||
.lidarr_data
|
||||
.album_details_modal
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.track_details_modal
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.track_details_tabs
|
||||
.get_active_route()
|
||||
);
|
||||
assert_navigation_pushed!(app, right_block.into());
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_submit {
|
||||
use super::*;
|
||||
use crate::event::Key;
|
||||
use crate::models::stateful_table::StatefulTable;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
const SUBMIT_KEY: Key = DEFAULT_KEYBINDINGS.submit.key;
|
||||
|
||||
#[test]
|
||||
fn test_track_history_submit() {
|
||||
let mut app = App::test_default_fully_populated();
|
||||
|
||||
TrackDetailsHandler::new(SUBMIT_KEY, &mut app, ActiveLidarrBlock::TrackHistory, None)
|
||||
.handle();
|
||||
|
||||
assert_navigation_pushed!(app, ActiveLidarrBlock::TrackHistoryDetails.into());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_track_history_submit_no_op_when_track_history_is_empty() {
|
||||
let mut app = App::test_default_fully_populated();
|
||||
app
|
||||
.data
|
||||
.lidarr_data
|
||||
.album_details_modal
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.track_details_modal
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.track_history = StatefulTable::default();
|
||||
app.push_navigation_stack(ActiveLidarrBlock::TrackHistory.into());
|
||||
|
||||
TrackDetailsHandler::new(SUBMIT_KEY, &mut app, ActiveLidarrBlock::TrackHistory, None)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
ActiveLidarrBlock::TrackHistory.into()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_track_history_submit_no_op_when_not_ready() {
|
||||
let mut app = App::test_default_fully_populated();
|
||||
app.is_loading = true;
|
||||
app.push_navigation_stack(ActiveLidarrBlock::TrackHistory.into());
|
||||
|
||||
TrackDetailsHandler::new(SUBMIT_KEY, &mut app, ActiveLidarrBlock::TrackHistory, None)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
ActiveLidarrBlock::TrackHistory.into()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_esc {
|
||||
use super::*;
|
||||
use crate::assert_navigation_popped;
|
||||
use crate::event::Key;
|
||||
|
||||
const ESC_KEY: Key = DEFAULT_KEYBINDINGS.esc.key;
|
||||
|
||||
#[test]
|
||||
fn test_track_history_details_block_esc() {
|
||||
let mut app = App::test_default_fully_populated();
|
||||
app.push_navigation_stack(ActiveLidarrBlock::TrackHistory.into());
|
||||
app.push_navigation_stack(ActiveLidarrBlock::TrackHistoryDetails.into());
|
||||
|
||||
TrackDetailsHandler::new(
|
||||
ESC_KEY,
|
||||
&mut app,
|
||||
ActiveLidarrBlock::TrackHistoryDetails,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_navigation_popped!(app, ActiveLidarrBlock::TrackHistory.into());
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_track_details_tabs_esc(
|
||||
#[values(ActiveLidarrBlock::TrackDetails, ActiveLidarrBlock::TrackHistory)]
|
||||
active_lidarr_block: ActiveLidarrBlock,
|
||||
) {
|
||||
let mut app = App::test_default_fully_populated();
|
||||
app.push_navigation_stack(ActiveLidarrBlock::AlbumDetails.into());
|
||||
app.push_navigation_stack(active_lidarr_block.into());
|
||||
|
||||
TrackDetailsHandler::new(ESC_KEY, &mut app, active_lidarr_block, None).handle();
|
||||
|
||||
assert_navigation_popped!(app, ActiveLidarrBlock::AlbumDetails.into());
|
||||
assert_none!(
|
||||
app
|
||||
.data
|
||||
.lidarr_data
|
||||
.album_details_modal
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.track_details_modal
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_key_char {
|
||||
use super::*;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[rstest]
|
||||
fn test_refresh_key(
|
||||
#[values(ActiveLidarrBlock::TrackDetails, ActiveLidarrBlock::TrackHistory)]
|
||||
active_lidarr_block: ActiveLidarrBlock,
|
||||
) {
|
||||
let mut app = App::test_default_fully_populated();
|
||||
app.push_navigation_stack(active_lidarr_block.into());
|
||||
app.is_routing = false;
|
||||
|
||||
TrackDetailsHandler::new(
|
||||
DEFAULT_KEYBINDINGS.refresh.key,
|
||||
&mut app,
|
||||
active_lidarr_block,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_navigation_pushed!(app, active_lidarr_block.into());
|
||||
assert!(app.is_routing);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_refresh_key_no_op_when_not_ready(
|
||||
#[values(ActiveLidarrBlock::TrackDetails, ActiveLidarrBlock::TrackHistory)]
|
||||
active_lidarr_block: ActiveLidarrBlock,
|
||||
) {
|
||||
let mut app = App::test_default_fully_populated();
|
||||
app.is_loading = true;
|
||||
app.push_navigation_stack(active_lidarr_block.into());
|
||||
app.is_routing = false;
|
||||
|
||||
TrackDetailsHandler::new(
|
||||
DEFAULT_KEYBINDINGS.refresh.key,
|
||||
&mut app,
|
||||
active_lidarr_block,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(app.get_current_route(), active_lidarr_block.into());
|
||||
assert!(!app.is_routing);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_track_details_handler_accepts() {
|
||||
ActiveLidarrBlock::iter().for_each(|active_lidarr_block| {
|
||||
if TRACK_DETAILS_BLOCKS.contains(&active_lidarr_block) {
|
||||
assert!(TrackDetailsHandler::accepts(active_lidarr_block));
|
||||
} else {
|
||||
assert!(!TrackDetailsHandler::accepts(active_lidarr_block));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_track_details_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 = TrackDetailsHandler::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_track_details_handler_is_not_ready_when_loading() {
|
||||
let mut app = App::test_default();
|
||||
app.push_navigation_stack(ActiveLidarrBlock::TrackDetails.into());
|
||||
app.is_loading = true;
|
||||
|
||||
let handler = TrackDetailsHandler::new(
|
||||
DEFAULT_KEYBINDINGS.esc.key,
|
||||
&mut app,
|
||||
ActiveLidarrBlock::TrackDetails,
|
||||
None,
|
||||
);
|
||||
|
||||
assert!(!handler.is_ready());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_track_details_handler_is_not_ready_when_album_details_modal_is_empty() {
|
||||
let mut app = App::test_default();
|
||||
app.push_navigation_stack(ActiveLidarrBlock::TrackDetails.into());
|
||||
app.is_loading = false;
|
||||
|
||||
let handler = TrackDetailsHandler::new(
|
||||
DEFAULT_KEYBINDINGS.esc.key,
|
||||
&mut app,
|
||||
ActiveLidarrBlock::TrackDetails,
|
||||
None,
|
||||
);
|
||||
|
||||
assert!(!handler.is_ready());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_track_details_handler_is_not_ready_when_track_details_modal_is_empty() {
|
||||
let mut app = App::test_default_fully_populated();
|
||||
app
|
||||
.data
|
||||
.lidarr_data
|
||||
.album_details_modal
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.track_details_modal = None;
|
||||
app.push_navigation_stack(ActiveLidarrBlock::TrackDetails.into());
|
||||
app.is_loading = false;
|
||||
|
||||
let handler = TrackDetailsHandler::new(
|
||||
DEFAULT_KEYBINDINGS.esc.key,
|
||||
&mut app,
|
||||
ActiveLidarrBlock::TrackDetails,
|
||||
None,
|
||||
);
|
||||
|
||||
assert!(!handler.is_ready());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_track_details_handler_is_not_ready_when_track_details_is_empty() {
|
||||
let mut app = App::test_default_fully_populated();
|
||||
app
|
||||
.data
|
||||
.lidarr_data
|
||||
.album_details_modal
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.track_details_modal
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.track_details = ScrollableText::default();
|
||||
app.push_navigation_stack(ActiveLidarrBlock::TrackDetails.into());
|
||||
app.is_loading = false;
|
||||
|
||||
let handler = TrackDetailsHandler::new(
|
||||
DEFAULT_KEYBINDINGS.esc.key,
|
||||
&mut app,
|
||||
ActiveLidarrBlock::TrackDetails,
|
||||
None,
|
||||
);
|
||||
|
||||
assert!(!handler.is_ready());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_track_details_handler_is_not_ready_when_track_history_table_is_empty() {
|
||||
let mut app = App::test_default_fully_populated();
|
||||
app
|
||||
.data
|
||||
.lidarr_data
|
||||
.album_details_modal
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.track_details_modal
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.track_history = StatefulTable::default();
|
||||
app.push_navigation_stack(ActiveLidarrBlock::TrackHistory.into());
|
||||
app.is_loading = false;
|
||||
|
||||
let handler = TrackDetailsHandler::new(
|
||||
DEFAULT_KEYBINDINGS.esc.key,
|
||||
&mut app,
|
||||
ActiveLidarrBlock::TrackHistory,
|
||||
None,
|
||||
);
|
||||
|
||||
assert!(!handler.is_ready());
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_track_details_handler_is_ready(
|
||||
#[values(
|
||||
ActiveLidarrBlock::TrackDetails,
|
||||
ActiveLidarrBlock::TrackHistory,
|
||||
)]
|
||||
active_lidarr_block: ActiveLidarrBlock,
|
||||
) {
|
||||
let mut app = App::test_default_fully_populated();
|
||||
app.push_navigation_stack(active_lidarr_block.into());
|
||||
app.is_loading = false;
|
||||
|
||||
let handler = TrackDetailsHandler::new(
|
||||
DEFAULT_KEYBINDINGS.esc.key,
|
||||
&mut app,
|
||||
active_lidarr_block,
|
||||
None,
|
||||
);
|
||||
|
||||
assert!(handler.is_ready());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user