refactor: Created dedicated proptests and assertions to clean up the handler unit tests

This commit is contained in:
2025-12-04 22:57:06 -07:00
parent 35dce0bf01
commit 49fd086b92
46 changed files with 1023 additions and 1018 deletions
@@ -6,6 +6,7 @@ mod tests {
use crate::app::App;
use crate::app::key_binding::DEFAULT_KEYBINDINGS;
use crate::assert_navigation_pushed;
use crate::event::Key;
use crate::handlers::KeyEventHandler;
use crate::handlers::radarr_handlers::downloads::DownloadsHandler;
@@ -31,10 +32,7 @@ mod tests {
DownloadsHandler::new(DELETE_KEY, &mut app, ActiveRadarrBlock::Downloads, None).handle();
assert_eq!(
app.get_current_route(),
ActiveRadarrBlock::DeleteDownloadPrompt.into()
);
assert_navigation_pushed!(app, ActiveRadarrBlock::DeleteDownloadPrompt.into());
}
#[test]
@@ -78,10 +76,7 @@ mod tests {
app.data.radarr_data.main_tabs.get_active_route(),
ActiveRadarrBlock::Collections.into()
);
assert_eq!(
app.get_current_route(),
ActiveRadarrBlock::Collections.into()
);
assert_navigation_pushed!(app, ActiveRadarrBlock::Collections.into());
}
#[rstest]
@@ -102,7 +97,7 @@ mod tests {
app.data.radarr_data.main_tabs.get_active_route(),
ActiveRadarrBlock::Blocklist.into()
);
assert_eq!(app.get_current_route(), ActiveRadarrBlock::Blocklist.into());
assert_navigation_pushed!(app, ActiveRadarrBlock::Blocklist.into());
}
#[rstest]
@@ -133,6 +128,7 @@ mod tests {
use crate::network::radarr_network::RadarrEvent;
use super::*;
use crate::{assert_navigation_popped, assert_navigation_pushed};
const SUBMIT_KEY: Key = DEFAULT_KEYBINDINGS.submit.key;
@@ -169,7 +165,7 @@ mod tests {
app.data.radarr_data.prompt_confirm_action,
Some(expected_action)
);
assert_eq!(app.get_current_route(), base_route.into());
assert_navigation_popped!(app, base_route.into());
}
#[rstest]
@@ -192,7 +188,7 @@ mod tests {
assert!(!app.data.radarr_data.prompt_confirm);
assert_eq!(app.data.radarr_data.prompt_confirm_action, None);
assert_eq!(app.get_current_route(), base_route.into());
assert_navigation_popped!(app, base_route.into());
}
}
@@ -201,6 +197,7 @@ mod tests {
use rstest::rstest;
use super::*;
use crate::{assert_navigation_popped, assert_navigation_pushed};
const ESC_KEY: Key = DEFAULT_KEYBINDINGS.esc.key;
@@ -218,7 +215,7 @@ mod tests {
DownloadsHandler::new(ESC_KEY, &mut app, prompt_block, None).handle();
assert_eq!(app.get_current_route(), base_block.into());
assert_navigation_popped!(app, base_block.into());
assert!(!app.data.radarr_data.prompt_confirm);
}
@@ -232,17 +229,17 @@ mod tests {
DownloadsHandler::new(ESC_KEY, &mut app, ActiveRadarrBlock::Downloads, None).handle();
assert_eq!(app.get_current_route(), ActiveRadarrBlock::Downloads.into());
assert_navigation_popped!(app, ActiveRadarrBlock::Downloads.into());
assert!(app.error.text.is_empty());
}
}
mod test_handle_key_char {
use crate::assert_navigation_popped;
use crate::network::radarr_network::RadarrEvent;
use pretty_assertions::assert_eq;
use rstest::rstest;
use crate::network::radarr_network::RadarrEvent;
use super::*;
#[test]
@@ -262,10 +259,7 @@ mod tests {
)
.handle();
assert_eq!(
app.get_current_route(),
ActiveRadarrBlock::UpdateDownloadsPrompt.into()
);
assert_navigation_pushed!(app, ActiveRadarrBlock::UpdateDownloadsPrompt.into());
}
#[test]
@@ -308,7 +302,7 @@ mod tests {
)
.handle();
assert_eq!(app.get_current_route(), ActiveRadarrBlock::Downloads.into());
assert_navigation_pushed!(app, ActiveRadarrBlock::Downloads.into());
assert!(app.should_refresh);
}
@@ -373,7 +367,7 @@ mod tests {
app.data.radarr_data.prompt_confirm_action,
Some(expected_action)
);
assert_eq!(app.get_current_route(), base_route.into());
assert_navigation_popped!(app, base_route.into());
}
}