Add a unit test
Some checks failed
Cargo CI / Build and Test (pull_request) Failing after 1m55s
Cargo CI / Lint (pull_request) Successful in 1m6s

This commit is contained in:
Wojciech Kozlowski 2024-12-30 23:15:00 +01:00
parent 6464f8300d
commit 62918ff3ca

View File

@ -729,20 +729,23 @@ mod tests {
assert!(matches!(app, AppState::Fetch(_))); assert!(matches!(app, AppState::Fetch(_)));
} }
#[test] fn browse_release_group_expectation(artist: &Artist) -> MockIMbJobSender {
fn recv_err_empty_first() { let requests = AppMachine::browse_release_group_job(&artist.meta.info.musicbrainz);
let mut collection = COLLECTION.clone();
collection[0].albums.clear();
let requests = AppMachine::browse_release_group_job(&collection[0].meta.info.musicbrainz);
let mut mb_job_sender = MockIMbJobSender::new(); let mut mb_job_sender = MockIMbJobSender::new();
mb_job_sender mb_job_sender
.expect_submit_background_job() .expect_submit_background_job()
.with(predicate::always(), predicate::eq(requests)) .with(predicate::always(), predicate::eq(requests))
.times(1) .times(1)
.return_once(|_, _| Ok(())); .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 inner = inner_with_mb(music_hoard(collection), mb_job_sender);
let app = AppMachine::app_fetch_first(inner); let app = AppMachine::app_fetch_first(inner);
assert!(matches!(app, AppState::Fetch(_))); assert!(matches!(app, AppState::Fetch(_)));
@ -760,6 +763,20 @@ mod tests {
assert!(matches!(app, AppState::Fetch(_))); assert!(matches!(app, AppState::Fetch(_)));
} }
#[test]
fn recv_err_disconnected_next() {
let mut collection = COLLECTION.clone();
collection[0].albums.clear();
let (_, rx) = mpsc::channel::<MbApiResult>();
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] #[test]
fn empty_first_then_ready() { fn empty_first_then_ready() {
let (tx, rx) = mpsc::channel::<MbApiResult>(); let (tx, rx) = mpsc::channel::<MbApiResult>();