refactor: Addressed Cargo fmt complaints
This commit is contained in:
@@ -6,9 +6,7 @@ mod tests {
|
|||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
|
|
||||||
use crate::app::context_clues::{build_context_clue_string, SERVARR_CONTEXT_CLUES};
|
use crate::app::context_clues::{build_context_clue_string, SERVARR_CONTEXT_CLUES};
|
||||||
use crate::app::{
|
use crate::app::{interpolate_env_vars, App, AppConfig, Data, ServarrConfig};
|
||||||
interpolate_env_vars, App, AppConfig, Data, ServarrConfig,
|
|
||||||
};
|
|
||||||
use crate::models::servarr_data::radarr::radarr_data::{ActiveRadarrBlock, RadarrData};
|
use crate::models::servarr_data::radarr::radarr_data::{ActiveRadarrBlock, RadarrData};
|
||||||
use crate::models::servarr_data::sonarr::sonarr_data::{ActiveSonarrBlock, SonarrData};
|
use crate::models::servarr_data::sonarr::sonarr_data::{ActiveSonarrBlock, SonarrData};
|
||||||
use crate::models::{HorizontallyScrollableText, TabRoute};
|
use crate::models::{HorizontallyScrollableText, TabRoute};
|
||||||
|
|||||||
+16
-4
@@ -62,7 +62,7 @@ impl App<'_> {
|
|||||||
let name = if let Some(name) = radarr_config.name.clone() {
|
let name = if let Some(name) = radarr_config.name.clone() {
|
||||||
name
|
name
|
||||||
} else {
|
} else {
|
||||||
idx+=1;
|
idx += 1;
|
||||||
format!("Radarr {}", idx)
|
format!("Radarr {}", idx)
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -83,7 +83,7 @@ impl App<'_> {
|
|||||||
let name = if let Some(name) = sonarr_config.name.clone() {
|
let name = if let Some(name) = sonarr_config.name.clone() {
|
||||||
name
|
name
|
||||||
} else {
|
} else {
|
||||||
idx+=1;
|
idx += 1;
|
||||||
format!("Sonarr {}", idx)
|
format!("Sonarr {}", idx)
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -101,8 +101,20 @@ impl App<'_> {
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.sorted_by(|tab1, tab2| {
|
.sorted_by(|tab1, tab2| {
|
||||||
Ord::cmp(
|
Ord::cmp(
|
||||||
tab1.config.as_ref().unwrap().weight.as_ref().unwrap_or(&1000),
|
tab1
|
||||||
tab2.config.as_ref().unwrap().weight.as_ref().unwrap_or(&1000),
|
.config
|
||||||
|
.as_ref()
|
||||||
|
.unwrap()
|
||||||
|
.weight
|
||||||
|
.as_ref()
|
||||||
|
.unwrap_or(&1000),
|
||||||
|
tab2
|
||||||
|
.config
|
||||||
|
.as_ref()
|
||||||
|
.unwrap()
|
||||||
|
.weight
|
||||||
|
.as_ref()
|
||||||
|
.unwrap_or(&1000),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|||||||
+1
-1
@@ -119,7 +119,7 @@ async fn main() -> Result<()> {
|
|||||||
config.clone(),
|
config.clone(),
|
||||||
cancellation_token.clone(),
|
cancellation_token.clone(),
|
||||||
)));
|
)));
|
||||||
|
|
||||||
match args.command {
|
match args.command {
|
||||||
Some(command) => match command {
|
Some(command) => match command {
|
||||||
Command::Radarr(_) | Command::Sonarr(_) => {
|
Command::Radarr(_) | Command::Sonarr(_) => {
|
||||||
|
|||||||
+8
-8
@@ -300,10 +300,10 @@ impl TabState {
|
|||||||
if self.tabs.is_empty() {
|
if self.tabs.is_empty() {
|
||||||
return &None;
|
return &None;
|
||||||
}
|
}
|
||||||
|
|
||||||
&self.tabs[self.index].config
|
&self.tabs[self.index].config
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn select_tab_by_title(&mut self, name: &str) -> bool {
|
pub fn select_tab_by_title(&mut self, name: &str) -> bool {
|
||||||
if !self.tabs.is_empty() {
|
if !self.tabs.is_empty() {
|
||||||
let mut found = false;
|
let mut found = false;
|
||||||
@@ -313,13 +313,13 @@ impl TabState {
|
|||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn select_tab_by_config(&mut self, config: &ServarrConfig) -> bool {
|
pub fn select_tab_by_config(&mut self, config: &ServarrConfig) -> bool {
|
||||||
if !self.tabs.is_empty() {
|
if !self.tabs.is_empty() {
|
||||||
let mut found = false;
|
let mut found = false;
|
||||||
@@ -329,13 +329,13 @@ impl TabState {
|
|||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_active_tab_help(&self) -> &str {
|
pub fn get_active_tab_help(&self) -> &str {
|
||||||
&self.tabs[self.index].help
|
&self.tabs[self.index].help
|
||||||
}
|
}
|
||||||
|
|||||||
+29
-23
@@ -3,12 +3,6 @@ mod tests {
|
|||||||
use std::sync::atomic::AtomicUsize;
|
use std::sync::atomic::AtomicUsize;
|
||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
|
|
||||||
use pretty_assertions::{assert_eq, assert_str_eq};
|
|
||||||
use serde::de::value::Error as ValueError;
|
|
||||||
use serde::de::value::F64Deserializer;
|
|
||||||
use serde::de::value::I64Deserializer;
|
|
||||||
use serde::de::IntoDeserializer;
|
|
||||||
use serde_json::to_string;
|
|
||||||
use crate::app::ServarrConfig;
|
use crate::app::ServarrConfig;
|
||||||
use crate::models::from_f64;
|
use crate::models::from_f64;
|
||||||
use crate::models::servarr_data::radarr::radarr_data::ActiveRadarrBlock;
|
use crate::models::servarr_data::radarr::radarr_data::ActiveRadarrBlock;
|
||||||
@@ -16,6 +10,12 @@ mod tests {
|
|||||||
use crate::models::{
|
use crate::models::{
|
||||||
BlockSelectionState, HorizontallyScrollableText, Scrollable, ScrollableText, TabRoute, TabState,
|
BlockSelectionState, HorizontallyScrollableText, Scrollable, ScrollableText, TabRoute, TabState,
|
||||||
};
|
};
|
||||||
|
use pretty_assertions::{assert_eq, assert_str_eq};
|
||||||
|
use serde::de::value::Error as ValueError;
|
||||||
|
use serde::de::value::F64Deserializer;
|
||||||
|
use serde::de::value::I64Deserializer;
|
||||||
|
use serde::de::IntoDeserializer;
|
||||||
|
use serde_json::to_string;
|
||||||
|
|
||||||
const BLOCKS: &[&[i32]] = &[&[11, 12], &[21, 22], &[31, 32]];
|
const BLOCKS: &[&[i32]] = &[&[11, 12], &[21, 22], &[31, 32]];
|
||||||
|
|
||||||
@@ -512,7 +512,7 @@ mod tests {
|
|||||||
|
|
||||||
assert_eq!(active_route, second_tab);
|
assert_eq!(active_route, second_tab);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_tab_state_get_active_config() {
|
fn test_tab_state_get_active_config() {
|
||||||
let mut tabs = create_test_tab_routes();
|
let mut tabs = create_test_tab_routes();
|
||||||
@@ -521,9 +521,9 @@ mod tests {
|
|||||||
..ServarrConfig::default()
|
..ServarrConfig::default()
|
||||||
});
|
});
|
||||||
let tab_state = TabState { tabs, index: 1 };
|
let tab_state = TabState { tabs, index: 1 };
|
||||||
|
|
||||||
let active_config = tab_state.get_active_config();
|
let active_config = tab_state.get_active_config();
|
||||||
|
|
||||||
assert!(active_config.is_some());
|
assert!(active_config.is_some());
|
||||||
assert_str_eq!(active_config.clone().unwrap().name.unwrap(), "Test");
|
assert_str_eq!(active_config.clone().unwrap().name.unwrap(), "Test");
|
||||||
}
|
}
|
||||||
@@ -537,7 +537,7 @@ mod tests {
|
|||||||
|
|
||||||
assert!(active_config.is_none());
|
assert!(active_config.is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_select_tab_by_title() {
|
fn test_select_tab_by_title() {
|
||||||
let tabs = create_test_tab_routes();
|
let tabs = create_test_tab_routes();
|
||||||
@@ -553,17 +553,20 @@ mod tests {
|
|||||||
assert!(!result);
|
assert!(!result);
|
||||||
assert_eq!(tab_state.index, 1);
|
assert_eq!(tab_state.index, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_select_tab_by_title_empty_tabs_returns_false() {
|
fn test_select_tab_by_title_empty_tabs_returns_false() {
|
||||||
let mut tab_state = TabState { tabs: vec![], index: 0 };
|
let mut tab_state = TabState {
|
||||||
|
tabs: vec![],
|
||||||
|
index: 0,
|
||||||
|
};
|
||||||
|
|
||||||
let result = tab_state.select_tab_by_title("Test 2");
|
let result = tab_state.select_tab_by_title("Test 2");
|
||||||
|
|
||||||
assert!(!result);
|
assert!(!result);
|
||||||
assert_eq!(tab_state.index, 0);
|
assert_eq!(tab_state.index, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_select_tab_by_config() {
|
fn test_select_tab_by_config() {
|
||||||
let mut tabs = create_test_tab_routes();
|
let mut tabs = create_test_tab_routes();
|
||||||
@@ -577,35 +580,38 @@ mod tests {
|
|||||||
..ServarrConfig::default()
|
..ServarrConfig::default()
|
||||||
});
|
});
|
||||||
let mut tab_state = TabState { tabs, index: 0 };
|
let mut tab_state = TabState { tabs, index: 0 };
|
||||||
|
|
||||||
let result = tab_state.select_tab_by_config(&ServarrConfig {
|
let result = tab_state.select_tab_by_config(&ServarrConfig {
|
||||||
host: Some("http://localhost".to_owned()),
|
host: Some("http://localhost".to_owned()),
|
||||||
port: Some(7878),
|
port: Some(7878),
|
||||||
..ServarrConfig::default()
|
..ServarrConfig::default()
|
||||||
});
|
});
|
||||||
|
|
||||||
assert!(result);
|
assert!(result);
|
||||||
assert_eq!(tab_state.index, 1);
|
assert_eq!(tab_state.index, 1);
|
||||||
|
|
||||||
let result = tab_state.select_tab_by_config(&ServarrConfig {
|
let result = tab_state.select_tab_by_config(&ServarrConfig {
|
||||||
name: Some("Not real".to_owned()),
|
name: Some("Not real".to_owned()),
|
||||||
..ServarrConfig::default()
|
..ServarrConfig::default()
|
||||||
});
|
});
|
||||||
|
|
||||||
assert!(!result);
|
assert!(!result);
|
||||||
assert_eq!(tab_state.index, 1);
|
assert_eq!(tab_state.index, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_select_tab_by_config_empty_tabs_returns_false() {
|
fn test_select_tab_by_config_empty_tabs_returns_false() {
|
||||||
let mut tab_state = TabState { tabs: vec![], index: 0 };
|
let mut tab_state = TabState {
|
||||||
|
tabs: vec![],
|
||||||
|
index: 0,
|
||||||
|
};
|
||||||
|
|
||||||
let result = tab_state.select_tab_by_config(&ServarrConfig {
|
let result = tab_state.select_tab_by_config(&ServarrConfig {
|
||||||
host: Some("http://localhost".to_owned()),
|
host: Some("http://localhost".to_owned()),
|
||||||
port: Some(7878),
|
port: Some(7878),
|
||||||
..ServarrConfig::default()
|
..ServarrConfig::default()
|
||||||
});
|
});
|
||||||
|
|
||||||
assert!(!result);
|
assert!(!result);
|
||||||
assert_eq!(tab_state.index, 0);
|
assert_eq!(tab_state.index, 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -264,7 +264,10 @@ mod tests {
|
|||||||
assert!(episode_details_modal.episode_details_tabs.tabs[0]
|
assert!(episode_details_modal.episode_details_tabs.tabs[0]
|
||||||
.contextual_help
|
.contextual_help
|
||||||
.is_none());
|
.is_none());
|
||||||
assert_eq!(episode_details_modal.episode_details_tabs.tabs[0].config, None);
|
assert_eq!(
|
||||||
|
episode_details_modal.episode_details_tabs.tabs[0].config,
|
||||||
|
None
|
||||||
|
);
|
||||||
|
|
||||||
assert_str_eq!(
|
assert_str_eq!(
|
||||||
episode_details_modal.episode_details_tabs.tabs[1].title,
|
episode_details_modal.episode_details_tabs.tabs[1].title,
|
||||||
@@ -282,7 +285,10 @@ mod tests {
|
|||||||
episode_details_modal.episode_details_tabs.tabs[1].contextual_help,
|
episode_details_modal.episode_details_tabs.tabs[1].contextual_help,
|
||||||
Some(build_context_clue_string(&DETAILS_CONTEXTUAL_CONTEXT_CLUES))
|
Some(build_context_clue_string(&DETAILS_CONTEXTUAL_CONTEXT_CLUES))
|
||||||
);
|
);
|
||||||
assert_eq!(episode_details_modal.episode_details_tabs.tabs[1].config, None);
|
assert_eq!(
|
||||||
|
episode_details_modal.episode_details_tabs.tabs[1].config,
|
||||||
|
None
|
||||||
|
);
|
||||||
|
|
||||||
assert_str_eq!(
|
assert_str_eq!(
|
||||||
episode_details_modal.episode_details_tabs.tabs[2].title,
|
episode_details_modal.episode_details_tabs.tabs[2].title,
|
||||||
@@ -299,7 +305,10 @@ mod tests {
|
|||||||
assert!(episode_details_modal.episode_details_tabs.tabs[2]
|
assert!(episode_details_modal.episode_details_tabs.tabs[2]
|
||||||
.contextual_help
|
.contextual_help
|
||||||
.is_none());
|
.is_none());
|
||||||
assert_eq!(episode_details_modal.episode_details_tabs.tabs[2].config, None);
|
assert_eq!(
|
||||||
|
episode_details_modal.episode_details_tabs.tabs[2].config,
|
||||||
|
None
|
||||||
|
);
|
||||||
|
|
||||||
assert_str_eq!(
|
assert_str_eq!(
|
||||||
episode_details_modal.episode_details_tabs.tabs[3].title,
|
episode_details_modal.episode_details_tabs.tabs[3].title,
|
||||||
@@ -317,7 +326,10 @@ mod tests {
|
|||||||
episode_details_modal.episode_details_tabs.tabs[3].contextual_help,
|
episode_details_modal.episode_details_tabs.tabs[3].contextual_help,
|
||||||
Some(build_context_clue_string(&DETAILS_CONTEXTUAL_CONTEXT_CLUES))
|
Some(build_context_clue_string(&DETAILS_CONTEXTUAL_CONTEXT_CLUES))
|
||||||
);
|
);
|
||||||
assert_eq!(episode_details_modal.episode_details_tabs.tabs[3].config, None);
|
assert_eq!(
|
||||||
|
episode_details_modal.episode_details_tabs.tabs[3].config,
|
||||||
|
None
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -350,7 +362,10 @@ mod tests {
|
|||||||
&SEASON_DETAILS_CONTEXTUAL_CONTEXT_CLUES
|
&SEASON_DETAILS_CONTEXTUAL_CONTEXT_CLUES
|
||||||
))
|
))
|
||||||
);
|
);
|
||||||
assert_eq!(season_details_modal.season_details_tabs.tabs[0].config, None);
|
assert_eq!(
|
||||||
|
season_details_modal.season_details_tabs.tabs[0].config,
|
||||||
|
None
|
||||||
|
);
|
||||||
|
|
||||||
assert_str_eq!(
|
assert_str_eq!(
|
||||||
season_details_modal.season_details_tabs.tabs[1].title,
|
season_details_modal.season_details_tabs.tabs[1].title,
|
||||||
@@ -368,7 +383,10 @@ mod tests {
|
|||||||
season_details_modal.season_details_tabs.tabs[1].contextual_help,
|
season_details_modal.season_details_tabs.tabs[1].contextual_help,
|
||||||
Some(build_context_clue_string(&DETAILS_CONTEXTUAL_CONTEXT_CLUES))
|
Some(build_context_clue_string(&DETAILS_CONTEXTUAL_CONTEXT_CLUES))
|
||||||
);
|
);
|
||||||
assert_eq!(season_details_modal.season_details_tabs.tabs[1].config, None);
|
assert_eq!(
|
||||||
|
season_details_modal.season_details_tabs.tabs[1].config,
|
||||||
|
None
|
||||||
|
);
|
||||||
|
|
||||||
assert_str_eq!(
|
assert_str_eq!(
|
||||||
season_details_modal.season_details_tabs.tabs[2].title,
|
season_details_modal.season_details_tabs.tabs[2].title,
|
||||||
@@ -386,6 +404,9 @@ mod tests {
|
|||||||
season_details_modal.season_details_tabs.tabs[2].contextual_help,
|
season_details_modal.season_details_tabs.tabs[2].contextual_help,
|
||||||
Some(build_context_clue_string(&DETAILS_CONTEXTUAL_CONTEXT_CLUES))
|
Some(build_context_clue_string(&DETAILS_CONTEXTUAL_CONTEXT_CLUES))
|
||||||
);
|
);
|
||||||
assert_eq!(season_details_modal.season_details_tabs.tabs[2].config, None);
|
assert_eq!(
|
||||||
|
season_details_modal.season_details_tabs.tabs[2].config,
|
||||||
|
None
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -401,18 +401,14 @@ mod tests {
|
|||||||
#[should_panic(expected = "Servarr config is undefined")]
|
#[should_panic(expected = "Servarr config is undefined")]
|
||||||
#[rstest]
|
#[rstest]
|
||||||
async fn test_request_props_from_requires_radarr_config_to_be_present_for_all_network_events(
|
async fn test_request_props_from_requires_radarr_config_to_be_present_for_all_network_events(
|
||||||
#[values(RadarrEvent::HealthCheck, SonarrEvent::HealthCheck)] network_event: impl Into<NetworkEvent> + NetworkResource) {
|
#[values(RadarrEvent::HealthCheck, SonarrEvent::HealthCheck)] network_event: impl Into<NetworkEvent>
|
||||||
|
+ NetworkResource,
|
||||||
|
) {
|
||||||
let app_arc = Arc::new(Mutex::new(App::default()));
|
let app_arc = Arc::new(Mutex::new(App::default()));
|
||||||
let network = Network::new(&app_arc, CancellationToken::new(), Client::new());
|
let network = Network::new(&app_arc, CancellationToken::new(), Client::new());
|
||||||
|
|
||||||
network
|
network
|
||||||
.request_props_from(
|
.request_props_from(network_event, RequestMethod::Get, None::<()>, None, None)
|
||||||
network_event,
|
|
||||||
RequestMethod::Get,
|
|
||||||
None::<()>,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+13
-5
@@ -274,11 +274,19 @@ pub(super) async fn start_cli_no_spinner(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn select_cli_configuration(app: &mut App<'_>, config: &AppConfig, command: &Command, servarr_name_arg: Option<String>) {
|
pub fn select_cli_configuration(
|
||||||
|
app: &mut App<'_>,
|
||||||
|
config: &AppConfig,
|
||||||
|
command: &Command,
|
||||||
|
servarr_name_arg: Option<String>,
|
||||||
|
) {
|
||||||
if let Some(servarr_name) = servarr_name_arg {
|
if let Some(servarr_name) = servarr_name_arg {
|
||||||
let trimmed_name = servarr_name.trim();
|
let trimmed_name = servarr_name.trim();
|
||||||
if !app.server_tabs.select_tab_by_title(trimmed_name) {
|
if !app.server_tabs.select_tab_by_title(trimmed_name) {
|
||||||
log_and_print_error(format!("A Servarr titled '{}' was not found in your configuration file", trimmed_name));
|
log_and_print_error(format!(
|
||||||
|
"A Servarr titled '{}' was not found in your configuration file",
|
||||||
|
trimmed_name
|
||||||
|
));
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -286,12 +294,12 @@ pub fn select_cli_configuration(app: &mut App<'_>, config: &AppConfig, command:
|
|||||||
Command::Radarr(_) => {
|
Command::Radarr(_) => {
|
||||||
let default_radarr_config = config.radarr.as_ref().unwrap()[0].clone();
|
let default_radarr_config = config.radarr.as_ref().unwrap()[0].clone();
|
||||||
app.server_tabs.select_tab_by_config(&default_radarr_config);
|
app.server_tabs.select_tab_by_config(&default_radarr_config);
|
||||||
},
|
}
|
||||||
Command::Sonarr(_) => {
|
Command::Sonarr(_) => {
|
||||||
let default_sonarr_config = config.sonarr.as_ref().unwrap()[0].clone();
|
let default_sonarr_config = config.sonarr.as_ref().unwrap()[0].clone();
|
||||||
app.server_tabs.select_tab_by_config(&default_sonarr_config);
|
app.server_tabs.select_tab_by_config(&default_sonarr_config);
|
||||||
},
|
}
|
||||||
_ => ()
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user