From e23c99ed628eea73d6da35a26be06ca17e5acfc5 Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Sun, 21 May 2023 22:47:36 +0200 Subject: [PATCH] Unit test --- src/tui/ui.rs | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/tui/ui.rs b/src/tui/ui.rs index f996ec9..3c8d26b 100644 --- a/src/tui/ui.rs +++ b/src/tui/ui.rs @@ -414,8 +414,8 @@ impl<'a> ArtistOverlay<'a> { } fn opt_vec_to_string(opt_vec: Option<&Vec>, indent: &str) -> String { - match opt_vec { - Some(vec) => { + opt_vec + .map(|vec| { if vec.len() < 2 { vec.get(0).map(|item| item.url()).unwrap_or("").to_string() } else { @@ -427,9 +427,8 @@ impl<'a> ArtistOverlay<'a> { .join(&indent); format!("{indent}{list}") } - } - None => String::from(""), - } + }) + .unwrap_or_else(|| String::from("")) } fn new(artists: &'a [Artist], state: &ListState) -> ArtistOverlay<'a> { @@ -686,7 +685,7 @@ impl Ui { let artists = self.music_hoard.get_collection(); let artist_selection = &mut self.selection.artist; - let artist_overlay = ArtistOverlay::new(&artists, &artist_selection.state); + let artist_overlay = ArtistOverlay::new(artists, &artist_selection.state); Self::render_overlay_widget("Artist", artist_overlay.properties, areas.artist, frame); } } @@ -1171,6 +1170,27 @@ mod tests { terminal.draw(|frame| ui.render(frame)).unwrap(); } + #[test] + fn overlay() { + let mut terminal = terminal(); + let mut ui = ui(COLLECTION.to_owned()); + + terminal.draw(|frame| ui.render(frame)).unwrap(); + + ui.toggle_overlay(); + + terminal.draw(|frame| ui.render(frame)).unwrap(); + + // Change the artist (which has a multi-link entry). + ui.increment_selection(); + + terminal.draw(|frame| ui.render(frame)).unwrap(); + + ui.toggle_overlay(); + + terminal.draw(|frame| ui.render(frame)).unwrap(); + } + #[test] fn errors() { let ui_err: UiError = musichoard::Error::DatabaseError(String::from("get rekt")).into();