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

This commit is contained in:
Dark-Alex-17 committed 2025-12-04 22:57:06 -07:00
1 parent 35dce0bf01
commit 49fd086b92
46 files changed
+1023 -1018

No files matched your search

@@ -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::sonarr_handlers::downloads::DownloadsHandler;
@@ -32,10 +33,7 @@ mod tests {
DownloadsHandler::new(DELETE_KEY, &mut app, ActiveSonarrBlock::Downloads, None).handle();
assert_eq!(
app.get_current_route(),
ActiveSonarrBlock::DeleteDownloadPrompt.into()
);
assert_navigation_pushed!(app, ActiveSonarrBlock::DeleteDownloadPrompt.into());
}
#[test]
@@ -60,6 +58,7 @@ mod tests {
use rstest::rstest;
use super::*;
use crate::assert_navigation_pushed;
#[rstest]
fn test_downloads_tab_left(#[values(true, false)] is_ready: bool) {
@@ -80,7 +79,7 @@ mod tests {
app.data.sonarr_data.main_tabs.get_active_route(),
ActiveSonarrBlock::Series.into()
);
assert_eq!(app.get_current_route(), ActiveSonarrBlock::Series.into());
assert_navigation_pushed!(app, ActiveSonarrBlock::Series.into());
}
#[rstest]
@@ -102,7 +101,7 @@ mod tests {
app.data.sonarr_data.main_tabs.get_active_route(),
ActiveSonarrBlock::Blocklist.into()
);
assert_eq!(app.get_current_route(), ActiveSonarrBlock::Blocklist.into());
assert_navigation_pushed!(app, ActiveSonarrBlock::Blocklist.into());
}
#[rstest]
@@ -134,6 +133,7 @@ mod tests {
use crate::network::sonarr_network::SonarrEvent;
use super::*;
use crate::{assert_navigation_popped, assert_navigation_pushed};
const SUBMIT_KEY: Key = DEFAULT_KEYBINDINGS.submit.key;
@@ -170,7 +170,7 @@ mod tests {
app.data.sonarr_data.prompt_confirm_action,
Some(expected_action)
);
assert_eq!(app.get_current_route(), base_route.into());
assert_navigation_popped!(app, base_route.into());
}
#[rstest]
@@ -193,7 +193,7 @@ mod tests {
assert!(!app.data.sonarr_data.prompt_confirm);
assert_eq!(app.data.sonarr_data.prompt_confirm_action, None);
assert_eq!(app.get_current_route(), base_route.into());
assert_navigation_popped!(app, base_route.into());
}
}
@@ -202,6 +202,7 @@ mod tests {
use rstest::rstest;
use super::*;
use crate::{assert_navigation_popped, assert_navigation_pushed};
const ESC_KEY: Key = DEFAULT_KEYBINDINGS.esc.key;
@@ -219,7 +220,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.sonarr_data.prompt_confirm);
}
@@ -233,17 +234,17 @@ mod tests {
DownloadsHandler::new(ESC_KEY, &mut app, ActiveSonarrBlock::Downloads, None).handle();
assert_eq!(app.get_current_route(), ActiveSonarrBlock::Downloads.into());
assert_navigation_popped!(app, ActiveSonarrBlock::Downloads.into());
assert!(app.error.text.is_empty());
}
}
mod test_handle_key_char {
use crate::assert_navigation_popped;
use crate::network::sonarr_network::SonarrEvent;
use pretty_assertions::assert_eq;
use rstest::rstest;
use crate::network::sonarr_network::SonarrEvent;
use super::*;
#[test]
@@ -264,10 +265,7 @@ mod tests {
)
.handle();
assert_eq!(
app.get_current_route(),
ActiveSonarrBlock::UpdateDownloadsPrompt.into()
);
assert_navigation_pushed!(app, ActiveSonarrBlock::UpdateDownloadsPrompt.into());
}
#[test]
@@ -310,7 +308,7 @@ mod tests {
)
.handle();
assert_eq!(app.get_current_route(), ActiveSonarrBlock::Downloads.into());
assert_navigation_pushed!(app, ActiveSonarrBlock::Downloads.into());
assert!(app.should_refresh);
}
@@ -375,7 +373,7 @@ mod tests {
app.data.sonarr_data.prompt_confirm_action,
Some(expected_action)
);
assert_eq!(app.get_current_route(), base_route.into());
assert_navigation_popped!(app, base_route.into());
}
}