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();