refactor: Created dedicated proptests and assertions to clean up the handler unit tests
This commit is contained in:
@@ -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::system::system_details_handler::SystemDetailsHandler;
|
||||
@@ -652,9 +653,9 @@ mod tests {
|
||||
}
|
||||
|
||||
mod test_handle_submit {
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
use crate::assert_navigation_popped;
|
||||
use crate::network::sonarr_network::SonarrEvent;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
use super::*;
|
||||
|
||||
@@ -669,10 +670,7 @@ mod tests {
|
||||
SystemDetailsHandler::new(SUBMIT_KEY, &mut app, ActiveSonarrBlock::SystemTasks, None)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
ActiveSonarrBlock::SystemTaskStartConfirmPrompt.into()
|
||||
);
|
||||
assert_navigation_pushed!(app, ActiveSonarrBlock::SystemTaskStartConfirmPrompt.into());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -717,10 +715,7 @@ mod tests {
|
||||
app.data.sonarr_data.prompt_confirm_action,
|
||||
Some(SonarrEvent::StartTask(SonarrTaskName::default()))
|
||||
);
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
ActiveSonarrBlock::SystemTasks.into()
|
||||
);
|
||||
assert_navigation_popped!(app, ActiveSonarrBlock::SystemTasks.into());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -740,10 +735,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(),
|
||||
ActiveSonarrBlock::SystemTasks.into()
|
||||
);
|
||||
assert_navigation_popped!(app, ActiveSonarrBlock::SystemTasks.into());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -753,6 +745,7 @@ mod tests {
|
||||
use rstest::rstest;
|
||||
|
||||
use super::*;
|
||||
use crate::{assert_navigation_popped, assert_navigation_pushed};
|
||||
|
||||
const ESC_KEY: Key = DEFAULT_KEYBINDINGS.esc.key;
|
||||
|
||||
@@ -775,7 +768,7 @@ mod tests {
|
||||
|
||||
SystemDetailsHandler::new(ESC_KEY, &mut app, ActiveSonarrBlock::SystemLogs, None).handle();
|
||||
|
||||
assert_eq!(app.get_current_route(), ActiveSonarrBlock::System.into());
|
||||
assert_navigation_popped!(app, ActiveSonarrBlock::System.into());
|
||||
assert!(app.data.sonarr_data.log_details.items.is_empty());
|
||||
}
|
||||
|
||||
@@ -793,7 +786,7 @@ mod tests {
|
||||
|
||||
SystemDetailsHandler::new(ESC_KEY, &mut app, ActiveSonarrBlock::SystemTasks, None).handle();
|
||||
|
||||
assert_eq!(app.get_current_route(), ActiveSonarrBlock::System.into());
|
||||
assert_navigation_popped!(app, ActiveSonarrBlock::System.into());
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
@@ -816,7 +809,7 @@ mod tests {
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(app.get_current_route(), ActiveSonarrBlock::System.into());
|
||||
assert_navigation_popped!(app, ActiveSonarrBlock::System.into());
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
@@ -828,7 +821,7 @@ mod tests {
|
||||
|
||||
SystemDetailsHandler::new(ESC_KEY, &mut app, ActiveSonarrBlock::SystemUpdates, None).handle();
|
||||
|
||||
assert_eq!(app.get_current_route(), ActiveSonarrBlock::System.into());
|
||||
assert_navigation_popped!(app, ActiveSonarrBlock::System.into());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -846,10 +839,7 @@ mod tests {
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
ActiveSonarrBlock::SystemTasks.into()
|
||||
);
|
||||
assert_navigation_popped!(app, ActiveSonarrBlock::SystemTasks.into());
|
||||
assert!(!app.data.sonarr_data.prompt_confirm);
|
||||
}
|
||||
}
|
||||
@@ -861,6 +851,7 @@ mod tests {
|
||||
use crate::network::sonarr_network::SonarrEvent;
|
||||
|
||||
use super::*;
|
||||
use crate::{assert_navigation_popped, assert_navigation_pushed};
|
||||
|
||||
#[rstest]
|
||||
fn test_refresh_key(
|
||||
@@ -885,7 +876,7 @@ mod tests {
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(app.get_current_route(), active_sonarr_block.into());
|
||||
assert_navigation_pushed!(app, active_sonarr_block.into());
|
||||
assert!(app.should_refresh);
|
||||
}
|
||||
|
||||
@@ -943,10 +934,7 @@ mod tests {
|
||||
app.data.sonarr_data.prompt_confirm_action,
|
||||
Some(SonarrEvent::StartTask(SonarrTaskName::default()))
|
||||
);
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
ActiveSonarrBlock::SystemTasks.into()
|
||||
);
|
||||
assert_navigation_popped!(app, ActiveSonarrBlock::SystemTasks.into());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,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::system::SystemHandler;
|
||||
@@ -19,6 +20,7 @@ mod tests {
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
use super::*;
|
||||
use crate::assert_navigation_pushed;
|
||||
|
||||
#[rstest]
|
||||
fn test_system_tab_left(#[values(true, false)] is_ready: bool) {
|
||||
@@ -39,7 +41,7 @@ mod tests {
|
||||
app.data.sonarr_data.main_tabs.get_active_route(),
|
||||
ActiveSonarrBlock::Indexers.into()
|
||||
);
|
||||
assert_eq!(app.get_current_route(), ActiveSonarrBlock::Indexers.into());
|
||||
assert_navigation_pushed!(app, ActiveSonarrBlock::Indexers.into());
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
@@ -61,7 +63,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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,6 +71,7 @@ mod tests {
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
use super::*;
|
||||
use crate::{assert_navigation_popped, assert_navigation_pushed};
|
||||
|
||||
const ESC_KEY: Key = DEFAULT_KEYBINDINGS.esc.key;
|
||||
|
||||
@@ -82,7 +85,7 @@ mod tests {
|
||||
|
||||
SystemHandler::new(ESC_KEY, &mut app, ActiveSonarrBlock::System, None).handle();
|
||||
|
||||
assert_eq!(app.get_current_route(), ActiveSonarrBlock::System.into());
|
||||
assert_navigation_popped!(app, ActiveSonarrBlock::System.into());
|
||||
assert!(app.error.text.is_empty());
|
||||
}
|
||||
}
|
||||
@@ -121,10 +124,7 @@ mod tests {
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
ActiveSonarrBlock::SystemUpdates.into()
|
||||
);
|
||||
assert_navigation_pushed!(app, ActiveSonarrBlock::SystemUpdates.into());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -185,10 +185,7 @@ mod tests {
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
ActiveSonarrBlock::SystemQueuedEvents.into()
|
||||
);
|
||||
assert_navigation_pushed!(app, ActiveSonarrBlock::SystemQueuedEvents.into());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -249,7 +246,7 @@ mod tests {
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(app.get_current_route(), ActiveSonarrBlock::System.into());
|
||||
assert_navigation_pushed!(app, ActiveSonarrBlock::System.into());
|
||||
assert!(app.should_refresh);
|
||||
}
|
||||
|
||||
@@ -313,10 +310,7 @@ mod tests {
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
ActiveSonarrBlock::SystemLogs.into()
|
||||
);
|
||||
assert_navigation_pushed!(app, ActiveSonarrBlock::SystemLogs.into());
|
||||
assert_eq!(
|
||||
app.data.sonarr_data.log_details.items,
|
||||
app.data.sonarr_data.logs.items
|
||||
@@ -386,10 +380,7 @@ mod tests {
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
ActiveSonarrBlock::SystemTasks.into()
|
||||
);
|
||||
assert_navigation_pushed!(app, ActiveSonarrBlock::SystemTasks.into());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user