diff --git a/src/ui/radarr_ui/mod.rs b/src/ui/radarr_ui/mod.rs index ad481fd..418681f 100644 --- a/src/ui/radarr_ui/mod.rs +++ b/src/ui/radarr_ui/mod.rs @@ -213,7 +213,7 @@ fn decorate_with_row_style<'a>( .find(|&download| download.movie_id == movie.id) { if download.status == "downloading" { - return row.warning(); + return row.downloading(); } if download.status == "completed" { @@ -221,13 +221,21 @@ fn decorate_with_row_style<'a>( } } - return row.failure(); + if !movie.monitored { + return row.unmonitored_missing(); + } + + if movie.status != "released" { + return row.unreleased(); + } + + return row.missing(); } if !movie.monitored { row.unmonitored() } else { - row.success() + row.downloaded() } } diff --git a/src/ui/radarr_ui/radarr_ui_tests.rs b/src/ui/radarr_ui/radarr_ui_tests.rs index a388794..6269f24 100644 --- a/src/ui/radarr_ui/radarr_ui_tests.rs +++ b/src/ui/radarr_ui/radarr_ui_tests.rs @@ -1,10 +1,14 @@ #[cfg(test)] mod tests { + use ratatui::widgets::{Cell, Row}; + use rstest::rstest; use strum::IntoEnumIterator; + use crate::models::radarr_models::{DownloadRecord, Movie}; use crate::models::servarr_data::radarr::radarr_data::ActiveRadarrBlock; - use crate::ui::radarr_ui::RadarrUi; + use crate::ui::radarr_ui::{decorate_with_row_style, RadarrUi}; use crate::ui::DrawUi; + use crate::ui::styles::ManagarrStyle; #[test] fn test_radarr_ui_accepts() { @@ -12,4 +16,60 @@ mod tests { assert!(RadarrUi::accepts(active_radarr_block.into())); }); } + + #[rstest] + #[case(false, Some("downloading"), false, "", RowStyle::Downloading)] + #[case(false, Some("completed"), false, "", RowStyle::AwaitingImport)] + #[case(false, None, false, "", RowStyle::UnmonitoredMissing)] + #[case(false, None, true, "", RowStyle::Unreleased)] + #[case(false, None, true, "released", RowStyle::Missing)] + #[case(true, None, false, "", RowStyle::Unmonitored)] + #[case(true, None, true, "", RowStyle::Downloaded)] + fn test_decorate_with_row_style( + #[case] has_file: bool, + #[case] download_status: Option<&str>, + #[case] is_monitored: bool, + #[case] movie_status: String, + #[case] expected_style: RowStyle, + ) { + let downloads_vec = if let Some(download_status) = download_status { + vec![DownloadRecord { + movie_id: 1, + status: download_status.to_owned(), + ..DownloadRecord::default() + }] + } else { + vec![] + }; + let movie = Movie { + id: 1, + has_file, + monitored: is_monitored, + status: movie_status, + ..Movie::default() + }; + let row = Row::new(vec![Cell::from("test".to_owned())]); + + let style = decorate_with_row_style(&downloads_vec, &movie, row.clone()); + + match expected_style { + RowStyle::AwaitingImport => assert_eq!(style, row.awaiting_import()), + RowStyle::Downloaded => assert_eq!(style, row.downloaded()), + RowStyle::Downloading => assert_eq!(style, row.downloading()), + RowStyle::Missing => assert_eq!(style, row.missing()), + RowStyle::Unmonitored => assert_eq!(style, row.unmonitored()), + RowStyle::UnmonitoredMissing => assert_eq!(style, row.unmonitored_missing()), + RowStyle::Unreleased => assert_eq!(style, row.unreleased()), + } + } + + enum RowStyle { + AwaitingImport, + Downloaded, + Downloading, + Missing, + Unmonitored, + UnmonitoredMissing, + Unreleased, + } } diff --git a/src/ui/styles.rs b/src/ui/styles.rs index 4452fd8..2bbeaad 100644 --- a/src/ui/styles.rs +++ b/src/ui/styles.rs @@ -15,14 +15,19 @@ where fn new() -> T; fn awaiting_import(self) -> T; fn default(self) -> T; + fn downloaded(self) -> T; + fn downloading(self) -> T; fn failure(self) -> T; fn help(self) -> T; fn highlight(self) -> T; + fn missing(self) -> T; fn primary(self) -> T; fn secondary(self) -> T; fn success(self) -> T; fn system_function(self) -> T; fn unmonitored(self) -> T; + fn unmonitored_missing(self) -> T; + fn unreleased(self) -> T; fn warning(self) -> T; } @@ -43,6 +48,14 @@ where self.white() } + fn downloaded(self) -> T { + self.green() + } + + fn downloading(self) -> T { + self.magenta() + } + fn failure(self) -> T { self.red() } @@ -55,6 +68,10 @@ where self.reversed() } + fn missing(self) -> T { + self.red() + } + fn primary(self) -> T { self.cyan() } @@ -72,9 +89,17 @@ where } fn unmonitored(self) -> T { - self.white() + self.gray() } + fn unmonitored_missing(self) -> T { + self.yellow() + } + + fn unreleased(self) -> T { + self.light_cyan() + } + fn warning(self) -> T { self.magenta() } diff --git a/src/ui/styles_tests.rs b/src/ui/styles_tests.rs index 4507c49..55169f7 100644 --- a/src/ui/styles_tests.rs +++ b/src/ui/styles_tests.rs @@ -23,6 +23,16 @@ mod test { assert_eq!(Style::new().default(), Style::new().white()); } + #[test] + fn test_style_downloaded() { + assert_eq!(Style::new().downloaded(), Style::new().green()); + } + + #[test] + fn test_style_downloading() { + assert_eq!(Style::new().downloading(), Style::new().magenta()); + } + #[test] fn test_style_failure() { assert_eq!(Style::new().failure(), Style::new().red()); @@ -41,6 +51,11 @@ mod test { ); } + #[test] + fn test_style_missing() { + assert_eq!(Style::new().missing(), Style::new().red()); + } + #[test] fn test_style_primary() { assert_eq!(Style::new().primary(), Style::new().cyan()); @@ -63,7 +78,17 @@ mod test { #[test] fn test_style_unmonitored() { - assert_eq!(Style::new().unmonitored(), Style::new().white()); + assert_eq!(Style::new().unmonitored(), Style::new().gray()); + } + + #[test] + fn test_style_unmonitored_missing() { + assert_eq!(Style::new().unmonitored_missing(), Style::new().yellow()); + } + + #[test] + fn test_style_unreleased() { + assert_eq!(Style::new().unreleased(), Style::new().light_cyan()); } #[test]