Add unit tests
All checks were successful
Cargo CI / Build and Test (pull_request) Successful in 2m1s
Cargo CI / Lint (pull_request) Successful in 1m7s

This commit is contained in:
Wojciech Kozlowski 2024-09-29 12:31:04 +02:00
parent d477037532
commit fbaee818af

View File

@ -358,6 +358,81 @@ mod tests {
.return_once(|_, _| Ok(())); .return_once(|_, _| Ok(()));
} }
#[test]
fn fetch_single_album() {
let mut mb_job_sender = MockIMbJobSender::new();
let artist_id = COLLECTION[1].meta.id.clone();
let artist_mbid: Mbid = "11111111-1111-1111-1111-111111111111".try_into().unwrap();
let album_meta = COLLECTION[1].albums[0].meta.clone();
search_release_group_expectation(
&mut mb_job_sender,
&artist_id,
&artist_mbid,
&[album_meta],
);
let music_hoard = music_hoard(COLLECTION.to_owned());
let inner = AppInner::new(music_hoard, mb_job_sender);
// Use second artist and have album selected to match the expectation.
let browse = AppMachine::browse_state(inner);
let browse = browse.increment_selection(Delta::Line).unwrap_browse();
let app = browse.increment_category();
let app = app.unwrap_browse().fetch_musicbrainz();
assert!(matches!(app, AppState::Fetch(_)));
}
#[test]
fn fetch_single_album_nothing_to_fetch() {
let music_hoard = music_hoard(COLLECTION.to_owned());
let inner = inner(music_hoard);
// Use second artist, have second album selected (has MBID) to match the expectation.
let browse = AppMachine::browse_state(inner);
let browse = browse.increment_selection(Delta::Line).unwrap_browse();
let browse = browse.increment_category().unwrap_browse();
let app = browse.increment_selection(Delta::Line);
let app = app.unwrap_browse().fetch_musicbrainz();
assert!(matches!(app, AppState::Browse(_)));
}
#[test]
fn fetch_single_album_no_artist_mbid() {
let music_hoard = music_hoard(COLLECTION.to_owned());
let inner = inner(music_hoard);
// Use third artist and have album selected to match the expectation.
let browse = AppMachine::browse_state(inner);
let browse = browse.increment_selection(Delta::Line).unwrap_browse();
let browse = browse.increment_selection(Delta::Line).unwrap_browse();
let app = browse.increment_category();
let app = app.unwrap_browse().fetch_musicbrainz();
assert!(matches!(app, AppState::Error(_)));
}
#[test]
fn fetch_single_album_no_album() {
let mut collection = COLLECTION.to_owned();
collection[1].albums.clear();
let music_hoard = music_hoard(collection);
let inner = inner(music_hoard);
// Use second artist and have album selected to match the expectation.
let browse = AppMachine::browse_state(inner);
let browse = browse.increment_selection(Delta::Line).unwrap_browse();
let app = browse.increment_category();
let app = app.unwrap_browse().fetch_musicbrainz();
assert!(matches!(app, AppState::Error(_)));
}
#[test] #[test]
fn fetch_albums() { fn fetch_albums() {
let mut mb_job_sender = MockIMbJobSender::new(); let mut mb_job_sender = MockIMbJobSender::new();