test: cover the status style branches for track and episode details
This commit is contained in:
2 files changed
+187
-2
No files matched your search
@@ -1,11 +1,14 @@
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use pretty_assertions::assert_eq;
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
use crate::app::App;
|
||||
use crate::models::lidarr_models::Track;
|
||||
use crate::models::servarr_data::lidarr::lidarr_data::{ActiveLidarrBlock, TRACK_DETAILS_BLOCKS};
|
||||
use crate::ui::DrawUi;
|
||||
use crate::ui::lidarr_ui::library::track_details_ui::TrackDetailsUi;
|
||||
use crate::ui::lidarr_ui::library::track_details_ui::{TrackDetailsUi, style_from_status};
|
||||
use crate::ui::styles::{downloaded_style, missing_style};
|
||||
use crate::ui::ui_test_utils::test_utils::render_to_string_with_app;
|
||||
|
||||
#[test]
|
||||
@@ -19,6 +22,30 @@ mod tests {
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_style_from_status_downloaded_when_track_has_file() {
|
||||
let track = Track {
|
||||
has_file: true,
|
||||
..Track::default()
|
||||
};
|
||||
|
||||
let style = style_from_status(&track);
|
||||
|
||||
assert_eq!(style, downloaded_style());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_style_from_status_missing_when_track_has_no_file() {
|
||||
let track = Track {
|
||||
has_file: false,
|
||||
..Track::default()
|
||||
};
|
||||
|
||||
let style = style_from_status(&track);
|
||||
|
||||
assert_eq!(style, missing_style());
|
||||
}
|
||||
|
||||
mod snapshot_tests {
|
||||
use crate::ui::ui_test_utils::test_utils::TerminalSize;
|
||||
use rstest::rstest;
|
||||
|
||||
@@ -1,13 +1,20 @@
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use chrono::{Duration, Utc};
|
||||
use pretty_assertions::assert_eq;
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
use crate::app::App;
|
||||
use crate::models::servarr_data::sonarr::sonarr_data::{
|
||||
ActiveSonarrBlock, EPISODE_DETAILS_BLOCKS,
|
||||
};
|
||||
use crate::models::sonarr_models::{DownloadRecord, DownloadStatus, Episode};
|
||||
use crate::ui::DrawUi;
|
||||
use crate::ui::sonarr_ui::library::episode_details_ui::EpisodeDetailsUi;
|
||||
use crate::ui::sonarr_ui::library::episode_details_ui::{EpisodeDetailsUi, style_from_status};
|
||||
use crate::ui::styles::{
|
||||
awaiting_import_style, downloaded_style, downloading_style, missing_style,
|
||||
unmonitored_missing_style, unmonitored_style, unreleased_style,
|
||||
};
|
||||
use crate::ui::ui_test_utils::test_utils::render_to_string_with_app;
|
||||
|
||||
#[test]
|
||||
@@ -21,6 +28,157 @@ mod tests {
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_style_from_status_downloading_when_episode_has_no_file_and_download_is_downloading() {
|
||||
let download = DownloadRecord {
|
||||
status: DownloadStatus::Downloading,
|
||||
..DownloadRecord::default()
|
||||
};
|
||||
let episode = Episode {
|
||||
has_file: false,
|
||||
monitored: true,
|
||||
..Episode::default()
|
||||
};
|
||||
|
||||
let style = style_from_status(Some(&download), &episode);
|
||||
|
||||
assert_eq!(style, downloading_style());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_style_from_status_awaiting_import_when_episode_has_no_file_and_download_is_completed() {
|
||||
let download = DownloadRecord {
|
||||
status: DownloadStatus::Completed,
|
||||
..DownloadRecord::default()
|
||||
};
|
||||
let episode = Episode {
|
||||
has_file: false,
|
||||
monitored: true,
|
||||
..Episode::default()
|
||||
};
|
||||
|
||||
let style = style_from_status(Some(&download), &episode);
|
||||
|
||||
assert_eq!(style, awaiting_import_style());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_style_from_status_ignores_download_that_is_neither_downloading_nor_completed() {
|
||||
let download = DownloadRecord {
|
||||
status: DownloadStatus::Queued,
|
||||
..DownloadRecord::default()
|
||||
};
|
||||
let episode = Episode {
|
||||
has_file: false,
|
||||
monitored: true,
|
||||
air_date_utc: None,
|
||||
..Episode::default()
|
||||
};
|
||||
|
||||
let style = style_from_status(Some(&download), &episode);
|
||||
|
||||
assert_eq!(style, missing_style());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_style_from_status_unmonitored_missing_when_episode_has_no_file_and_is_unmonitored() {
|
||||
let episode = Episode {
|
||||
has_file: false,
|
||||
monitored: false,
|
||||
air_date_utc: Some(Utc::now() + Duration::days(1)),
|
||||
..Episode::default()
|
||||
};
|
||||
|
||||
let style = style_from_status(None, &episode);
|
||||
|
||||
assert_eq!(style, unmonitored_missing_style());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_style_from_status_unreleased_when_episode_has_no_file_and_air_date_is_future() {
|
||||
let episode = Episode {
|
||||
has_file: false,
|
||||
monitored: true,
|
||||
air_date_utc: Some(Utc::now() + Duration::days(1)),
|
||||
..Episode::default()
|
||||
};
|
||||
|
||||
let style = style_from_status(None, &episode);
|
||||
|
||||
assert_eq!(style, unreleased_style());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_style_from_status_missing_when_episode_has_no_file_and_air_date_has_passed() {
|
||||
let episode = Episode {
|
||||
has_file: false,
|
||||
monitored: true,
|
||||
air_date_utc: Some(Utc::now() - Duration::days(1)),
|
||||
..Episode::default()
|
||||
};
|
||||
|
||||
let style = style_from_status(None, &episode);
|
||||
|
||||
assert_eq!(style, missing_style());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_style_from_status_missing_when_episode_has_no_file_and_no_air_date() {
|
||||
let episode = Episode {
|
||||
has_file: false,
|
||||
monitored: true,
|
||||
air_date_utc: None,
|
||||
..Episode::default()
|
||||
};
|
||||
|
||||
let style = style_from_status(None, &episode);
|
||||
|
||||
assert_eq!(style, missing_style());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_style_from_status_unmonitored_when_episode_has_file_and_is_unmonitored() {
|
||||
let episode = Episode {
|
||||
has_file: true,
|
||||
monitored: false,
|
||||
..Episode::default()
|
||||
};
|
||||
|
||||
let style = style_from_status(None, &episode);
|
||||
|
||||
assert_eq!(style, unmonitored_style());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_style_from_status_downloaded_when_episode_has_file_and_is_monitored() {
|
||||
let episode = Episode {
|
||||
has_file: true,
|
||||
monitored: true,
|
||||
..Episode::default()
|
||||
};
|
||||
|
||||
let style = style_from_status(None, &episode);
|
||||
|
||||
assert_eq!(style, downloaded_style());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_style_from_status_ignores_download_when_episode_has_file() {
|
||||
let download = DownloadRecord {
|
||||
status: DownloadStatus::Downloading,
|
||||
..DownloadRecord::default()
|
||||
};
|
||||
let episode = Episode {
|
||||
has_file: true,
|
||||
monitored: true,
|
||||
..Episode::default()
|
||||
};
|
||||
|
||||
let style = style_from_status(Some(&download), &episode);
|
||||
|
||||
assert_eq!(style, downloaded_style());
|
||||
}
|
||||
|
||||
mod snapshot_tests {
|
||||
use crate::ui::ui_test_utils::test_utils::TerminalSize;
|
||||
use rstest::rstest;
|
||||
|
||||
Reference in new issue
Block a user