refactor: Created dedicated proptests and assertions to clean up the handler unit tests
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
mod tests {
|
||||
use crate::app::App;
|
||||
use crate::app::key_binding::DEFAULT_KEYBINDINGS;
|
||||
use crate::assert_modal_absent;
|
||||
use crate::assert_navigation_pushed;
|
||||
use crate::event::Key;
|
||||
use crate::handlers::KeyEventHandler;
|
||||
use crate::handlers::sonarr_handlers::library::series_details_handler::SeriesDetailsHandler;
|
||||
@@ -69,7 +71,7 @@ mod tests {
|
||||
app.get_current_route(),
|
||||
app.data.sonarr_data.series_info_tabs.get_active_route()
|
||||
);
|
||||
assert_eq!(app.get_current_route(), left_block.into());
|
||||
assert_navigation_pushed!(app, left_block.into());
|
||||
|
||||
SeriesDetailsHandler::new(DEFAULT_KEYBINDINGS.right.key, &mut app, left_block, None).handle();
|
||||
|
||||
@@ -77,15 +79,15 @@ mod tests {
|
||||
app.get_current_route(),
|
||||
app.data.sonarr_data.series_info_tabs.get_active_route()
|
||||
);
|
||||
assert_eq!(app.get_current_route(), right_block.into());
|
||||
assert_navigation_pushed!(app, right_block.into());
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_submit {
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
use crate::extended_stateful_iterable_vec;
|
||||
use crate::network::sonarr_network::SonarrEvent;
|
||||
use crate::{assert_navigation_popped, extended_stateful_iterable_vec};
|
||||
|
||||
use super::*;
|
||||
|
||||
@@ -103,10 +105,7 @@ mod tests {
|
||||
SeriesDetailsHandler::new(SUBMIT_KEY, &mut app, ActiveSonarrBlock::SeriesDetails, None)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
ActiveSonarrBlock::SeasonDetails.into()
|
||||
);
|
||||
assert_navigation_pushed!(app, ActiveSonarrBlock::SeasonDetails.into());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -145,10 +144,7 @@ mod tests {
|
||||
SeriesDetailsHandler::new(SUBMIT_KEY, &mut app, ActiveSonarrBlock::SeriesHistory, None)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
ActiveSonarrBlock::SeriesHistoryDetails.into()
|
||||
);
|
||||
assert_navigation_pushed!(app, ActiveSonarrBlock::SeriesHistoryDetails.into());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -200,10 +196,7 @@ mod tests {
|
||||
SeriesDetailsHandler::new(SUBMIT_KEY, &mut app, prompt_block, None).handle();
|
||||
|
||||
assert!(app.data.sonarr_data.prompt_confirm);
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
ActiveSonarrBlock::SeriesDetails.into()
|
||||
);
|
||||
assert_navigation_popped!(app, ActiveSonarrBlock::SeriesDetails.into());
|
||||
assert_eq!(
|
||||
app.data.sonarr_data.prompt_confirm_action,
|
||||
Some(expected_action)
|
||||
@@ -225,16 +218,14 @@ mod tests {
|
||||
SeriesDetailsHandler::new(SUBMIT_KEY, &mut app, prompt_block, None).handle();
|
||||
|
||||
assert!(!app.data.sonarr_data.prompt_confirm);
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
ActiveSonarrBlock::SeriesDetails.into()
|
||||
);
|
||||
assert_navigation_popped!(app, ActiveSonarrBlock::SeriesDetails.into());
|
||||
assert_eq!(app.data.sonarr_data.prompt_confirm_action, None);
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_esc {
|
||||
use super::*;
|
||||
use crate::assert_navigation_popped;
|
||||
use crate::models::stateful_table::StatefulTable;
|
||||
use pretty_assertions::assert_eq;
|
||||
use ratatui::widgets::TableState;
|
||||
@@ -255,10 +246,7 @@ mod tests {
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
ActiveSonarrBlock::SeriesHistory.into()
|
||||
);
|
||||
assert_navigation_popped!(app, ActiveSonarrBlock::SeriesHistory.into());
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
@@ -279,10 +267,7 @@ mod tests {
|
||||
SeriesDetailsHandler::new(ESC_KEY, &mut app, prompt_block, None).handle();
|
||||
|
||||
assert!(!app.data.sonarr_data.prompt_confirm);
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
ActiveSonarrBlock::SeriesDetails.into()
|
||||
);
|
||||
assert_navigation_popped!(app, ActiveSonarrBlock::SeriesDetails.into());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -343,7 +328,7 @@ mod tests {
|
||||
use crate::models::servarr_data::sonarr::sonarr_data::sonarr_test_utils::utils::create_test_sonarr_data;
|
||||
use crate::models::sonarr_models::{Series, SeriesType};
|
||||
use crate::network::sonarr_network::SonarrEvent;
|
||||
use crate::test_edit_series_key;
|
||||
use crate::{assert_navigation_popped, test_edit_series_key};
|
||||
use pretty_assertions::{assert_eq, assert_str_eq};
|
||||
use serde_json::Number;
|
||||
use strum::IntoEnumIterator;
|
||||
@@ -378,7 +363,7 @@ mod tests {
|
||||
.handle();
|
||||
|
||||
assert_eq!(app.get_current_route(), active_sonarr_block.into());
|
||||
assert!(app.data.sonarr_data.edit_series_modal.is_none());
|
||||
assert_modal_absent!(app.data.sonarr_data.edit_series_modal);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -428,7 +413,7 @@ mod tests {
|
||||
ActiveSonarrBlock::SeriesDetails.into()
|
||||
);
|
||||
assert!(!app.data.sonarr_data.prompt_confirm);
|
||||
assert!(app.data.sonarr_data.prompt_confirm_action.is_none());
|
||||
assert_modal_absent!(app.data.sonarr_data.prompt_confirm_action);
|
||||
assert!(!app.is_routing);
|
||||
}
|
||||
|
||||
@@ -451,8 +436,8 @@ mod tests {
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
assert_navigation_pushed!(
|
||||
app,
|
||||
ActiveSonarrBlock::AutomaticallySearchSeriesPrompt.into()
|
||||
);
|
||||
}
|
||||
@@ -496,10 +481,7 @@ mod tests {
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
ActiveSonarrBlock::UpdateAndScanSeriesPrompt.into()
|
||||
);
|
||||
assert_navigation_pushed!(app, ActiveSonarrBlock::UpdateAndScanSeriesPrompt.into());
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
@@ -542,7 +524,7 @@ mod tests {
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(app.get_current_route(), active_sonarr_block.into());
|
||||
assert_navigation_pushed!(app, active_sonarr_block.into());
|
||||
assert!(app.is_routing);
|
||||
}
|
||||
|
||||
@@ -598,7 +580,7 @@ mod tests {
|
||||
.handle();
|
||||
|
||||
assert!(app.data.sonarr_data.prompt_confirm);
|
||||
assert_eq!(app.get_current_route(), active_sonarr_block.into());
|
||||
assert_navigation_popped!(app, active_sonarr_block.into());
|
||||
assert_eq!(
|
||||
app.data.sonarr_data.prompt_confirm_action,
|
||||
Some(expected_action)
|
||||
|
||||
Reference in New Issue
Block a user