From fbf711f4283f0d3ac75ae8b4d603d5e8352b6cf6 Mon Sep 17 00:00:00 2001 From: Alex Clarke Date: Thu, 10 Sep 2026 16:19:25 -0600 Subject: [PATCH] test(lidarr): extract and cover the track row style branch The snapshot harness renders to a plain string, so colour and text modifiers never reach the assertion. The track row's downloaded and missing arms were therefore invisible to the suite: swapping either arm for the other, or inverting the has_file condition, all left the full run green. Move the branch into decorate_track_row_with_style, mirroring the row decorators already extracted in the other library detail views, and unit test both arms directly against Row equality. All three mutations now fail the suite. --- src/ui/lidarr_ui/library/album_details_ui.rs | 32 +++++++++-------- .../library/album_details_ui_tests.rs | 34 ++++++++++++++++++- 2 files changed, 51 insertions(+), 15 deletions(-) diff --git a/src/ui/lidarr_ui/library/album_details_ui.rs b/src/ui/lidarr_ui/library/album_details_ui.rs index 66871a58..31628d86 100644 --- a/src/ui/lidarr_ui/library/album_details_ui.rs +++ b/src/ui/lidarr_ui/library/album_details_ui.rs @@ -157,7 +157,6 @@ fn draw_tracks_table(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) { title, duration, track_file_id, - has_file, .. } = track; @@ -187,19 +186,16 @@ fn draw_tracks_table(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) { let secs = duration_secs % 60; let duration_str = format!("{mins}:{secs:02}"); - let row = Row::new(vec![ - Cell::from(track_number.clone()), - Cell::from(title.clone()), - Cell::from(duration_str), - Cell::from(audio_info), - Cell::from(quality), - ]); - - if *has_file { - row.downloaded() - } else { - row.missing() - } + decorate_track_row_with_style( + track, + Row::new(vec![ + Cell::from(track_number.clone()), + Cell::from(title.clone()), + Cell::from(duration_str), + Cell::from(audio_info), + Cell::from(quality), + ]), + ) }; let is_searching = active_lidarr_block == ActiveLidarrBlock::SearchTracks; @@ -225,6 +221,14 @@ fn draw_tracks_table(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) { } } +fn decorate_track_row_with_style<'a>(track: &Track, row: Row<'a>) -> Row<'a> { + if track.has_file { + row.downloaded() + } else { + row.missing() + } +} + fn draw_album_history_table(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) { match app.data.lidarr_data.album_details_modal.as_ref() { Some(album_details_modal) if !app.is_loading => { diff --git a/src/ui/lidarr_ui/library/album_details_ui_tests.rs b/src/ui/lidarr_ui/library/album_details_ui_tests.rs index 874ba338..260fb8af 100644 --- a/src/ui/lidarr_ui/library/album_details_ui_tests.rs +++ b/src/ui/lidarr_ui/library/album_details_ui_tests.rs @@ -1,14 +1,20 @@ #[cfg(test)] mod tests { + use pretty_assertions::assert_eq; + use ratatui::widgets::{Cell, Row}; use strum::IntoEnumIterator; use crate::app::App; + use crate::models::lidarr_models::Track; use crate::models::servarr_data::lidarr::lidarr_data::{ ALBUM_DETAILS_BLOCKS, ActiveLidarrBlock, TRACK_DETAILS_BLOCKS, }; use crate::models::stateful_table::StatefulTable; use crate::ui::DrawUi; - use crate::ui::lidarr_ui::library::album_details_ui::AlbumDetailsUi; + use crate::ui::lidarr_ui::library::album_details_ui::{ + AlbumDetailsUi, decorate_track_row_with_style, + }; + use crate::ui::styles::ManagarrStyle; use crate::ui::ui_test_utils::test_utils::render_to_string_with_app; #[test] @@ -25,6 +31,32 @@ mod tests { }); } + #[test] + fn test_decorate_track_row_with_style_downloaded_when_track_has_file() { + let track = Track { + has_file: true, + ..Track::default() + }; + let row = Row::new(vec![Cell::from("test".to_owned())]); + + let style = decorate_track_row_with_style(&track, row.clone()); + + assert_eq!(style, row.downloaded()); + } + + #[test] + fn test_decorate_track_row_with_style_missing_when_track_has_no_file() { + let track = Track { + has_file: false, + ..Track::default() + }; + let row = Row::new(vec![Cell::from("test".to_owned())]); + + let style = decorate_track_row_with_style(&track, row.clone()); + + assert_eq!(style, row.missing()); + } + mod snapshot_tests { use crate::ui::ui_test_utils::test_utils::TerminalSize; use rstest::rstest;