refactor: Migrated the handle_table_events macro into a trait for better IDE support, created a TableEventAdapter wrapper for the KeyEventHandlers to make it so that the trait can be used properly and a simple function to replace the previous call to the handle_table_events macro
This commit is contained in:
1 parent
71240373c0
commit
35dce0bf01
42 files changed
+1425
-756
No files matched your search
@@ -3,9 +3,9 @@ mod tests {
|
||||
use crate::app::App;
|
||||
use crate::app::key_binding::DEFAULT_KEYBINDINGS;
|
||||
use crate::event::Key;
|
||||
use crate::handle_table_events;
|
||||
use crate::handlers::KeyEventHandler;
|
||||
use crate::handlers::table_handler::TableHandlingConfig;
|
||||
use crate::handlers::table_handler::handle_table;
|
||||
use crate::models::radarr_models::Movie;
|
||||
use crate::models::servarr_data::radarr::radarr_data::ActiveRadarrBlock;
|
||||
use crate::models::servarr_models::Language;
|
||||
@@ -33,13 +33,13 @@ mod tests {
|
||||
let minimal_movie_table_handling_config =
|
||||
TableHandlingConfig::new(ActiveRadarrBlock::Movies.into());
|
||||
|
||||
match self.active_radarr_block {
|
||||
ActiveRadarrBlock::MovieDetails => {
|
||||
self.handle_movies_table_events(minimal_movie_table_handling_config);
|
||||
}
|
||||
_ => {
|
||||
self.handle_movies_table_events(movie_table_handling_config);
|
||||
}
|
||||
let config = match self.active_radarr_block {
|
||||
ActiveRadarrBlock::MovieDetails => minimal_movie_table_handling_config,
|
||||
_ => movie_table_handling_config,
|
||||
};
|
||||
|
||||
if !handle_table(self, |app| &mut app.data.radarr_data.movies, config) {
|
||||
self.handle_key_event();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,10 +90,14 @@ mod tests {
|
||||
fn handle_esc(&mut self) {}
|
||||
|
||||
fn handle_char_key_event(&mut self) {}
|
||||
}
|
||||
|
||||
impl TableHandlerUnit<'_, '_> {
|
||||
handle_table_events!(self, movies, self.app.data.radarr_data.movies, Movie);
|
||||
fn app_mut(&mut self) -> &mut App<'b> {
|
||||
self.app
|
||||
}
|
||||
|
||||
fn current_route(&self) -> crate::models::Route {
|
||||
self.app.get_current_route()
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_scroll_up_and_down {
|
||||
@@ -198,6 +202,86 @@ mod tests {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_table_sort_scroll_up_with_sort_some() {
|
||||
let movie_field_vec = sort_options();
|
||||
let mut app = App::test_default();
|
||||
app.data.radarr_data.movies.sorting(sort_options());
|
||||
app.push_navigation_stack(ActiveRadarrBlock::MoviesSortPrompt.into());
|
||||
|
||||
assert_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.movies
|
||||
.sort
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection(),
|
||||
&movie_field_vec[0]
|
||||
);
|
||||
|
||||
TableHandlerUnit::new(
|
||||
DEFAULT_KEYBINDINGS.up.key,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::MoviesSortPrompt,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.movies
|
||||
.sort
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection(),
|
||||
&movie_field_vec[movie_field_vec.len() - 1]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_table_sort_scroll_down_with_sort_some() {
|
||||
let movie_field_vec = sort_options();
|
||||
let mut app = App::test_default();
|
||||
app.data.radarr_data.movies.sorting(sort_options());
|
||||
app.push_navigation_stack(ActiveRadarrBlock::MoviesSortPrompt.into());
|
||||
|
||||
assert_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.movies
|
||||
.sort
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection(),
|
||||
&movie_field_vec[0]
|
||||
);
|
||||
|
||||
TableHandlerUnit::new(
|
||||
DEFAULT_KEYBINDINGS.down.key,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::MoviesSortPrompt,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.movies
|
||||
.sort
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection(),
|
||||
&movie_field_vec[0]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_home_end {
|
||||
@@ -426,6 +510,70 @@ mod tests {
|
||||
&movie_field_vec[0]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_table_sort_home_with_sort_some() {
|
||||
let movie_field_vec = sort_options();
|
||||
let mut app = App::test_default();
|
||||
app.data.radarr_data.movies.sorting(sort_options());
|
||||
app.push_navigation_stack(ActiveRadarrBlock::MoviesSortPrompt.into());
|
||||
|
||||
TableHandlerUnit::new(
|
||||
DEFAULT_KEYBINDINGS.down.key,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::MoviesSortPrompt,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
TableHandlerUnit::new(
|
||||
DEFAULT_KEYBINDINGS.home.key,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::MoviesSortPrompt,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.movies
|
||||
.sort
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection(),
|
||||
&movie_field_vec[0]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_table_sort_end_with_sort_some() {
|
||||
let movie_field_vec = sort_options();
|
||||
let mut app = App::test_default();
|
||||
app.data.radarr_data.movies.sorting(sort_options());
|
||||
app.push_navigation_stack(ActiveRadarrBlock::MoviesSortPrompt.into());
|
||||
|
||||
TableHandlerUnit::new(
|
||||
DEFAULT_KEYBINDINGS.end.key,
|
||||
&mut app,
|
||||
ActiveRadarrBlock::MoviesSortPrompt,
|
||||
None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.movies
|
||||
.sort
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection(),
|
||||
&movie_field_vec[movie_field_vec.len() - 1]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_pagination_scroll {
|
||||
@@ -835,6 +983,30 @@ mod tests {
|
||||
|
||||
assert_eq!(app.get_current_route(), ActiveRadarrBlock::Movies.into());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_table_block_esc_with_filter_applied() {
|
||||
let mut app = App::test_default();
|
||||
app.push_navigation_stack(ActiveRadarrBlock::Movies.into());
|
||||
app.data.radarr_data.movies = StatefulTable {
|
||||
filter: Some("Test".into()),
|
||||
filtered_items: Some(Vec::new()),
|
||||
filtered_state: Some(TableState::default()),
|
||||
..StatefulTable::default()
|
||||
};
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.movies
|
||||
.set_items(vec![Movie::default()]);
|
||||
|
||||
TableHandlerUnit::new(ESC_KEY, &mut app, ActiveRadarrBlock::Movies, None).handle();
|
||||
|
||||
assert_eq!(app.get_current_route(), ActiveRadarrBlock::Movies.into());
|
||||
assert_eq!(app.data.radarr_data.movies.filter, None);
|
||||
assert_eq!(app.data.radarr_data.movies.filtered_items, None);
|
||||
assert_eq!(app.data.radarr_data.movies.filtered_state, None);
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_key_char {
|
||||
|
||||
Reference in new issue
Block a user