From 8c8e6971c54b7aebc6768eb6633515c1a72e6a2d Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Fri, 19 May 2023 22:19:31 +0200 Subject: [PATCH] Test new UI methods --- src/tui/event.rs | 5 +++++ src/tui/ui.rs | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/tui/event.rs b/src/tui/event.rs index bae2541..a99d610 100644 --- a/src/tui/event.rs +++ b/src/tui/event.rs @@ -102,6 +102,8 @@ mod tests { use crossterm::event::{KeyCode, KeyEvent, KeyEventKind, KeyEventState, KeyModifiers}; + use crate::tui::ui::UiError; + use super::{Event, EventChannel, EventError}; #[test] @@ -145,13 +147,16 @@ mod tests { })); let recv_err = EventError::Recv; let io_err = EventError::Io(io::Error::new(io::ErrorKind::Interrupted, "interrupted")); + let ui_err: EventError = UiError::Lib(String::from("lib error")).into(); assert!(!send_err.to_string().is_empty()); assert!(!recv_err.to_string().is_empty()); assert!(!io_err.to_string().is_empty()); + assert!(!ui_err.to_string().is_empty()); assert!(!format!("{:?}", send_err).is_empty()); assert!(!format!("{:?}", recv_err).is_empty()); assert!(!format!("{:?}", io_err).is_empty()); + assert!(!format!("{:?}", ui_err).is_empty()); } } diff --git a/src/tui/ui.rs b/src/tui/ui.rs index 6cd7536..2827147 100644 --- a/src/tui/ui.rs +++ b/src/tui/ui.rs @@ -809,6 +809,21 @@ mod tests { assert!(!ui.is_running()); } + #[test] + fn ui_save() { + let mut music_hoard = music_hoard(COLLECTION.to_owned()); + + music_hoard + .expect_save_to_database() + .times(1) + .return_once(|| Ok(())); + + let mut ui = Ui::new(music_hoard).unwrap(); + + let result = ui.save(); + assert!(result.is_ok()); + } + #[test] fn ui_modifiers() { let mut ui = Ui::new(music_hoard(COLLECTION.to_owned())).unwrap(); @@ -1044,4 +1059,13 @@ mod tests { terminal.draw(|frame| ui.render(frame)).unwrap(); } + + #[test] + fn errors() { + let ui_err: UiError = musichoard::Error::DatabaseError(String::from("get rekt")).into(); + + assert!(!ui_err.to_string().is_empty()); + + assert!(!format!("{:?}", ui_err).is_empty()); + } }