Finish UTs
All checks were successful
Cargo CI / Build and Test (pull_request) Successful in 2m47s
Cargo CI / Lint (pull_request) Successful in 1m6s

This commit is contained in:
Wojciech Kozlowski 2024-09-23 22:36:18 +02:00
parent 6a9919fac9
commit 780e6b8350
2 changed files with 80 additions and 78 deletions

View File

@ -86,14 +86,14 @@ impl MatchStateInfo {
} }
} }
fn push_cannot_have_mbid(&mut self) { pub fn push_cannot_have_mbid(&mut self) {
match self { match self {
Self::Artist(a) => a.push_cannot_have_mbid(), Self::Artist(a) => a.push_cannot_have_mbid(),
Self::Album(a) => a.push_cannot_have_mbid(), Self::Album(a) => a.push_cannot_have_mbid(),
} }
} }
fn push_manual_input_mbid(&mut self) { pub fn push_manual_input_mbid(&mut self) {
match self { match self {
Self::Artist(a) => a.push_manual_input_mbid(), Self::Artist(a) => a.push_manual_input_mbid(),
Self::Album(a) => a.push_manual_input_mbid(), Self::Album(a) => a.push_manual_input_mbid(),
@ -518,7 +518,7 @@ mod tests {
#[test] #[test]
fn select_manual_input_album() { fn select_manual_input_album() {
let mut mb_job_sender = MockIMbJobSender::new(); let mut mb_job_sender = MockIMbJobSender::new();
let album = AlbumMeta::new("Album", 1990u32, None, vec![]); let album = AlbumMeta::new("Album", 1990, None, vec![]);
let requests = VecDeque::from([MbParams::lookup_release_group(album.clone(), mbid())]); let requests = VecDeque::from([MbParams::lookup_release_group(album.clone(), mbid())]);
mb_job_sender mb_job_sender
.expect_submit_foreground_job() .expect_submit_foreground_job()

View File

@ -206,8 +206,8 @@ mod tests {
}; };
use crate::tui::{ use crate::tui::{
app::{AppPublic, AppPublicInner, Delta, MatchStatePublic, MissOption, SearchOption}, app::{AppPublic, AppPublicInner, Delta, MatchStatePublic},
lib::interface::musicbrainz::api::Match, lib::interface::musicbrainz::api::{Lookup, Match},
testmod::COLLECTION, testmod::COLLECTION,
tests::terminal, tests::terminal,
}; };
@ -250,20 +250,6 @@ mod tests {
} }
} }
fn artist_matches(matching: ArtistMeta, list: Vec<Match<ArtistMeta>>) -> MatchStateInfo {
let mut list: Vec<SearchOption<ArtistMeta>> = list.into_iter().map(Into::into).collect();
list.push(SearchOption::None(MissOption::CannotHaveMbid));
list.push(SearchOption::None(MissOption::ManualInputMbid));
MatchStateInfo::artist_search(matching, list)
}
fn album_matches(matching: AlbumMeta, list: Vec<Match<AlbumMeta>>) -> MatchStateInfo {
let mut list: Vec<SearchOption<AlbumMeta>> = list.into_iter().map(Into::into).collect();
list.push(SearchOption::None(MissOption::CannotHaveMbid));
list.push(SearchOption::None(MissOption::ManualInputMbid));
MatchStateInfo::album_search(matching, list)
}
fn draw_test_suite(collection: &Collection, selection: &mut Selection) { fn draw_test_suite(collection: &Collection, selection: &mut Selection) {
let mut terminal = terminal(); let mut terminal = terminal();
@ -354,76 +340,92 @@ mod tests {
terminal.draw(|frame| Ui::render(&mut app, frame)).unwrap(); terminal.draw(|frame| Ui::render(&mut app, frame)).unwrap();
} }
#[test] fn artist_meta() -> ArtistMeta {
fn draw_artist_matches() { ArtistMeta::new(ArtistId::new("an artist"))
let collection = &COLLECTION;
let mut selection = Selection::new(collection);
let mut terminal = terminal();
let artist = ArtistMeta::new(ArtistId::new("an artist"));
let artist_match = Match {
score: 80,
item: artist.clone(),
disambiguation: None,
};
let list = vec![artist_match.clone(), artist_match.clone()];
let artist_matches = artist_matches(artist, list);
let mut widget_state = WidgetState::default();
widget_state.list.select(Some(0));
let mut app = AppPublic {
inner: public_inner(collection, &mut selection),
state: AppState::Match(MatchStatePublic {
info: Some(&artist_matches),
state: &mut widget_state,
}),
input: None,
};
terminal.draw(|frame| Ui::render(&mut app, frame)).unwrap();
let input = tui_input::Input::default();
app.input = Some(&input);
terminal.draw(|frame| Ui::render(&mut app, frame)).unwrap();
} }
#[test] fn artist_matches() -> MatchStateInfo {
fn draw_album_matches() { let artist = artist_meta();
let collection = &COLLECTION; let artist_match = Match::new(80, artist.clone());
let mut selection = Selection::new(collection); let list = vec![artist_match.clone(), artist_match.clone()];
let mut terminal = terminal(); let mut info = MatchStateInfo::artist_search(artist, list);
info.push_cannot_have_mbid();
info.push_manual_input_mbid();
info
}
let album = AlbumMeta::new( fn artist_lookup() -> MatchStateInfo {
let artist = artist_meta();
let artist_lookup = Lookup::new(artist.clone());
let mut info = MatchStateInfo::artist_lookup(artist, artist_lookup);
info.push_cannot_have_mbid();
info.push_manual_input_mbid();
info
}
fn album_meta() -> AlbumMeta {
AlbumMeta::new(
AlbumId::new("An Album"), AlbumId::new("An 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_match = Match { }
score: 80,
item: album.clone(), fn album_matches() -> MatchStateInfo {
disambiguation: None, let album = album_meta();
}; let album_match = Match::new(80, album.clone());
let list = vec![album_match.clone(), album_match.clone()]; let list = vec![album_match.clone(), album_match.clone()];
let album_matches = album_matches(album, list);
let mut widget_state = WidgetState::default(); let mut info = MatchStateInfo::album_search(album, list);
widget_state.list.select(Some(0)); info.push_cannot_have_mbid();
info.push_manual_input_mbid();
info
}
let mut app = AppPublic { fn album_lookup() -> MatchStateInfo {
inner: public_inner(collection, &mut selection), let album = album_meta();
state: AppState::Match(MatchStatePublic { let album_lookup = Lookup::new(album.clone());
info: Some(&album_matches),
state: &mut widget_state,
}),
input: None,
};
terminal.draw(|frame| Ui::render(&mut app, frame)).unwrap();
let input = tui_input::Input::default(); let mut info = MatchStateInfo::album_lookup(album, album_lookup);
app.input = Some(&input); info.push_cannot_have_mbid();
terminal.draw(|frame| Ui::render(&mut app, frame)).unwrap(); info.push_manual_input_mbid();
info
}
#[test]
fn draw_matche_state_suite() {
let collection = &COLLECTION;
let mut selection = Selection::new(collection);
let mut terminal = terminal();
let match_state_infos = vec![
artist_matches(),
album_matches(),
artist_lookup(),
album_lookup(),
];
for info in match_state_infos.iter() {
let mut widget_state = WidgetState::default();
widget_state.list.select(Some(0));
let mut app = AppPublic {
inner: public_inner(collection, &mut selection),
state: AppState::Match(MatchStatePublic {
info: Some(info),
state: &mut widget_state,
}),
input: None,
};
terminal.draw(|frame| Ui::render(&mut app, frame)).unwrap();
let input = tui_input::Input::default();
app.input = Some(&input);
terminal.draw(|frame| Ui::render(&mut app, frame)).unwrap();
}
} }
} }