fix(app/mod): use correct api for tab when starting on non default tab

Further testing of the servarr_name switch revealed an issue where selecting a server that didn't match the first tab caused the wrong api to be used. Now when a non-default tab is selected the correct api is used
This commit is contained in:
solareon committed 2026-09-25 07:44:51 -04:00
1 parent 5279d37ea2
commit 699e929ed2
2 files changed
+36 -8

No files matched your search

+31
View File
@@ -15,6 +15,7 @@ mod tests {
use crate::models::{HorizontallyScrollableText, TabRoute}; use crate::models::{HorizontallyScrollableText, TabRoute};
use crate::network::NetworkEvent; use crate::network::NetworkEvent;
use crate::network::radarr_network::RadarrEvent; use crate::network::radarr_network::RadarrEvent;
use crate::network::sonarr_network::SonarrEvent;
use tokio_util::sync::CancellationToken; use tokio_util::sync::CancellationToken;
#[test] #[test]
@@ -145,6 +146,36 @@ mod tests {
assert!(app.is_routing); assert!(app.is_routing);
} }
#[tokio::test]
async fn test_named_tab_uses_selected_servarr_route_and_network_events() {
let (network_tx, mut network_rx) = mpsc::channel(500);
let mut app = App::new(
network_tx,
AppConfig {
radarr: Some(vec![ServarrConfig {
name: Some("Movies".to_owned()),
..ServarrConfig::default()
}]),
sonarr: Some(vec![ServarrConfig {
name: Some("Shows".to_owned()),
..ServarrConfig::default()
}]),
..AppConfig::default()
},
CancellationToken::new(),
);
assert!(app.server_tabs.select_tab_by_title("Shows"));
assert_eq!(app.get_current_route(), ActiveSonarrBlock::Series.into());
app.on_tick().await;
assert_eq!(
network_rx.recv().await.unwrap(),
SonarrEvent::GetQualityProfiles.into()
);
}
#[test] #[test]
fn test_reset_cancellation_token() { fn test_reset_cancellation_token() {
let mut app = App { let mut app = App {
+5 -8
View File
@@ -240,14 +240,11 @@ impl App<'_> {
} }
pub fn get_current_route(&self) -> Route { pub fn get_current_route(&self) -> Route {
*self.navigation_stack.last().unwrap_or( self
&self .navigation_stack
.server_tabs .last()
.tabs .copied()
.first() .unwrap_or_else(|| self.server_tabs.get_active_route())
.expect("At least one server tab must exist")
.route,
)
} }
} }