Compare commits

...

2 Commits

Author SHA1 Message Date
cb09f47eb2 Ui unit tests
Some checks failed
Cargo CI / Build and Test (pull_request) Failing after 2m1s
Cargo CI / Lint (pull_request) Successful in 1m7s
2024-09-15 11:00:12 +02:00
dd3633cd5f Don't use super:: imports 2024-09-15 10:56:28 +02:00
9 changed files with 35 additions and 27 deletions

View File

@ -5,13 +5,14 @@ pub mod backend;
#[cfg(test)]
use mockall::automock;
use crate::core::{
collection::Collection,
interface::database::{IDatabase, LoadError, SaveError},
use crate::{
core::{
collection::Collection,
interface::database::{IDatabase, LoadError, SaveError},
},
external::database::serde::{deserialize::DeserializeDatabase, serialize::SerializeDatabase},
};
use super::serde::{deserialize::DeserializeDatabase, serialize::SerializeDatabase};
impl From<serde_json::Error> for LoadError {
fn from(err: serde_json::Error) -> LoadError {
LoadError::SerDeError(err.to_string())

View File

@ -4,11 +4,12 @@ use serde::Deserialize;
use crate::{
collection::{artist::ArtistId, musicbrainz::Mbid},
external::musicbrainz::api::SerdeMbid,
external::musicbrainz::api::{
search::query::{impl_term, EmptyQuery, EmptyQueryJoin, Query, QueryJoin},
SerdeMbid,
},
};
use super::query::{impl_term, EmptyQuery, EmptyQueryJoin, Query, QueryJoin};
pub enum SearchArtist<'a> {
String(&'a str),
}

View File

@ -8,12 +8,11 @@ use crate::{
musicbrainz::Mbid,
},
external::musicbrainz::api::{
search::query::{impl_term, EmptyQuery, EmptyQueryJoin, Query, QueryJoin},
ApiDisplay, SerdeAlbumDate, SerdeAlbumPrimaryType, SerdeAlbumSecondaryType, SerdeMbid,
},
};
use super::query::{impl_term, EmptyQuery, EmptyQueryJoin, Query, QueryJoin};
pub enum SearchReleaseGroup<'a> {
String(&'a str),
Arid(&'a Mbid),

View File

@ -14,15 +14,13 @@ use musichoard::collection::{
use crate::tui::{
app::{
machine::{App, AppInner, AppMachine},
machine::{match_state::MatchState, App, AppInner, AppMachine},
AppPublicState, AppState, IAppEventFetch, IAppInteractFetch, MatchStateInfo,
},
event::{Event, EventSender},
lib::interface::musicbrainz::{self, Error as MbError, IMusicBrainz},
};
use super::match_state::MatchState;
pub struct FetchState {
fetch_rx: FetchReceiver,
}

View File

@ -1,13 +1,11 @@
use std::cmp;
use crate::tui::app::{
machine::{App, AppInner, AppMachine},
machine::{fetch_state::FetchState, input::Input, App, AppInner, AppMachine},
AlbumMatches, AppPublicState, AppState, ArtistMatches, IAppInteractMatch, MatchOption,
MatchStateInfo, MatchStatePublic, WidgetState,
};
use super::{fetch_state::FetchState, input::Input};
impl ArtistMatches {
fn len(&self) -> usize {
self.list.len()

View File

@ -11,7 +11,10 @@ mod search_state;
use std::sync::{Arc, Mutex};
use crate::tui::{
app::{selection::Selection, AppPublic, AppPublicInner, AppState, IApp, IAppAccess},
app::{
selection::Selection, AppMode, AppPublic, AppPublicInner, AppPublicState, AppState, IApp,
IAppAccess, IAppBase, IAppState,
},
event::EventSender,
lib::{interface::musicbrainz::IMusicBrainz, IMusicHoard},
};
@ -26,8 +29,6 @@ use match_state::MatchState;
use reload_state::ReloadState;
use search_state::SearchState;
use super::{AppMode, AppPublicState, IAppBase, IAppState};
pub type App = AppState<
AppMachine<BrowseState>,
AppMachine<InfoState>,

View File

@ -5,14 +5,13 @@ use mockall::automock;
use crate::tui::{
app::{
AppState, Delta, IApp, IAppInteractBrowse, IAppInteractError, IAppInteractFetch,
IAppInteractInfo, IAppInteractMatch, IAppInteractReload, IAppInteractSearch,
AppMode, AppState, Delta, IApp, IAppBase, IAppEventFetch, IAppInput, IAppInteractBrowse,
IAppInteractError, IAppInteractFetch, IAppInteractInfo, IAppInteractMatch,
IAppInteractReload, IAppInteractSearch,
},
event::{Event, EventError, EventReceiver},
};
use super::app::{AppMode, IAppBase, IAppEventFetch, IAppInput};
#[cfg_attr(test, automock)]
pub trait IEventHandler<APP: IApp> {
fn handle_next_event(&self, app: APP) -> Result<APP, EventError>;

View File

@ -4,7 +4,7 @@ use std::thread;
#[cfg(test)]
use mockall::automock;
use super::event::{Event, EventError, EventSender};
use crate::tui::event::{Event, EventError, EventSender};
#[cfg_attr(test, automock)]
pub trait IEventListener {

View File

@ -17,7 +17,10 @@ use ratatui::{layout::Rect, widgets::Paragraph, Frame};
use musichoard::collection::{album::Album, Collection};
use crate::tui::{
app::{AppPublicState, AppState, Category, IAppAccess, MatchStateInfo, Selection, WidgetState},
app::{
AppPublicState, AppState, Category, IAppAccess, InputPublic, MatchStateInfo, Selection,
WidgetState,
},
ui::{
browse_state::{
AlbumArea, AlbumState, ArtistArea, ArtistState, FrameArea, TrackArea, TrackState,
@ -35,8 +38,6 @@ use crate::tui::{
},
};
use super::app::InputPublic;
pub trait IUi {
fn render<APP: IAppAccess>(app: &mut APP, frame: &mut Frame);
}
@ -252,12 +253,14 @@ mod tests {
fn artist_matches(matching: ArtistMeta, list: Vec<Match<ArtistMeta>>) -> MatchStateInfo {
let mut list: Vec<MatchOption<ArtistMeta>> = list.into_iter().map(Into::into).collect();
list.push(MatchOption::CannotHaveMbid);
list.push(MatchOption::ManualInputMbid);
MatchStateInfo::artist(matching, list)
}
fn album_matches(matching: AlbumMeta, list: Vec<Match<AlbumMeta>>) -> MatchStateInfo {
let mut list: Vec<MatchOption<AlbumMeta>> = list.into_iter().map(Into::into).collect();
list.push(MatchOption::CannotHaveMbid);
list.push(MatchOption::ManualInputMbid);
MatchStateInfo::album(matching, list)
}
@ -379,6 +382,10 @@ mod tests {
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]
@ -414,5 +421,9 @@ mod tests {
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();
}
}