Unit tests for matches
This commit is contained in:
parent
196de92959
commit
c6a6d21199
@ -27,6 +27,17 @@ pub struct AppFetch {
|
|||||||
fetch_rx: FetchReceiver,
|
fetch_rx: FetchReceiver,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl AppFetch {
|
||||||
|
pub fn new(fetch_rx: FetchReceiver) -> Self {
|
||||||
|
AppFetch { fetch_rx }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type FetchError = MbError;
|
||||||
|
pub type FetchResult = Result<AppMatchesInfo, FetchError>;
|
||||||
|
pub type FetchSender = mpsc::Sender<FetchResult>;
|
||||||
|
pub type FetchReceiver = mpsc::Receiver<FetchResult>;
|
||||||
|
|
||||||
impl AppMachine<AppFetch> {
|
impl AppMachine<AppFetch> {
|
||||||
fn fetch(inner: AppInner, state: AppFetch) -> Self {
|
fn fetch(inner: AppInner, state: AppFetch) -> Self {
|
||||||
AppMachine { inner, state }
|
AppMachine { inner, state }
|
||||||
@ -57,15 +68,14 @@ impl AppMachine<AppFetch> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let fetch = AppFetch { fetch_rx };
|
let fetch = AppFetch::new(fetch_rx);
|
||||||
AppMachine::app_fetch_next(inner, fetch, true)
|
AppMachine::app_fetch_next(inner, fetch, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn app_fetch_next(inner: AppInner, fetch: AppFetch, first: bool) -> App {
|
pub fn app_fetch_next(inner: AppInner, fetch: AppFetch, first: bool) -> App {
|
||||||
match fetch.fetch_rx.try_recv() {
|
match fetch.fetch_rx.try_recv() {
|
||||||
Ok(fetch_result) => match fetch_result {
|
Ok(fetch_result) => match fetch_result {
|
||||||
Ok(mut next_match) => {
|
Ok(next_match) => {
|
||||||
next_match.push_cannot_have_mbid();
|
|
||||||
let current = Some(next_match);
|
let current = Some(next_match);
|
||||||
AppMachine::matches(inner, AppMatches::new(current, fetch)).into()
|
AppMachine::matches(inner, AppMatches::new(current, fetch)).into()
|
||||||
}
|
}
|
||||||
@ -76,7 +86,7 @@ impl AppMachine<AppFetch> {
|
|||||||
Err(recv_err) => match recv_err {
|
Err(recv_err) => match recv_err {
|
||||||
TryRecvError::Disconnected => {
|
TryRecvError::Disconnected => {
|
||||||
if first {
|
if first {
|
||||||
AppMachine::matches(inner, AppMatches::empty(fetch)).into()
|
AppMachine::matches(inner, AppMatches::new(None, fetch)).into()
|
||||||
} else {
|
} else {
|
||||||
AppMachine::browse(inner).into()
|
AppMachine::browse(inner).into()
|
||||||
}
|
}
|
||||||
@ -85,65 +95,7 @@ impl AppMachine<AppFetch> {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl From<AppMachine<AppFetch>> for App {
|
|
||||||
fn from(machine: AppMachine<AppFetch>) -> Self {
|
|
||||||
AppState::Fetch(machine)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> From<&'a mut AppMachine<AppFetch>> for AppPublic<'a> {
|
|
||||||
fn from(machine: &'a mut AppMachine<AppFetch>) -> Self {
|
|
||||||
AppPublic {
|
|
||||||
inner: (&mut machine.inner).into(),
|
|
||||||
state: AppState::Fetch(()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl IAppInteractFetch for AppMachine<AppFetch> {
|
|
||||||
type APP = App;
|
|
||||||
|
|
||||||
fn abort(self) -> Self::APP {
|
|
||||||
AppMachine::browse(self.inner).into()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn no_op(self) -> Self::APP {
|
|
||||||
self.into()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl IAppEventFetch for AppMachine<AppFetch> {
|
|
||||||
type APP = App;
|
|
||||||
|
|
||||||
fn fetch_result_ready(self) -> Self::APP {
|
|
||||||
Self::app_fetch_next(self.inner, self.state, false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type FetchError = MbError;
|
|
||||||
type FetchResult = Result<AppMatchesInfo, FetchError>;
|
|
||||||
type FetchSender = mpsc::Sender<FetchResult>;
|
|
||||||
type FetchReceiver = mpsc::Receiver<FetchResult>;
|
|
||||||
|
|
||||||
trait IAppInteractFetchPrivate {
|
|
||||||
fn fetch_artist(
|
|
||||||
musicbrainz: Arc<Mutex<dyn IMusicBrainz + Send>>,
|
|
||||||
fetch_tx: FetchSender,
|
|
||||||
events: EventSender,
|
|
||||||
artist: ArtistMeta,
|
|
||||||
);
|
|
||||||
fn fetch_albums(
|
|
||||||
musicbrainz: Arc<Mutex<dyn IMusicBrainz + Send>>,
|
|
||||||
fetch_tx: FetchSender,
|
|
||||||
events: EventSender,
|
|
||||||
arid: Mbid,
|
|
||||||
albums: Vec<AlbumMeta>,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
impl IAppInteractFetchPrivate for AppMachine<AppFetch> {
|
|
||||||
fn fetch_artist(
|
fn fetch_artist(
|
||||||
musicbrainz: Arc<Mutex<dyn IMusicBrainz + Send>>,
|
musicbrainz: Arc<Mutex<dyn IMusicBrainz + Send>>,
|
||||||
fetch_tx: FetchSender,
|
fetch_tx: FetchSender,
|
||||||
@ -192,3 +144,274 @@ impl IAppInteractFetchPrivate for AppMachine<AppFetch> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<AppMachine<AppFetch>> for App {
|
||||||
|
fn from(machine: AppMachine<AppFetch>) -> Self {
|
||||||
|
AppState::Fetch(machine)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> From<&'a mut AppMachine<AppFetch>> for AppPublic<'a> {
|
||||||
|
fn from(machine: &'a mut AppMachine<AppFetch>) -> Self {
|
||||||
|
AppPublic {
|
||||||
|
inner: (&mut machine.inner).into(),
|
||||||
|
state: AppState::Fetch(()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IAppInteractFetch for AppMachine<AppFetch> {
|
||||||
|
type APP = App;
|
||||||
|
|
||||||
|
fn abort(self) -> Self::APP {
|
||||||
|
AppMachine::browse(self.inner).into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn no_op(self) -> Self::APP {
|
||||||
|
self.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IAppEventFetch for AppMachine<AppFetch> {
|
||||||
|
type APP = App;
|
||||||
|
|
||||||
|
fn fetch_result_ready(self) -> Self::APP {
|
||||||
|
Self::app_fetch_next(self.inner, self.state, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
|
||||||
|
// use std::sync::mpsc;
|
||||||
|
|
||||||
|
// use musichoard::collection::{
|
||||||
|
// album::{AlbumDate, AlbumId, AlbumMeta, AlbumPrimaryType, AlbumSecondaryType},
|
||||||
|
// artist::{ArtistId, ArtistMeta},
|
||||||
|
// };
|
||||||
|
|
||||||
|
// use crate::tui::{
|
||||||
|
// app::{
|
||||||
|
// machine::tests::{inner, music_hoard},
|
||||||
|
// IAppAccess,
|
||||||
|
// },
|
||||||
|
// lib::interface::musicbrainz::Match,
|
||||||
|
// };
|
||||||
|
|
||||||
|
// use super::*;
|
||||||
|
|
||||||
|
// impl<T> Match<T> {
|
||||||
|
// pub fn new(score: u8, item: T) -> Self {
|
||||||
|
// Match {
|
||||||
|
// score,
|
||||||
|
// item,
|
||||||
|
// disambiguation: None,
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// fn artist_matches_info_vec() -> Vec<AppMatchesInfo> {
|
||||||
|
// let artist_1 = ArtistMeta::new(ArtistId::new("Artist 1"));
|
||||||
|
|
||||||
|
// let artist_1_1 = artist_1.clone();
|
||||||
|
// let artist_match_1_1 = Match::new(100, artist_1_1);
|
||||||
|
|
||||||
|
// let artist_1_2 = artist_1.clone();
|
||||||
|
// let mut artist_match_1_2 = Match::new(100, artist_1_2);
|
||||||
|
// artist_match_1_2.disambiguation = Some(String::from("some disambiguation"));
|
||||||
|
|
||||||
|
// let list = vec![artist_match_1_1.clone(), artist_match_1_2.clone()];
|
||||||
|
// let matches_info_1 = AppMatchesInfo::artist(artist_1.clone(), list);
|
||||||
|
|
||||||
|
// let artist_2 = ArtistMeta::new(ArtistId::new("Artist 2"));
|
||||||
|
|
||||||
|
// let artist_2_1 = artist_1.clone();
|
||||||
|
// let album_match_2_1 = Match::new(100, artist_2_1);
|
||||||
|
|
||||||
|
// let list = vec![album_match_2_1.clone()];
|
||||||
|
// let matches_info_2 = AppMatchesInfo::artist(artist_2.clone(), list);
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
@ -51,14 +51,11 @@ pub struct AppMatches {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AppMatches {
|
impl AppMatches {
|
||||||
pub fn empty(fetch: AppFetch) -> Self {
|
pub fn new(mut current: Option<AppMatchesInfo>, fetch: AppFetch) -> Self {
|
||||||
Self::new(None, fetch)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new(current: Option<AppMatchesInfo>, fetch: AppFetch) -> Self {
|
|
||||||
let mut state = WidgetState::default();
|
let mut state = WidgetState::default();
|
||||||
if current.is_some() {
|
if let Some(ref mut current) = current {
|
||||||
state.list.select(Some(0));
|
state.list.select(Some(0));
|
||||||
|
current.push_cannot_have_mbid();
|
||||||
}
|
}
|
||||||
AppMatches {
|
AppMatches {
|
||||||
current,
|
current,
|
||||||
@ -160,209 +157,169 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn artist_matches_info_vec() -> Vec<AppMatchesInfo> {
|
fn artist_match() -> AppMatchesInfo {
|
||||||
let artist_1 = ArtistMeta::new(ArtistId::new("Artist 1"));
|
let artist = ArtistMeta::new(ArtistId::new("Artist"));
|
||||||
|
|
||||||
let artist_1_1 = artist_1.clone();
|
let artist_1 = artist.clone();
|
||||||
let artist_match_1_1 = Match::new(100, artist_1_1);
|
let artist_match_1 = Match::new(100, artist_1);
|
||||||
|
|
||||||
let artist_1_2 = artist_1.clone();
|
let artist_2 = artist.clone();
|
||||||
let mut artist_match_1_2 = Match::new(100, artist_1_2);
|
let mut artist_match_2 = Match::new(100, artist_2);
|
||||||
artist_match_1_2.disambiguation = Some(String::from("some disambiguation"));
|
artist_match_2.disambiguation = Some(String::from("some disambiguation"));
|
||||||
|
|
||||||
let list = vec![artist_match_1_1.clone(), artist_match_1_2.clone()];
|
let list = vec![artist_match_1.clone(), artist_match_2.clone()];
|
||||||
let matches_info_1 = AppMatchesInfo::artist(artist_1.clone(), list);
|
AppMatchesInfo::artist(artist, list)
|
||||||
|
|
||||||
let artist_2 = ArtistMeta::new(ArtistId::new("Artist 2"));
|
|
||||||
|
|
||||||
let artist_2_1 = artist_1.clone();
|
|
||||||
let album_match_2_1 = Match::new(100, artist_2_1);
|
|
||||||
|
|
||||||
let list = vec![album_match_2_1.clone()];
|
|
||||||
let matches_info_2 = AppMatchesInfo::artist(artist_2.clone(), list);
|
|
||||||
|
|
||||||
vec![matches_info_1, matches_info_2]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn album_matches_info_vec() -> Vec<AppMatchesInfo> {
|
fn album_match() -> AppMatchesInfo {
|
||||||
let album_1 = AlbumMeta::new(
|
let album = AlbumMeta::new(
|
||||||
AlbumId::new("Album 1"),
|
AlbumId::new("Album"),
|
||||||
AlbumDate::new(Some(1990), Some(5), None),
|
AlbumDate::new(Some(1990), Some(5), None),
|
||||||
Some(AlbumPrimaryType::Album),
|
Some(AlbumPrimaryType::Album),
|
||||||
vec![AlbumSecondaryType::Live, AlbumSecondaryType::Compilation],
|
vec![AlbumSecondaryType::Live, AlbumSecondaryType::Compilation],
|
||||||
);
|
);
|
||||||
|
|
||||||
let album_1_1 = album_1.clone();
|
let album_1 = album.clone();
|
||||||
let album_match_1_1 = Match::new(100, album_1_1);
|
let album_match_1 = Match::new(100, album_1);
|
||||||
|
|
||||||
let mut album_1_2 = album_1.clone();
|
let mut album_2 = album.clone();
|
||||||
album_1_2.id.title.push_str(" extra title part");
|
album_2.id.title.push_str(" extra title part");
|
||||||
album_1_2.secondary_types.pop();
|
album_2.secondary_types.pop();
|
||||||
let album_match_1_2 = Match::new(100, album_1_2);
|
let album_match_2 = Match::new(100, album_2);
|
||||||
|
|
||||||
let list = vec![album_match_1_1.clone(), album_match_1_2.clone()];
|
let list = vec![album_match_1.clone(), album_match_2.clone()];
|
||||||
let matches_info_1 = AppMatchesInfo::album(album_1.clone(), list);
|
AppMatchesInfo::album(album, 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 {
|
fn fetch() -> AppFetch {
|
||||||
// let (tx, rx) = mpsc::channel();
|
let (_, rx) = mpsc::channel();
|
||||||
// for matches_info in matches_info_vec.into_iter() {
|
AppFetch::new(rx)
|
||||||
// tx.send(Ok(matches_info)).unwrap();
|
}
|
||||||
// }
|
|
||||||
// rx
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn push_cannot_have_mbid(matches_info_vec: &mut [AppMatchesInfo]) {
|
fn matches(matches_info: Option<AppMatchesInfo>) -> AppMatches {
|
||||||
// for matches_info in matches_info_vec.iter_mut() {
|
AppMatches::new(matches_info, fetch())
|
||||||
// matches_info.push_cannot_have_mbid();
|
}
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn create_empty() {
|
fn create_empty() {
|
||||||
// let matches =
|
let matches = AppMachine::matches(inner(music_hoard(vec![])), matches(None));
|
||||||
// AppMachine::app_matches(inner(music_hoard(vec![])), receiver(vec![])).unwrap_matches();
|
|
||||||
|
|
||||||
// let widget_state = WidgetState::default();
|
let widget_state = WidgetState::default();
|
||||||
|
|
||||||
// assert_eq!(matches.state.current, None);
|
assert_eq!(matches.state.current, None);
|
||||||
// assert_eq!(matches.state.state, widget_state);
|
assert_eq!(matches.state.state, widget_state);
|
||||||
|
|
||||||
// let mut app = matches.no_op();
|
let mut app = matches.no_op();
|
||||||
// let public = app.get();
|
let public = app.get();
|
||||||
// let public_matches = public.state.unwrap_matches();
|
let public_matches = public.state.unwrap_matches();
|
||||||
|
|
||||||
// assert_eq!(public_matches.matches, None);
|
assert_eq!(public_matches.matches, None);
|
||||||
// assert_eq!(public_matches.state, &widget_state);
|
assert_eq!(public_matches.state, &widget_state);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn create_nonempty() {
|
fn create_nonempty() {
|
||||||
// let mut matches_info_vec = album_matches_info_vec();
|
let mut album_match = album_match();
|
||||||
// let matches = AppMachine::app_matches(
|
let matches = AppMachine::matches(
|
||||||
// inner(music_hoard(vec![])),
|
inner(music_hoard(vec![])),
|
||||||
// receiver(matches_info_vec.clone()),
|
matches(Some(album_match.clone())),
|
||||||
// )
|
);
|
||||||
// .unwrap_matches();
|
album_match.push_cannot_have_mbid();
|
||||||
// push_cannot_have_mbid(&mut matches_info_vec);
|
|
||||||
|
|
||||||
// let mut widget_state = WidgetState::default();
|
let mut widget_state = WidgetState::default();
|
||||||
// widget_state.list.select(Some(0));
|
widget_state.list.select(Some(0));
|
||||||
|
|
||||||
// assert_eq!(matches.state.current.as_ref(), Some(&matches_info_vec[0]));
|
assert_eq!(matches.state.current.as_ref(), Some(&album_match));
|
||||||
// assert_eq!(matches.state.state, widget_state);
|
assert_eq!(matches.state.state, widget_state);
|
||||||
|
|
||||||
// let mut app = matches.no_op();
|
let mut app = matches.no_op();
|
||||||
// let public = app.get();
|
let public = app.get();
|
||||||
// let public_matches = public.state.unwrap_matches();
|
let public_matches = public.state.unwrap_matches();
|
||||||
|
|
||||||
// assert_eq!(public_matches.matches, Some(&matches_info_vec[0]));
|
assert_eq!(public_matches.matches, Some(&album_match));
|
||||||
// assert_eq!(public_matches.state, &widget_state);
|
assert_eq!(public_matches.state, &widget_state);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// fn matches_flow(mut matches_info_vec: Vec<AppMatchesInfo>) {
|
fn matches_flow(mut matches_info: AppMatchesInfo) {
|
||||||
// let matches = AppMachine::app_matches(
|
// tx must exist for rx to return Empty rather than Disconnected.
|
||||||
// inner(music_hoard(vec![])),
|
#[allow(unused_variables)]
|
||||||
// receiver(matches_info_vec.clone()),
|
let (tx, rx) = mpsc::channel();
|
||||||
// )
|
let app_matches = AppMatches::new(Some(matches_info.clone()), AppFetch::new(rx));
|
||||||
// .unwrap_matches();
|
|
||||||
// push_cannot_have_mbid(&mut matches_info_vec);
|
|
||||||
|
|
||||||
// let mut widget_state = WidgetState::default();
|
let matches = AppMachine::matches(inner(music_hoard(vec![])), app_matches);
|
||||||
// widget_state.list.select(Some(0));
|
matches_info.push_cannot_have_mbid();
|
||||||
|
|
||||||
// assert_eq!(matches.state.current.as_ref(), Some(&matches_info_vec[0]));
|
let mut widget_state = WidgetState::default();
|
||||||
// assert_eq!(matches.state.state, widget_state);
|
widget_state.list.select(Some(0));
|
||||||
|
|
||||||
// let matches = matches.prev_match().unwrap_matches();
|
assert_eq!(matches.state.current.as_ref(), Some(&matches_info));
|
||||||
|
assert_eq!(matches.state.state, widget_state);
|
||||||
|
|
||||||
// assert_eq!(matches.state.current.as_ref(), Some(&matches_info_vec[0]));
|
let matches = matches.prev_match().unwrap_matches();
|
||||||
// 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));
|
||||||
|
assert_eq!(matches.state.state.list.selected(), Some(0));
|
||||||
|
|
||||||
// assert_eq!(matches.state.current.as_ref(), Some(&matches_info_vec[0]));
|
let matches = matches.next_match().unwrap_matches();
|
||||||
// assert_eq!(matches.state.state.list.selected(), Some(1));
|
|
||||||
|
|
||||||
// // Next is CannotHaveMBID
|
assert_eq!(matches.state.current.as_ref(), Some(&matches_info));
|
||||||
// let matches = matches.next_match().unwrap_matches();
|
assert_eq!(matches.state.state.list.selected(), Some(1));
|
||||||
|
|
||||||
// assert_eq!(matches.state.current.as_ref(), Some(&matches_info_vec[0]));
|
// Next is CannotHaveMBID
|
||||||
// assert_eq!(matches.state.state.list.selected(), Some(2));
|
let matches = matches.next_match().unwrap_matches();
|
||||||
|
|
||||||
// let matches = matches.next_match().unwrap_matches();
|
assert_eq!(matches.state.current.as_ref(), Some(&matches_info));
|
||||||
|
assert_eq!(matches.state.state.list.selected(), Some(2));
|
||||||
|
|
||||||
// assert_eq!(matches.state.current.as_ref(), Some(&matches_info_vec[0]));
|
let matches = matches.next_match().unwrap_matches();
|
||||||
// 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));
|
||||||
|
assert_eq!(matches.state.state.list.selected(), Some(2));
|
||||||
|
|
||||||
// assert_eq!(matches.state.current.as_ref(), Some(&matches_info_vec[1]));
|
// And it's done
|
||||||
// assert_eq!(matches.state.state.list.selected(), Some(0));
|
matches.select().unwrap_fetch();
|
||||||
|
}
|
||||||
|
|
||||||
// // And it's done
|
#[test]
|
||||||
// matches.select().unwrap_browse();
|
fn artist_matches_flow() {
|
||||||
// }
|
matches_flow(artist_match());
|
||||||
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn artist_matches_flow() {
|
fn album_matches_flow() {
|
||||||
// matches_flow(artist_matches_info_vec());
|
matches_flow(album_match());
|
||||||
// }
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn album_matches_flow() {
|
fn matches_abort() {
|
||||||
// matches_flow(album_matches_info_vec());
|
let mut album_match = album_match();
|
||||||
// }
|
let matches = AppMachine::matches(
|
||||||
|
inner(music_hoard(vec![])),
|
||||||
|
matches(Some(album_match.clone())),
|
||||||
|
);
|
||||||
|
album_match.push_cannot_have_mbid();
|
||||||
|
|
||||||
// #[test]
|
let mut widget_state = WidgetState::default();
|
||||||
// fn matches_abort() {
|
widget_state.list.select(Some(0));
|
||||||
// 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();
|
assert_eq!(matches.state.current.as_ref(), Some(&album_match));
|
||||||
// widget_state.list.select(Some(0));
|
assert_eq!(matches.state.state, widget_state);
|
||||||
|
|
||||||
// assert_eq!(matches.state.current.as_ref(), Some(&matches_info_vec[0]));
|
matches.abort().unwrap_browse();
|
||||||
// assert_eq!(matches.state.state, widget_state);
|
}
|
||||||
|
|
||||||
// matches.abort().unwrap_browse();
|
#[test]
|
||||||
// }
|
fn matches_select_empty() {
|
||||||
|
// Note that what really matters in this test is actually that the transmit channel has
|
||||||
|
// disconnected and so the receive within AppFetch concludes there are no more matches.
|
||||||
|
let matches = AppMachine::matches(inner(music_hoard(vec![])), matches(None));
|
||||||
|
matches.select().unwrap_browse();
|
||||||
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn matches_select_empty() {
|
fn no_op() {
|
||||||
// let matches =
|
let matches = AppMachine::matches(inner(music_hoard(vec![])), matches(None));
|
||||||
// AppMachine::app_matches(inner(music_hoard(vec![])), receiver(vec![])).unwrap_matches();
|
let app = matches.no_op();
|
||||||
|
app.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