Compare commits
2 Commits
6b90f470be
...
9488464b11
Author | SHA1 | Date | |
---|---|---|---|
9488464b11 | |||
967c4b4175 |
@ -100,14 +100,14 @@ impl ArtistMeta {
|
||||
|
||||
impl Default for ArtistInfo {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
Self::new(MbRefOption::None)
|
||||
}
|
||||
}
|
||||
|
||||
impl ArtistInfo {
|
||||
pub fn new() -> Self {
|
||||
pub fn new(musicbrainz: MbRefOption<MbArtistRef>) -> Self {
|
||||
ArtistInfo {
|
||||
musicbrainz: MbRefOption::None,
|
||||
musicbrainz,
|
||||
properties: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
@ -461,7 +461,7 @@ mod tests {
|
||||
let mut expected: MbRefOption<MbArtistRef> = MbRefOption::None;
|
||||
assert_eq!(music_hoard.collection[0].meta.info.musicbrainz, expected);
|
||||
|
||||
let mut info = ArtistInfo::new();
|
||||
let mut info = ArtistInfo::default();
|
||||
info.musicbrainz = MbRefOption::Some(MbArtistRef::from_uuid_str(MBID).unwrap());
|
||||
|
||||
// Setting a URL on an artist not in the collection is an error.
|
||||
|
@ -350,7 +350,7 @@ mod tests {
|
||||
let app = browse.increment_selection(Delta::Line);
|
||||
|
||||
let app = app.unwrap_browse().fetch_musicbrainz();
|
||||
assert!(matches!(app, AppState::Match(_)));
|
||||
assert!(matches!(app, AppState::Fetch(_)));
|
||||
}
|
||||
|
||||
fn lookup_album_expectation(
|
||||
@ -413,7 +413,7 @@ mod tests {
|
||||
let app = browse.increment_selection(Delta::Line);
|
||||
|
||||
let app = app.unwrap_browse().fetch_musicbrainz();
|
||||
assert!(matches!(app, AppState::Match(_)));
|
||||
assert!(matches!(app, AppState::Fetch(_)));
|
||||
}
|
||||
|
||||
fn lookup_artist_expectation(job_sender: &mut MockIMbJobSender, artist: &ArtistMeta) {
|
||||
@ -542,21 +542,23 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recv_err_disconnected_first() {
|
||||
let (_, rx) = mpsc::channel::<MbApiResult>();
|
||||
fn recv_err_empty_first() {
|
||||
let mut collection = COLLECTION.clone();
|
||||
collection[0].albums.clear();
|
||||
|
||||
let inner = inner(music_hoard(COLLECTION.clone()));
|
||||
let fetch = FetchState::new(rx);
|
||||
let app = AppMachine::app_fetch_next(inner, fetch);
|
||||
let app = AppMachine::app_fetch_first(inner(music_hoard(collection)));
|
||||
assert!(matches!(app, AppState::Match(_)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recv_err_disconnected_next() {
|
||||
let (_, rx) = mpsc::channel::<MbApiResult>();
|
||||
fn recv_err_empty_next() {
|
||||
let mut collection = COLLECTION.clone();
|
||||
collection[0].albums.clear();
|
||||
|
||||
let (_, rx) = mpsc::channel::<MbApiResult>();
|
||||
let fetch = FetchState::new(rx);
|
||||
let app = AppMachine::app_fetch_next(inner(music_hoard(COLLECTION.clone())), fetch);
|
||||
|
||||
let app = AppMachine::app_fetch_next(inner(music_hoard(collection)), fetch);
|
||||
assert!(matches!(app, AppState::Browse(_)));
|
||||
}
|
||||
|
||||
|
@ -308,7 +308,7 @@ impl IAppInteractMatch for AppMachine<MatchState> {
|
||||
mod tests {
|
||||
use std::{collections::VecDeque, sync::mpsc};
|
||||
|
||||
use mockall::predicate;
|
||||
use mockall::predicate::{self, eq};
|
||||
use musichoard::collection::{
|
||||
album::{AlbumDate, AlbumId, AlbumInfo, AlbumMeta, AlbumPrimaryType, AlbumSecondaryType},
|
||||
artist::{ArtistId, ArtistMeta},
|
||||
@ -346,8 +346,12 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
fn artist_meta() -> ArtistMeta {
|
||||
ArtistMeta::new(ArtistId::new("Artist"))
|
||||
}
|
||||
|
||||
fn artist_match() -> MatchStateInfo {
|
||||
let artist = ArtistMeta::new(ArtistId::new("Artist"));
|
||||
let artist = artist_meta();
|
||||
|
||||
let artist_1 = artist.clone();
|
||||
let artist_match_1 = Match::new(100, artist_1);
|
||||
@ -361,14 +365,13 @@ mod tests {
|
||||
}
|
||||
|
||||
fn artist_lookup() -> MatchStateInfo {
|
||||
let artist = ArtistMeta::new(ArtistId::new("Artist"));
|
||||
let artist = artist_meta();
|
||||
let lookup = Lookup::new(artist.clone());
|
||||
MatchStateInfo::artist_lookup(artist, lookup)
|
||||
}
|
||||
|
||||
fn album_match() -> MatchStateInfo {
|
||||
let artist_id = ArtistId::new("Artist");
|
||||
let album = AlbumMeta::new(
|
||||
fn album_meta() -> AlbumMeta {
|
||||
AlbumMeta::new(
|
||||
AlbumId::new("Album"),
|
||||
AlbumDate::new(Some(1990), Some(5), None),
|
||||
AlbumInfo::new(
|
||||
@ -376,7 +379,12 @@ mod tests {
|
||||
Some(AlbumPrimaryType::Album),
|
||||
vec![AlbumSecondaryType::Live, AlbumSecondaryType::Compilation],
|
||||
),
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
fn album_match() -> MatchStateInfo {
|
||||
let artist_id = ArtistId::new("Artist");
|
||||
let album = album_meta();
|
||||
|
||||
let album_1 = album.clone();
|
||||
let album_match_1 = Match::new(100, album_1);
|
||||
@ -392,15 +400,7 @@ mod tests {
|
||||
|
||||
fn album_lookup() -> MatchStateInfo {
|
||||
let artist_id = ArtistId::new("Artist");
|
||||
let album = AlbumMeta::new(
|
||||
AlbumId::new("Album"),
|
||||
AlbumDate::new(Some(1990), Some(5), None),
|
||||
AlbumInfo::new(
|
||||
MbRefOption::None,
|
||||
Some(AlbumPrimaryType::Album),
|
||||
vec![AlbumSecondaryType::Live, AlbumSecondaryType::Compilation],
|
||||
),
|
||||
);
|
||||
let album = album_meta();
|
||||
let lookup = Lookup::new(album.clone());
|
||||
MatchStateInfo::album_lookup(artist_id, album, lookup)
|
||||
}
|
||||
@ -457,11 +457,34 @@ mod tests {
|
||||
|
||||
fn match_state_flow(mut matches_info: MatchStateInfo, len: usize) {
|
||||
// tx must exist for rx to return Empty rather than Disconnected.
|
||||
#[allow(unused_variables)]
|
||||
let (tx, rx) = mpsc::channel();
|
||||
let (_tx, rx) = mpsc::channel();
|
||||
let app_matches = MatchState::new(Some(matches_info.clone()), FetchState::new(rx));
|
||||
|
||||
let matches = AppMachine::match_state(inner(music_hoard(vec![])), app_matches);
|
||||
let mut music_hoard = music_hoard(vec![]);
|
||||
let artist_id = ArtistId::new("Artist");
|
||||
match matches_info {
|
||||
MatchStateInfo::Album(_) => {
|
||||
let album_id = AlbumId::new("Album");
|
||||
let mut info = album_meta().info;
|
||||
info.musicbrainz = MbRefOption::CannotHaveMbid;
|
||||
music_hoard
|
||||
.expect_set_album_info()
|
||||
.with(eq(artist_id.clone()), eq(album_id.clone()), eq(info))
|
||||
.times(1)
|
||||
.return_once(|_, _, _| Ok(()));
|
||||
}
|
||||
MatchStateInfo::Artist(_) => {
|
||||
let mut info = artist_meta().info;
|
||||
info.musicbrainz = MbRefOption::CannotHaveMbid;
|
||||
music_hoard
|
||||
.expect_set_artist_info()
|
||||
.with(eq(artist_id.clone()), eq(info))
|
||||
.times(1)
|
||||
.return_once(|_, _| Ok(()));
|
||||
}
|
||||
}
|
||||
|
||||
let matches = AppMachine::match_state(inner(music_hoard), app_matches);
|
||||
matches_info.push_cannot_have_mbid();
|
||||
matches_info.push_manual_input_mbid();
|
||||
|
||||
@ -547,10 +570,11 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn select_empty() {
|
||||
// Note that what really matters in this test is actually that the transmit channel has
|
||||
// disconnected and so the receive within FetchState concludes there are no more matches.
|
||||
// This test will become obsolete with #203 so it just needs to work well enough for
|
||||
// coverage. We expect the error state, because after selecting, fetch will be invoked, but
|
||||
// with an empty collection, an error will be raised.
|
||||
let matches = AppMachine::match_state(inner(music_hoard(vec![])), match_state(None));
|
||||
matches.select().unwrap_browse();
|
||||
matches.select().unwrap_error();
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user