From e622be328808af14eab1575d17e881a3842ce15f Mon Sep 17 00:00:00 2001 From: Alex Clarke Date: Thu, 10 Sep 2026 00:41:07 -0600 Subject: [PATCH] test: assert delegated handlers pop exactly one navigation stack frame test_handler_delegation! asserted only that the current route equalled the base block after Esc. When the delegated block was itself the base block the stack read [base, base], so that assertion held whether or not the sub-handler popped, and the case asserted nothing. Capture the navigation stack depth before delegating and assert it drops by exactly one, which also catches a handler that pops and then re-pushes. Depth is read through a test-only accessor on App; the navigation_stack field stays private. Main tab blocks clear errors on Esc rather than popping, by design, so they cannot be probed this way at all. Drop them from the delegation value lists; the remaining values in each list already exercise the same dispatch arm. --- src/app/mod.rs | 4 ++++ src/handlers/handler_test_utils.rs | 6 ++++++ src/handlers/lidarr_handlers/lidarr_handler_tests.rs | 7 ------- src/handlers/radarr_handlers/radarr_handler_tests.rs | 8 -------- src/handlers/readarr_handlers/readarr_handler_tests.rs | 7 ------- src/handlers/sonarr_handlers/sonarr_handler_tests.rs | 7 ------- 6 files changed, 10 insertions(+), 29 deletions(-) diff --git a/src/app/mod.rs b/src/app/mod.rs index 14b18339..18baab56 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -371,6 +371,10 @@ impl App<'_> { ..App::default() } } + + pub fn get_navigation_stack_depth(&self) -> usize { + self.navigation_stack.len() + } } #[derive(Default)] diff --git a/src/handlers/handler_test_utils.rs b/src/handlers/handler_test_utils.rs index 592f7c69..4c81d576 100644 --- a/src/handlers/handler_test_utils.rs +++ b/src/handlers/handler_test_utils.rs @@ -333,10 +333,16 @@ mod test_utils { let mut app = App::test_default_fully_populated(); app.push_navigation_stack($base.into()); app.push_navigation_stack($active_block.into()); + let navigation_stack_depth_before_delegation = app.get_navigation_stack_depth(); $handler::new(DEFAULT_KEYBINDINGS.esc.key, &mut app, $active_block, None).handle(); pretty_assertions::assert_eq!(app.get_current_route(), $base.into()); + pretty_assertions::assert_eq!( + app.get_navigation_stack_depth(), + navigation_stack_depth_before_delegation - 1, + "Expected the delegated handler to pop exactly one route off the navigation stack" + ); }; } diff --git a/src/handlers/lidarr_handlers/lidarr_handler_tests.rs b/src/handlers/lidarr_handlers/lidarr_handler_tests.rs index 1a507092..b11d2131 100644 --- a/src/handlers/lidarr_handlers/lidarr_handler_tests.rs +++ b/src/handlers/lidarr_handlers/lidarr_handler_tests.rs @@ -160,7 +160,6 @@ mod tests { #[rstest] fn test_delegates_library_blocks_to_library_handler( #[values( - ActiveLidarrBlock::Artists, ActiveLidarrBlock::ArtistsSortPrompt, ActiveLidarrBlock::FilterArtists, ActiveLidarrBlock::FilterArtistsError, @@ -187,7 +186,6 @@ mod tests { #[rstest] fn test_delegates_downloads_blocks_to_downloads_handler( #[values( - ActiveLidarrBlock::Downloads, ActiveLidarrBlock::DeleteDownloadPrompt, ActiveLidarrBlock::UpdateDownloadsPrompt )] @@ -203,7 +201,6 @@ mod tests { #[rstest] fn test_delegates_blocklist_blocks_to_blocklist_handler( #[values( - ActiveLidarrBlock::Blocklist, ActiveLidarrBlock::BlocklistItemDetails, ActiveLidarrBlock::DeleteBlocklistItemPrompt, ActiveLidarrBlock::BlocklistClearAllItemsPrompt, @@ -221,7 +218,6 @@ mod tests { #[rstest] fn test_delegates_history_blocks_to_history_handler( #[values( - ActiveLidarrBlock::History, ActiveLidarrBlock::HistoryItemDetails, ActiveLidarrBlock::HistorySortPrompt, ActiveLidarrBlock::FilterHistory, @@ -241,7 +237,6 @@ mod tests { #[rstest] fn test_delegates_root_folders_blocks_to_root_folders_handler( #[values( - ActiveLidarrBlock::RootFolders, ActiveLidarrBlock::AddRootFolderPrompt, ActiveLidarrBlock::DeleteRootFolderPrompt )] @@ -258,7 +253,6 @@ mod tests { fn test_delegates_indexers_blocks_to_indexers_handler( #[values( ActiveLidarrBlock::DeleteIndexerPrompt, - ActiveLidarrBlock::Indexers, ActiveLidarrBlock::AllIndexerSettingsPrompt, ActiveLidarrBlock::IndexerSettingsConfirmPrompt, ActiveLidarrBlock::IndexerSettingsMaximumSizeInput, @@ -278,7 +272,6 @@ mod tests { #[rstest] fn test_delegates_system_blocks_to_system_handler( #[values( - ActiveLidarrBlock::System, ActiveLidarrBlock::SystemLogs, ActiveLidarrBlock::SystemQueuedEvents, ActiveLidarrBlock::SystemTasks, diff --git a/src/handlers/radarr_handlers/radarr_handler_tests.rs b/src/handlers/radarr_handlers/radarr_handler_tests.rs index 5333f699..58c2ec15 100644 --- a/src/handlers/radarr_handlers/radarr_handler_tests.rs +++ b/src/handlers/radarr_handlers/radarr_handler_tests.rs @@ -123,7 +123,6 @@ mod tests { #[rstest] fn test_delegates_system_blocks_to_system_handler( #[values( - ActiveRadarrBlock::System, ActiveRadarrBlock::SystemLogs, ActiveRadarrBlock::SystemQueuedEvents, ActiveRadarrBlock::SystemTasks, @@ -142,7 +141,6 @@ mod tests { #[rstest] fn test_delegates_library_blocks_to_library_handler( #[values( - ActiveRadarrBlock::Movies, ActiveRadarrBlock::MoviesSortPrompt, ActiveRadarrBlock::SearchMovie, ActiveRadarrBlock::SearchMovieError, @@ -186,7 +184,6 @@ mod tests { #[rstest] fn test_delegates_collections_blocks_to_collections_handler( #[values( - ActiveRadarrBlock::Collections, ActiveRadarrBlock::SearchCollection, ActiveRadarrBlock::CollectionsSortPrompt, ActiveRadarrBlock::SearchCollectionError, @@ -213,7 +210,6 @@ mod tests { fn test_delegates_indexers_blocks_to_indexers_handler( #[values( ActiveRadarrBlock::DeleteIndexerPrompt, - ActiveRadarrBlock::Indexers, ActiveRadarrBlock::AllIndexerSettingsPrompt, ActiveRadarrBlock::IndexerSettingsAvailabilityDelayInput, ActiveRadarrBlock::IndexerSettingsConfirmPrompt, @@ -237,7 +233,6 @@ mod tests { #[rstest] fn test_delegates_downloads_blocks_to_downloads_handler( #[values( - ActiveRadarrBlock::Downloads, ActiveRadarrBlock::DeleteDownloadPrompt, ActiveRadarrBlock::UpdateDownloadsPrompt )] @@ -253,7 +248,6 @@ mod tests { #[rstest] fn test_delegates_root_folders_blocks_to_root_folders_handler( #[values( - ActiveRadarrBlock::RootFolders, ActiveRadarrBlock::AddRootFolderPrompt, ActiveRadarrBlock::DeleteRootFolderPrompt )] @@ -269,7 +263,6 @@ mod tests { #[rstest] fn test_delegates_blocklist_blocks_to_blocklist_handler( #[values( - ActiveRadarrBlock::Blocklist, ActiveRadarrBlock::BlocklistItemDetails, ActiveRadarrBlock::DeleteBlocklistItemPrompt, ActiveRadarrBlock::BlocklistClearAllItemsPrompt, @@ -287,7 +280,6 @@ mod tests { #[rstest] fn test_delegates_history_blocks_to_history_handler( #[values( - ActiveRadarrBlock::History, ActiveRadarrBlock::HistoryItemDetails, ActiveRadarrBlock::HistorySortPrompt, ActiveRadarrBlock::FilterHistory, diff --git a/src/handlers/readarr_handlers/readarr_handler_tests.rs b/src/handlers/readarr_handlers/readarr_handler_tests.rs index 445aab40..dd8e7aa4 100644 --- a/src/handlers/readarr_handlers/readarr_handler_tests.rs +++ b/src/handlers/readarr_handlers/readarr_handler_tests.rs @@ -160,7 +160,6 @@ mod tests { #[rstest] fn test_delegates_library_blocks_to_library_handler( #[values( - ActiveReadarrBlock::Authors, ActiveReadarrBlock::AuthorsSortPrompt, ActiveReadarrBlock::FilterAuthors, ActiveReadarrBlock::FilterAuthorsError, @@ -180,7 +179,6 @@ mod tests { #[rstest] fn test_delegates_blocklist_blocks_to_blocklist_handler( #[values( - ActiveReadarrBlock::Blocklist, ActiveReadarrBlock::BlocklistItemDetails, ActiveReadarrBlock::DeleteBlocklistItemPrompt, ActiveReadarrBlock::BlocklistClearAllItemsPrompt, @@ -198,7 +196,6 @@ mod tests { #[rstest] fn test_delegates_downloads_blocks_to_downloads_handler( #[values( - ActiveReadarrBlock::Downloads, ActiveReadarrBlock::DeleteDownloadPrompt, ActiveReadarrBlock::UpdateDownloadsPrompt )] @@ -214,7 +211,6 @@ mod tests { #[rstest] fn test_delegates_history_blocks_to_history_handler( #[values( - ActiveReadarrBlock::History, ActiveReadarrBlock::HistoryItemDetails, ActiveReadarrBlock::HistorySortPrompt, ActiveReadarrBlock::SearchHistory, @@ -234,7 +230,6 @@ mod tests { #[rstest] fn test_delegates_root_folders_blocks_to_root_folders_handler( #[values( - ActiveReadarrBlock::RootFolders, ActiveReadarrBlock::AddRootFolderPrompt, ActiveReadarrBlock::DeleteRootFolderPrompt )] @@ -250,7 +245,6 @@ mod tests { #[rstest] fn test_delegates_indexers_blocks_to_indexers_handler( #[values( - ActiveReadarrBlock::Indexers, ActiveReadarrBlock::DeleteIndexerPrompt, ActiveReadarrBlock::TestIndexer, ActiveReadarrBlock::TestAllIndexers, @@ -274,7 +268,6 @@ mod tests { #[rstest] fn test_delegates_system_blocks_to_system_handler( #[values( - ActiveReadarrBlock::System, ActiveReadarrBlock::SystemLogs, ActiveReadarrBlock::SystemQueuedEvents, ActiveReadarrBlock::SystemTasks, diff --git a/src/handlers/sonarr_handlers/sonarr_handler_tests.rs b/src/handlers/sonarr_handlers/sonarr_handler_tests.rs index 8cc007ee..208e6ded 100644 --- a/src/handlers/sonarr_handlers/sonarr_handler_tests.rs +++ b/src/handlers/sonarr_handlers/sonarr_handler_tests.rs @@ -165,7 +165,6 @@ mod tests { ActiveSonarrBlock::SearchSeriesHistory, ActiveSonarrBlock::SearchSeriesHistoryError, ActiveSonarrBlock::SeasonDetails, - ActiveSonarrBlock::Series, ActiveSonarrBlock::SeriesDetails, ActiveSonarrBlock::SeriesHistory, ActiveSonarrBlock::SeriesHistorySortPrompt, @@ -186,7 +185,6 @@ mod tests { #[rstest] fn test_delegates_downloads_blocks_to_downloads_handler( #[values( - ActiveSonarrBlock::Downloads, ActiveSonarrBlock::DeleteDownloadPrompt, ActiveSonarrBlock::UpdateDownloadsPrompt )] @@ -202,7 +200,6 @@ mod tests { #[rstest] fn test_delegates_blocklist_blocks_to_blocklist_handler( #[values( - ActiveSonarrBlock::Blocklist, ActiveSonarrBlock::BlocklistItemDetails, ActiveSonarrBlock::DeleteBlocklistItemPrompt, ActiveSonarrBlock::BlocklistClearAllItemsPrompt, @@ -220,7 +217,6 @@ mod tests { #[rstest] fn test_delegates_history_blocks_to_history_handler( #[values( - ActiveSonarrBlock::History, ActiveSonarrBlock::HistoryItemDetails, ActiveSonarrBlock::HistorySortPrompt, ActiveSonarrBlock::FilterHistory, @@ -240,7 +236,6 @@ mod tests { #[rstest] fn test_delegates_root_folders_blocks_to_root_folders_handler( #[values( - ActiveSonarrBlock::RootFolders, ActiveSonarrBlock::AddRootFolderPrompt, ActiveSonarrBlock::DeleteRootFolderPrompt )] @@ -257,7 +252,6 @@ mod tests { fn test_delegates_indexers_blocks_to_indexers_handler( #[values( ActiveSonarrBlock::DeleteIndexerPrompt, - ActiveSonarrBlock::Indexers, ActiveSonarrBlock::AllIndexerSettingsPrompt, ActiveSonarrBlock::IndexerSettingsConfirmPrompt, ActiveSonarrBlock::IndexerSettingsMaximumSizeInput, @@ -277,7 +271,6 @@ mod tests { #[rstest] fn test_delegates_system_blocks_to_system_handler( #[values( - ActiveSonarrBlock::System, ActiveSonarrBlock::SystemLogs, ActiveSonarrBlock::SystemQueuedEvents, ActiveSonarrBlock::SystemTasks,