fix(sonarr): Provide the series ID and season number alongside all GetSeasonHistory events when publishing to the networking channel
This commit is contained in:
+19
-3
@@ -55,9 +55,14 @@ impl<'a> App<'a> {
|
||||
.await;
|
||||
}
|
||||
ActiveSonarrBlock::SeasonHistory => {
|
||||
self
|
||||
.dispatch_network_event(SonarrEvent::GetSeasonHistory(None).into())
|
||||
.await;
|
||||
if !self.data.sonarr_data.seasons.is_empty() {
|
||||
self
|
||||
.dispatch_network_event(
|
||||
SonarrEvent::GetSeasonHistory(self.extract_series_id_season_number_tuple().await)
|
||||
.into(),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
}
|
||||
ActiveSonarrBlock::ManualSeasonSearch => {
|
||||
match self.data.sonarr_data.season_details_modal.as_ref() {
|
||||
@@ -266,4 +271,15 @@ impl<'a> App<'a> {
|
||||
async fn extract_series_id(&self) -> i64 {
|
||||
self.data.sonarr_data.series.current_selection().id
|
||||
}
|
||||
|
||||
async fn extract_series_id_season_number_tuple(&self) -> (i64, i64) {
|
||||
let series_id = self.data.sonarr_data.series.current_selection().id;
|
||||
let season_number = self
|
||||
.data
|
||||
.sonarr_data
|
||||
.seasons
|
||||
.current_selection()
|
||||
.season_number;
|
||||
(series_id, season_number)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,6 +111,14 @@ mod tests {
|
||||
#[tokio::test]
|
||||
async fn test_dispatch_by_season_history_block() {
|
||||
let (mut app, mut sync_network_rx) = construct_app_unit();
|
||||
app.data.sonarr_data.series.set_items(vec![Series {
|
||||
id: 1,
|
||||
..Series::default()
|
||||
}]);
|
||||
app.data.sonarr_data.seasons.set_items(vec![Season {
|
||||
season_number: 1,
|
||||
..Season::default()
|
||||
}]);
|
||||
|
||||
app
|
||||
.dispatch_by_sonarr_block(&ActiveSonarrBlock::SeasonHistory)
|
||||
@@ -119,12 +127,29 @@ mod tests {
|
||||
assert!(app.is_loading);
|
||||
assert_eq!(
|
||||
sync_network_rx.recv().await.unwrap(),
|
||||
SonarrEvent::GetSeasonHistory(None).into()
|
||||
SonarrEvent::GetSeasonHistory((1, 1)).into()
|
||||
);
|
||||
assert!(!app.data.sonarr_data.prompt_confirm);
|
||||
assert_eq!(app.tick_count, 0);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_dispatch_by_season_history_block_no_op_when_seasons_table_is_empty() {
|
||||
let (mut app, _) = construct_app_unit();
|
||||
app.data.sonarr_data.series.set_items(vec![Series {
|
||||
id: 1,
|
||||
..Series::default()
|
||||
}]);
|
||||
|
||||
app
|
||||
.dispatch_by_sonarr_block(&ActiveSonarrBlock::SeasonHistory)
|
||||
.await;
|
||||
|
||||
assert!(!app.is_loading);
|
||||
assert!(!app.data.sonarr_data.prompt_confirm);
|
||||
assert_eq!(app.tick_count, 0);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_dispatch_by_manual_season_search_block() {
|
||||
let (mut app, mut sync_network_rx) = construct_app_unit();
|
||||
@@ -777,6 +802,21 @@ mod tests {
|
||||
assert_eq!(app.extract_series_id().await, 1);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_extract_series_id_season_number_tuple() {
|
||||
let mut app = App::default();
|
||||
app.data.sonarr_data.series.set_items(vec![Series {
|
||||
id: 1,
|
||||
..Series::default()
|
||||
}]);
|
||||
app.data.sonarr_data.seasons.set_items(vec![Season {
|
||||
season_number: 1,
|
||||
..Season::default()
|
||||
}]);
|
||||
|
||||
assert_eq!(app.extract_series_id_season_number_tuple().await, (1, 1));
|
||||
}
|
||||
|
||||
fn construct_app_unit<'a>() -> (App<'a>, mpsc::Receiver<NetworkEvent>) {
|
||||
let (sync_network_tx, sync_network_rx) = mpsc::channel::<NetworkEvent>(500);
|
||||
let mut app = App {
|
||||
|
||||
Reference in New Issue
Block a user