Complete unit tests
This commit is contained in:
parent
f5f2cc478f
commit
b1e764ffb9
@ -51,6 +51,7 @@ impl AppMachine<AppFetch> {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(recv_err) => match recv_err {
|
Err(recv_err) => match recv_err {
|
||||||
|
TryRecvError::Empty => AppMachine::fetch(inner, fetch).into(),
|
||||||
TryRecvError::Disconnected => {
|
TryRecvError::Disconnected => {
|
||||||
if first {
|
if first {
|
||||||
AppMachine::matches(inner, AppMatches::new(None, fetch)).into()
|
AppMachine::matches(inner, AppMatches::new(None, fetch)).into()
|
||||||
@ -58,7 +59,6 @@ impl AppMachine<AppFetch> {
|
|||||||
AppMachine::browse(inner).into()
|
AppMachine::browse(inner).into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TryRecvError::Empty => AppMachine::fetch(inner, fetch).into(),
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -101,276 +101,98 @@ impl IAppEventFetch for AppMachine<AppFetch> {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use musichoard::collection::artist::ArtistMeta;
|
||||||
|
|
||||||
// use std::sync::mpsc;
|
use crate::tui::{
|
||||||
|
app::machine::tests::{inner, music_hoard},
|
||||||
|
lib::interface::musicbrainz::{self, Match},
|
||||||
|
testmod::COLLECTION,
|
||||||
|
};
|
||||||
|
|
||||||
// use musichoard::collection::{
|
use super::*;
|
||||||
// album::{AlbumDate, AlbumId, AlbumMeta, AlbumPrimaryType, AlbumSecondaryType},
|
|
||||||
// artist::{ArtistId, ArtistMeta},
|
|
||||||
// };
|
|
||||||
|
|
||||||
// use crate::tui::{
|
#[test]
|
||||||
// app::{
|
fn recv_ok_fetch_ok() {
|
||||||
// machine::tests::{inner, music_hoard},
|
let (tx, rx) = mpsc::channel::<FetchResult>();
|
||||||
// IAppAccess,
|
|
||||||
// },
|
|
||||||
// lib::interface::musicbrainz::Match,
|
|
||||||
// };
|
|
||||||
|
|
||||||
// use super::*;
|
let artist = COLLECTION[3].meta.clone();
|
||||||
|
let fetch_result = Ok(AppMatchesInfo::artist::<Match<ArtistMeta>>(artist, vec![]));
|
||||||
|
tx.send(fetch_result).unwrap();
|
||||||
|
|
||||||
// #[test]
|
let app = AppMachine::app_fetch_new(inner(music_hoard(COLLECTION.clone())), rx);
|
||||||
// fn fetch_musicbrainz_artist_api_error() {
|
assert!(matches!(app, AppState::Matches(_)));
|
||||||
// let mut mb_api = MockIMusicBrainz::new();
|
}
|
||||||
|
|
||||||
// let error = Err(musicbrainz::Error::RateLimit);
|
#[test]
|
||||||
|
fn recv_ok_fetch_err() {
|
||||||
|
let (tx, rx) = mpsc::channel::<FetchResult>();
|
||||||
|
|
||||||
// mb_api
|
let fetch_result = Err(musicbrainz::Error::RateLimit);
|
||||||
// .expect_search_artist()
|
tx.send(fetch_result).unwrap();
|
||||||
// .times(1)
|
|
||||||
// .return_once(|_| error);
|
|
||||||
|
|
||||||
// let browse = AppMachine::browse(inner_with_mb(music_hoard(COLLECTION.to_owned()), mb_api));
|
let app = AppMachine::app_fetch_new(inner(music_hoard(COLLECTION.clone())), rx);
|
||||||
|
assert!(matches!(app, AppState::Error(_)));
|
||||||
|
}
|
||||||
|
|
||||||
// // Use the fourth artist for this test as they have no MBID.
|
#[test]
|
||||||
// let browse = browse.increment_selection(Delta::Line).unwrap_browse();
|
fn recv_err_empty() {
|
||||||
// let browse = browse.increment_selection(Delta::Line).unwrap_browse();
|
let (_tx, rx) = mpsc::channel::<FetchResult>();
|
||||||
// let browse = browse.increment_selection(Delta::Line).unwrap_browse();
|
|
||||||
|
|
||||||
// let app = browse.fetch_musicbrainz();
|
let app = AppMachine::app_fetch_new(inner(music_hoard(COLLECTION.clone())), rx);
|
||||||
// app.unwrap_error();
|
assert!(matches!(app, AppState::Fetch(_)));
|
||||||
// }
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn fetch_musicbrainz_album_api_error() {
|
fn recv_err_disconnected_first() {
|
||||||
// let mut mb_api = MockIMusicBrainz::new();
|
let (_, rx) = mpsc::channel::<FetchResult>();
|
||||||
|
|
||||||
// let error = Err(musicbrainz::Error::RateLimit);
|
let app = AppMachine::app_fetch_new(inner(music_hoard(COLLECTION.clone())), rx);
|
||||||
|
assert!(matches!(app, AppState::Matches(_)));
|
||||||
|
}
|
||||||
|
|
||||||
// mb_api
|
#[test]
|
||||||
// .expect_search_release_group()
|
fn recv_err_disconnected_next() {
|
||||||
// .times(1)
|
let (_, rx) = mpsc::channel::<FetchResult>();
|
||||||
// .return_once(|_, _| error);
|
|
||||||
|
|
||||||
// let browse = AppMachine::browse(inner_with_mb(music_hoard(COLLECTION.to_owned()), mb_api));
|
let fetch = AppFetch::new(rx);
|
||||||
|
let app = AppMachine::app_fetch_next(inner(music_hoard(COLLECTION.clone())), fetch);
|
||||||
|
assert!(matches!(app, AppState::Browse(_)));
|
||||||
|
}
|
||||||
|
|
||||||
// let app = browse.fetch_musicbrainz();
|
#[test]
|
||||||
// app.unwrap_error();
|
fn empty_first_then_ready() {
|
||||||
// }
|
let (tx, rx) = mpsc::channel::<FetchResult>();
|
||||||
|
|
||||||
|
let app = AppMachine::app_fetch_new(inner(music_hoard(COLLECTION.clone())), rx);
|
||||||
|
assert!(matches!(app, AppState::Fetch(_)));
|
||||||
|
|
||||||
// impl<T> Match<T> {
|
let artist = COLLECTION[3].meta.clone();
|
||||||
// pub fn new(score: u8, item: T) -> Self {
|
let fetch_result = Ok(AppMatchesInfo::artist::<Match<ArtistMeta>>(artist, vec![]));
|
||||||
// Match {
|
tx.send(fetch_result).unwrap();
|
||||||
// score,
|
|
||||||
// item,
|
|
||||||
// disambiguation: None,
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn artist_matches_info_vec() -> Vec<AppMatchesInfo> {
|
let app = app.unwrap_fetch().fetch_result_ready();
|
||||||
// let artist_1 = ArtistMeta::new(ArtistId::new("Artist 1"));
|
assert!(matches!(app, AppState::Matches(_)));
|
||||||
|
}
|
||||||
|
|
||||||
// let artist_1_1 = artist_1.clone();
|
#[test]
|
||||||
// let artist_match_1_1 = Match::new(100, artist_1_1);
|
fn abort() {
|
||||||
|
let (_, rx) = mpsc::channel::<FetchResult>();
|
||||||
|
|
||||||
// let artist_1_2 = artist_1.clone();
|
let fetch = AppFetch::new(rx);
|
||||||
// let mut artist_match_1_2 = Match::new(100, artist_1_2);
|
let app = AppMachine::fetch(inner(music_hoard(COLLECTION.clone())), fetch);
|
||||||
// artist_match_1_2.disambiguation = Some(String::from("some disambiguation"));
|
|
||||||
|
|
||||||
// let list = vec![artist_match_1_1.clone(), artist_match_1_2.clone()];
|
let app = app.abort();
|
||||||
// let matches_info_1 = AppMatchesInfo::artist(artist_1.clone(), list);
|
assert!(matches!(app, AppState::Browse(_)));
|
||||||
|
}
|
||||||
|
|
||||||
// let artist_2 = ArtistMeta::new(ArtistId::new("Artist 2"));
|
#[test]
|
||||||
|
fn no_op() {
|
||||||
|
let (_, rx) = mpsc::channel::<FetchResult>();
|
||||||
|
|
||||||
// let artist_2_1 = artist_1.clone();
|
let fetch = AppFetch::new(rx);
|
||||||
// let album_match_2_1 = Match::new(100, artist_2_1);
|
let app = AppMachine::fetch(inner(music_hoard(COLLECTION.clone())), fetch);
|
||||||
|
|
||||||
// let list = vec![album_match_2_1.clone()];
|
let app = app.no_op();
|
||||||
// let matches_info_2 = AppMatchesInfo::artist(artist_2.clone(), list);
|
assert!(matches!(app, AppState::Fetch(_)));
|
||||||
|
}
|
||||||
// vec![matches_info_1, matches_info_2]
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn album_matches_info_vec() -> Vec<AppMatchesInfo> {
|
|
||||||
// let album_1 = AlbumMeta::new(
|
|
||||||
// AlbumId::new("Album 1"),
|
|
||||||
// AlbumDate::new(Some(1990), Some(5), None),
|
|
||||||
// Some(AlbumPrimaryType::Album),
|
|
||||||
// vec![AlbumSecondaryType::Live, AlbumSecondaryType::Compilation],
|
|
||||||
// );
|
|
||||||
|
|
||||||
// let album_1_1 = album_1.clone();
|
|
||||||
// let album_match_1_1 = Match::new(100, album_1_1);
|
|
||||||
|
|
||||||
// let mut album_1_2 = album_1.clone();
|
|
||||||
// album_1_2.id.title.push_str(" extra title part");
|
|
||||||
// album_1_2.secondary_types.pop();
|
|
||||||
// let album_match_1_2 = Match::new(100, album_1_2);
|
|
||||||
|
|
||||||
// let list = vec![album_match_1_1.clone(), album_match_1_2.clone()];
|
|
||||||
// let matches_info_1 = AppMatchesInfo::album(album_1.clone(), list);
|
|
||||||
|
|
||||||
// let album_2 = AlbumMeta::new(
|
|
||||||
// AlbumId::new("Album 2"),
|
|
||||||
// AlbumDate::new(Some(2001), None, None),
|
|
||||||
// Some(AlbumPrimaryType::Album),
|
|
||||||
// vec![],
|
|
||||||
// );
|
|
||||||
|
|
||||||
// let album_2_1 = album_1.clone();
|
|
||||||
// let album_match_2_1 = Match::new(100, album_2_1);
|
|
||||||
|
|
||||||
// let list = vec![album_match_2_1.clone()];
|
|
||||||
// let matches_info_2 = AppMatchesInfo::album(album_2.clone(), list);
|
|
||||||
|
|
||||||
// vec![matches_info_1, matches_info_2]
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn receiver(matches_info_vec: Vec<AppMatchesInfo>) -> FetchReceiver {
|
|
||||||
// let (tx, rx) = mpsc::channel();
|
|
||||||
// for matches_info in matches_info_vec.into_iter() {
|
|
||||||
// tx.send(Ok(matches_info)).unwrap();
|
|
||||||
// }
|
|
||||||
// rx
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn push_cannot_have_mbid(matches_info_vec: &mut [AppMatchesInfo]) {
|
|
||||||
// for matches_info in matches_info_vec.iter_mut() {
|
|
||||||
// matches_info.push_cannot_have_mbid();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// #[test]
|
|
||||||
// fn create_empty() {
|
|
||||||
// let matches = AppMachine::matches(inner(music_hoard(vec![])), AppMatches::empty(fetch()));
|
|
||||||
|
|
||||||
// let widget_state = WidgetState::default();
|
|
||||||
|
|
||||||
// assert_eq!(matches.state.current, None);
|
|
||||||
// assert_eq!(matches.state.state, widget_state);
|
|
||||||
|
|
||||||
// let mut app = matches.no_op();
|
|
||||||
// let public = app.get();
|
|
||||||
// let public_matches = public.state.unwrap_matches();
|
|
||||||
|
|
||||||
// assert_eq!(public_matches.matches, None);
|
|
||||||
// assert_eq!(public_matches.state, &widget_state);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// #[test]
|
|
||||||
// fn create_nonempty() {
|
|
||||||
// let mut matches_info_vec = album_matches_info_vec();
|
|
||||||
// let matches = AppMachine::app_matches(
|
|
||||||
// inner(music_hoard(vec![])),
|
|
||||||
// receiver(matches_info_vec.clone()),
|
|
||||||
// )
|
|
||||||
// .unwrap_matches();
|
|
||||||
// push_cannot_have_mbid(&mut matches_info_vec);
|
|
||||||
|
|
||||||
// let mut widget_state = WidgetState::default();
|
|
||||||
// widget_state.list.select(Some(0));
|
|
||||||
|
|
||||||
// assert_eq!(matches.state.current.as_ref(), Some(&matches_info_vec[0]));
|
|
||||||
// assert_eq!(matches.state.state, widget_state);
|
|
||||||
|
|
||||||
// let mut app = matches.no_op();
|
|
||||||
// let public = app.get();
|
|
||||||
// let public_matches = public.state.unwrap_matches();
|
|
||||||
|
|
||||||
// assert_eq!(public_matches.matches, Some(&matches_info_vec[0]));
|
|
||||||
// assert_eq!(public_matches.state, &widget_state);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn matches_flow(mut matches_info_vec: Vec<AppMatchesInfo>) {
|
|
||||||
// let matches = AppMachine::app_matches(
|
|
||||||
// inner(music_hoard(vec![])),
|
|
||||||
// receiver(matches_info_vec.clone()),
|
|
||||||
// )
|
|
||||||
// .unwrap_matches();
|
|
||||||
// push_cannot_have_mbid(&mut matches_info_vec);
|
|
||||||
|
|
||||||
// let mut widget_state = WidgetState::default();
|
|
||||||
// widget_state.list.select(Some(0));
|
|
||||||
|
|
||||||
// assert_eq!(matches.state.current.as_ref(), Some(&matches_info_vec[0]));
|
|
||||||
// assert_eq!(matches.state.state, widget_state);
|
|
||||||
|
|
||||||
// let matches = matches.prev_match().unwrap_matches();
|
|
||||||
|
|
||||||
// assert_eq!(matches.state.current.as_ref(), Some(&matches_info_vec[0]));
|
|
||||||
// assert_eq!(matches.state.state.list.selected(), Some(0));
|
|
||||||
|
|
||||||
// let matches = matches.next_match().unwrap_matches();
|
|
||||||
|
|
||||||
// assert_eq!(matches.state.current.as_ref(), Some(&matches_info_vec[0]));
|
|
||||||
// assert_eq!(matches.state.state.list.selected(), Some(1));
|
|
||||||
|
|
||||||
// // Next is CannotHaveMBID
|
|
||||||
// let matches = matches.next_match().unwrap_matches();
|
|
||||||
|
|
||||||
// assert_eq!(matches.state.current.as_ref(), Some(&matches_info_vec[0]));
|
|
||||||
// assert_eq!(matches.state.state.list.selected(), Some(2));
|
|
||||||
|
|
||||||
// let matches = matches.next_match().unwrap_matches();
|
|
||||||
|
|
||||||
// assert_eq!(matches.state.current.as_ref(), Some(&matches_info_vec[0]));
|
|
||||||
// assert_eq!(matches.state.state.list.selected(), Some(2));
|
|
||||||
|
|
||||||
// let matches = matches.select().unwrap_matches();
|
|
||||||
|
|
||||||
// assert_eq!(matches.state.current.as_ref(), Some(&matches_info_vec[1]));
|
|
||||||
// assert_eq!(matches.state.state.list.selected(), Some(0));
|
|
||||||
|
|
||||||
// // And it's done
|
|
||||||
// matches.select().unwrap_browse();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// #[test]
|
|
||||||
// fn artist_matches_flow() {
|
|
||||||
// matches_flow(artist_matches_info_vec());
|
|
||||||
// }
|
|
||||||
|
|
||||||
// #[test]
|
|
||||||
// fn album_matches_flow() {
|
|
||||||
// matches_flow(album_matches_info_vec());
|
|
||||||
// }
|
|
||||||
|
|
||||||
// #[test]
|
|
||||||
// fn matches_abort() {
|
|
||||||
// let mut matches_info_vec = album_matches_info_vec();
|
|
||||||
// let matches = AppMachine::app_matches(
|
|
||||||
// inner(music_hoard(vec![])),
|
|
||||||
// receiver(matches_info_vec.clone()),
|
|
||||||
// )
|
|
||||||
// .unwrap_matches();
|
|
||||||
// push_cannot_have_mbid(&mut matches_info_vec);
|
|
||||||
|
|
||||||
// let mut widget_state = WidgetState::default();
|
|
||||||
// widget_state.list.select(Some(0));
|
|
||||||
|
|
||||||
// assert_eq!(matches.state.current.as_ref(), Some(&matches_info_vec[0]));
|
|
||||||
// assert_eq!(matches.state.state, widget_state);
|
|
||||||
|
|
||||||
// matches.abort().unwrap_browse();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// #[test]
|
|
||||||
// fn matches_select_empty() {
|
|
||||||
// let matches =
|
|
||||||
// AppMachine::app_matches(inner(music_hoard(vec![])), receiver(vec![])).unwrap_matches();
|
|
||||||
|
|
||||||
// assert_eq!(matches.state.current, None);
|
|
||||||
|
|
||||||
// matches.select().unwrap_browse();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// #[test]
|
|
||||||
// fn no_op() {
|
|
||||||
// let matches =
|
|
||||||
// AppMachine::app_matches(inner(music_hoard(vec![])), receiver(vec![])).unwrap_matches();
|
|
||||||
// let app = matches.no_op();
|
|
||||||
// app.unwrap_matches();
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user