Fix unit tests

This commit is contained in:
Wojciech Kozlowski 2023-05-19 21:48:09 +02:00
parent e2dd53845f
commit 11bcb8bdb9
2 changed files with 28 additions and 50 deletions

View File

@ -180,13 +180,18 @@ mod tests {
Terminal::new(backend).unwrap()
}
pub fn ui(collection: Collection) -> Ui<MockIMusicHoard> {
pub fn music_hoard(collection: Collection) -> MockIMusicHoard {
let mut music_hoard = MockIMusicHoard::new();
music_hoard.expect_load_from_database().returning(|| Ok(()));
music_hoard.expect_rescan_library().returning(|| Ok(()));
music_hoard.expect_get_collection().return_const(collection);
Ui::new(music_hoard).unwrap()
music_hoard
}
pub fn ui(collection: Collection) -> Ui<MockIMusicHoard> {
Ui::new(music_hoard(collection)).unwrap()
}
fn listener() -> MockIEventListener {

View File

@ -632,6 +632,22 @@ mod tests {
use super::*;
pub fn music_hoard(collection: Collection) -> MockIMusicHoard {
let mut music_hoard = MockIMusicHoard::new();
music_hoard
.expect_load_from_database()
.times(1)
.return_once(|| Ok(()));
music_hoard
.expect_rescan_library()
.times(1)
.return_once(|| Ok(()));
music_hoard.expect_get_collection().return_const(collection);
music_hoard
}
#[test]
fn test_track_selection() {
let tracks = &COLLECTION[0].albums[0].tracks;
@ -786,17 +802,7 @@ mod tests {
#[test]
fn ui_running() {
let mut music_hoard = MockIMusicHoard::new();
music_hoard
.expect_rescan_library()
.times(1)
.return_once(|| Ok(()));
music_hoard
.expect_get_collection()
.return_const(COLLECTION.to_owned());
let mut ui = Ui::new(music_hoard).unwrap();
let mut ui = Ui::new(music_hoard(COLLECTION.to_owned())).unwrap();
assert!(ui.is_running());
ui.quit();
@ -805,17 +811,7 @@ mod tests {
#[test]
fn ui_modifiers() {
let mut music_hoard = MockIMusicHoard::new();
music_hoard
.expect_rescan_library()
.times(1)
.return_once(|| Ok(()));
music_hoard
.expect_get_collection()
.return_const(COLLECTION.to_owned());
let mut ui = Ui::new(music_hoard).unwrap();
let mut ui = Ui::new(music_hoard(COLLECTION.to_owned())).unwrap();
assert!(ui.is_running());
assert_eq!(ui.selection.active, Category::Artist);
@ -904,17 +900,10 @@ mod tests {
#[test]
fn app_no_tracks() {
let mut music_hoard = MockIMusicHoard::new();
let mut collection = COLLECTION.to_owned();
collection[0].albums[0].tracks = vec![];
music_hoard
.expect_rescan_library()
.times(1)
.return_once(|| Ok(()));
music_hoard.expect_get_collection().return_const(collection);
let mut app = Ui::new(music_hoard).unwrap();
let mut app = Ui::new(music_hoard(collection)).unwrap();
assert!(app.is_running());
assert_eq!(app.selection.active, Category::Artist);
@ -940,17 +929,10 @@ mod tests {
#[test]
fn app_no_albums() {
let mut music_hoard = MockIMusicHoard::new();
let mut collection = COLLECTION.to_owned();
collection[0].albums = vec![];
music_hoard
.expect_rescan_library()
.times(1)
.return_once(|| Ok(()));
music_hoard.expect_get_collection().return_const(collection);
let mut app = Ui::new(music_hoard).unwrap();
let mut app = Ui::new(music_hoard(collection)).unwrap();
assert!(app.is_running());
assert_eq!(app.selection.active, Category::Artist);
@ -989,16 +971,7 @@ mod tests {
#[test]
fn app_no_artists() {
let mut music_hoard = MockIMusicHoard::new();
let collection = vec![];
music_hoard
.expect_rescan_library()
.times(1)
.return_once(|| Ok(()));
music_hoard.expect_get_collection().return_const(collection);
let mut app = Ui::new(music_hoard).unwrap();
let mut app = Ui::new(music_hoard(vec![])).unwrap();
assert!(app.is_running());
assert_eq!(app.selection.active, Category::Artist);