Unit test
All checks were successful
Cargo CI / Build and Test (pull_request) Successful in 2m6s
Cargo CI / Lint (pull_request) Successful in 1m7s

This commit is contained in:
Wojciech Kozlowski 2025-01-05 12:00:28 +01:00
parent 829bb89696
commit 38fe036a4b

View File

@ -330,9 +330,12 @@ mod tests {
machine::tests::{inner, inner_with_mb, input_event, music_hoard},
IApp, IAppAccess, IAppInput,
},
lib::interface::musicbrainz::{
api::Entity,
daemon::{MbParams, MockIMbJobSender},
lib::{
interface::musicbrainz::{
api::Entity,
daemon::{MbParams, MockIMbJobSender},
},
MockIMusicHoard,
},
};
@ -660,14 +663,34 @@ mod tests {
// (3) An album with a different album_id than the selected one.
// (4) This album has an MBID that is identical to that of the selected match.
let mb_ref = AlbumMbRef::Some(mbid().into());
let removed = Album::new(AlbumId::new("Not the Same").with_mb_ref(mb_ref));
let removed = Album::new(AlbumId::new("Album: Not the Same").with_mb_ref(mb_ref.clone()));
artist.albums.push(removed.clone());
// (5) An album after the one that will be removed. Selection must remain on it.
let selected = Album::new(AlbumId::new("Album: Z"));
artist.albums.push(selected.clone());
let (_tx, rx) = mpsc::channel();
let app_matches = MatchState::new(matches_info.clone(), FetchState::search(rx));
let collection = vec![artist];
let mut music_hoard = music_hoard(collection.clone());
let mut reduced = collection.clone();
reduced[0].albums.retain(|a| a.meta.id.mb_ref != mb_ref);
// We need a custom music_hoard to override the get_filtered expectations.
let mut music_hoard = MockIMusicHoard::new();
let mut seq = Sequence::new();
music_hoard
.expect_get_filtered()
.times(2)
.in_sequence(&mut seq)
.return_const(collection.clone());
music_hoard
.expect_get_filtered()
.times(1)
.in_sequence(&mut seq)
.return_const(reduced.clone());
match matches_info {
EntityMatches::Artist(_) => panic!(),
EntityMatches::Album(matches) => {
@ -678,7 +701,7 @@ mod tests {
.expect_get_collection()
.times(1)
.in_sequence(&mut seq)
.return_const(collection);
.return_const(collection.clone());
music_hoard
.expect_remove_album()
.times(1)
@ -698,8 +721,26 @@ mod tests {
}
}
let matches = AppMachine::match_state(inner(music_hoard), app_matches);
matches.select().unwrap_fetch();
let mut matches = AppMachine::match_state(inner(music_hoard), app_matches);
// Make sure the last album is selected.
let selection = &mut matches.inner.selection;
selection.increment_category();
selection.increment_selection(&collection, Delta::Line);
selection.increment_selection(&collection, Delta::Line);
// Check that the correct album is selected.
let state = selection.state_album(&collection).unwrap();
let album = &collection[0].albums[state.index];
assert_eq!(album.meta, selected.meta);
let mut fetch = matches.select().unwrap_fetch();
// Check that the correct album is still selected in the reduced collection.
let selection = &mut fetch.inner.selection;
let state = selection.state_album(&reduced).unwrap();
let album = &reduced[0].albums[state.index];
assert_eq!(album.meta, selected.meta);
}
#[test]