From 62918ff3ca894976a1e62991f6a92840f45e561a Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Mon, 30 Dec 2024 23:15:00 +0100 Subject: [PATCH] Add a unit test --- src/tui/app/machine/fetch_state.rs | 31 +++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/tui/app/machine/fetch_state.rs b/src/tui/app/machine/fetch_state.rs index 12fac9e..862dd65 100644 --- a/src/tui/app/machine/fetch_state.rs +++ b/src/tui/app/machine/fetch_state.rs @@ -729,20 +729,23 @@ mod tests { assert!(matches!(app, AppState::Fetch(_))); } - #[test] - fn recv_err_empty_first() { - let mut collection = COLLECTION.clone(); - collection[0].albums.clear(); - - let requests = AppMachine::browse_release_group_job(&collection[0].meta.info.musicbrainz); - + fn browse_release_group_expectation(artist: &Artist) -> MockIMbJobSender { + let requests = AppMachine::browse_release_group_job(&artist.meta.info.musicbrainz); let mut mb_job_sender = MockIMbJobSender::new(); mb_job_sender .expect_submit_background_job() .with(predicate::always(), predicate::eq(requests)) .times(1) .return_once(|_, _| Ok(())); + mb_job_sender + } + #[test] + fn recv_err_empty_first() { + let mut collection = COLLECTION.clone(); + collection[0].albums.clear(); + + let mb_job_sender = browse_release_group_expectation(&collection[0]); let inner = inner_with_mb(music_hoard(collection), mb_job_sender); let app = AppMachine::app_fetch_first(inner); assert!(matches!(app, AppState::Fetch(_))); @@ -760,6 +763,20 @@ mod tests { assert!(matches!(app, AppState::Fetch(_))); } + #[test] + fn recv_err_disconnected_next() { + let mut collection = COLLECTION.clone(); + collection[0].albums.clear(); + + let (_, rx) = mpsc::channel::(); + let fetch = FetchState::search(rx); + + let mb_job_sender = browse_release_group_expectation(&collection[0]); + let inner = inner_with_mb(music_hoard(collection), mb_job_sender); + let app = AppMachine::app_fetch_next(inner, fetch); + assert!(matches!(app, AppState::Fetch(_))); + } + #[test] fn empty_first_then_ready() { let (tx, rx) = mpsc::channel::();