refactor: Addressed Cargo fmt complaints
This commit is contained in:
@@ -6,9 +6,7 @@ mod tests {
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
use crate::app::context_clues::{build_context_clue_string, SERVARR_CONTEXT_CLUES};
|
||||
use crate::app::{
|
||||
interpolate_env_vars, App, AppConfig, Data, ServarrConfig,
|
||||
};
|
||||
use crate::app::{interpolate_env_vars, App, AppConfig, Data, ServarrConfig};
|
||||
use crate::models::servarr_data::radarr::radarr_data::{ActiveRadarrBlock, RadarrData};
|
||||
use crate::models::servarr_data::sonarr::sonarr_data::{ActiveSonarrBlock, SonarrData};
|
||||
use crate::models::{HorizontallyScrollableText, TabRoute};
|
||||
|
||||
+16
-4
@@ -62,7 +62,7 @@ impl App<'_> {
|
||||
let name = if let Some(name) = radarr_config.name.clone() {
|
||||
name
|
||||
} else {
|
||||
idx+=1;
|
||||
idx += 1;
|
||||
format!("Radarr {}", idx)
|
||||
};
|
||||
|
||||
@@ -83,7 +83,7 @@ impl App<'_> {
|
||||
let name = if let Some(name) = sonarr_config.name.clone() {
|
||||
name
|
||||
} else {
|
||||
idx+=1;
|
||||
idx += 1;
|
||||
format!("Sonarr {}", idx)
|
||||
};
|
||||
|
||||
@@ -101,8 +101,20 @@ impl App<'_> {
|
||||
.into_iter()
|
||||
.sorted_by(|tab1, tab2| {
|
||||
Ord::cmp(
|
||||
tab1.config.as_ref().unwrap().weight.as_ref().unwrap_or(&1000),
|
||||
tab2.config.as_ref().unwrap().weight.as_ref().unwrap_or(&1000),
|
||||
tab1
|
||||
.config
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.weight
|
||||
.as_ref()
|
||||
.unwrap_or(&1000),
|
||||
tab2
|
||||
.config
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.weight
|
||||
.as_ref()
|
||||
.unwrap_or(&1000),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
|
||||
+1
-1
@@ -119,7 +119,7 @@ async fn main() -> Result<()> {
|
||||
config.clone(),
|
||||
cancellation_token.clone(),
|
||||
)));
|
||||
|
||||
|
||||
match args.command {
|
||||
Some(command) => match command {
|
||||
Command::Radarr(_) | Command::Sonarr(_) => {
|
||||
|
||||
+8
-8
@@ -300,10 +300,10 @@ impl TabState {
|
||||
if self.tabs.is_empty() {
|
||||
return &None;
|
||||
}
|
||||
|
||||
|
||||
&self.tabs[self.index].config
|
||||
}
|
||||
|
||||
|
||||
pub fn select_tab_by_title(&mut self, name: &str) -> bool {
|
||||
if !self.tabs.is_empty() {
|
||||
let mut found = false;
|
||||
@@ -313,13 +313,13 @@ impl TabState {
|
||||
found = true;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
|
||||
pub fn select_tab_by_config(&mut self, config: &ServarrConfig) -> bool {
|
||||
if !self.tabs.is_empty() {
|
||||
let mut found = false;
|
||||
@@ -329,13 +329,13 @@ impl TabState {
|
||||
found = true;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
|
||||
pub fn get_active_tab_help(&self) -> &str {
|
||||
&self.tabs[self.index].help
|
||||
}
|
||||
|
||||
+29
-23
@@ -3,12 +3,6 @@ mod tests {
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
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::models::from_f64;
|
||||
use crate::models::servarr_data::radarr::radarr_data::ActiveRadarrBlock;
|
||||
@@ -16,6 +10,12 @@ mod tests {
|
||||
use crate::models::{
|
||||
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]];
|
||||
|
||||
@@ -512,7 +512,7 @@ mod tests {
|
||||
|
||||
assert_eq!(active_route, second_tab);
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_tab_state_get_active_config() {
|
||||
let mut tabs = create_test_tab_routes();
|
||||
@@ -521,9 +521,9 @@ mod tests {
|
||||
..ServarrConfig::default()
|
||||
});
|
||||
let tab_state = TabState { tabs, index: 1 };
|
||||
|
||||
|
||||
let active_config = tab_state.get_active_config();
|
||||
|
||||
|
||||
assert!(active_config.is_some());
|
||||
assert_str_eq!(active_config.clone().unwrap().name.unwrap(), "Test");
|
||||
}
|
||||
@@ -537,7 +537,7 @@ mod tests {
|
||||
|
||||
assert!(active_config.is_none());
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_select_tab_by_title() {
|
||||
let tabs = create_test_tab_routes();
|
||||
@@ -553,17 +553,20 @@ mod tests {
|
||||
assert!(!result);
|
||||
assert_eq!(tab_state.index, 1);
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
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");
|
||||
|
||||
|
||||
assert!(!result);
|
||||
assert_eq!(tab_state.index, 0);
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_select_tab_by_config() {
|
||||
let mut tabs = create_test_tab_routes();
|
||||
@@ -577,35 +580,38 @@ mod tests {
|
||||
..ServarrConfig::default()
|
||||
});
|
||||
let mut tab_state = TabState { tabs, index: 0 };
|
||||
|
||||
|
||||
let result = tab_state.select_tab_by_config(&ServarrConfig {
|
||||
host: Some("http://localhost".to_owned()),
|
||||
port: Some(7878),
|
||||
..ServarrConfig::default()
|
||||
});
|
||||
|
||||
|
||||
assert!(result);
|
||||
assert_eq!(tab_state.index, 1);
|
||||
|
||||
|
||||
let result = tab_state.select_tab_by_config(&ServarrConfig {
|
||||
name: Some("Not real".to_owned()),
|
||||
..ServarrConfig::default()
|
||||
});
|
||||
|
||||
|
||||
assert!(!result);
|
||||
assert_eq!(tab_state.index, 1);
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
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 {
|
||||
host: Some("http://localhost".to_owned()),
|
||||
port: Some(7878),
|
||||
..ServarrConfig::default()
|
||||
});
|
||||
|
||||
|
||||
assert!(!result);
|
||||
assert_eq!(tab_state.index, 0);
|
||||
}
|
||||
|
||||
@@ -264,7 +264,10 @@ mod tests {
|
||||
assert!(episode_details_modal.episode_details_tabs.tabs[0]
|
||||
.contextual_help
|
||||
.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!(
|
||||
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,
|
||||
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!(
|
||||
episode_details_modal.episode_details_tabs.tabs[2].title,
|
||||
@@ -299,7 +305,10 @@ mod tests {
|
||||
assert!(episode_details_modal.episode_details_tabs.tabs[2]
|
||||
.contextual_help
|
||||
.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!(
|
||||
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,
|
||||
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]
|
||||
@@ -350,7 +362,10 @@ mod tests {
|
||||
&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!(
|
||||
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,
|
||||
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!(
|
||||
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,
|
||||
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")]
|
||||
#[rstest]
|
||||
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 network = Network::new(&app_arc, CancellationToken::new(), Client::new());
|
||||
|
||||
network
|
||||
.request_props_from(
|
||||
network_event,
|
||||
RequestMethod::Get,
|
||||
None::<()>,
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.request_props_from(network_event, RequestMethod::Get, None::<()>, None, None)
|
||||
.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 {
|
||||
let trimmed_name = servarr_name.trim();
|
||||
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);
|
||||
}
|
||||
} else {
|
||||
@@ -286,12 +294,12 @@ pub fn select_cli_configuration(app: &mut App<'_>, config: &AppConfig, command:
|
||||
Command::Radarr(_) => {
|
||||
let default_radarr_config = config.radarr.as_ref().unwrap()[0].clone();
|
||||
app.server_tabs.select_tab_by_config(&default_radarr_config);
|
||||
},
|
||||
}
|
||||
Command::Sonarr(_) => {
|
||||
let default_sonarr_config = config.sonarr.as_ref().unwrap()[0].clone();
|
||||
app.server_tabs.select_tab_by_config(&default_sonarr_config);
|
||||
},
|
||||
_ => ()
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user