Handle idle time between fetch results #212
@ -170,7 +170,8 @@ mod tests {
|
||||
|
||||
use crate::tui::{
|
||||
app::{AppState, IAppInteract, IAppInteractBrowse},
|
||||
lib::{interface::musicbrainz::MockIMusicBrainz, MockIMusicHoard}, EventChannel,
|
||||
lib::{interface::musicbrainz::MockIMusicBrainz, MockIMusicHoard},
|
||||
EventChannel,
|
||||
};
|
||||
|
||||
use super::*;
|
||||
@ -337,24 +338,46 @@ mod tests {
|
||||
assert!(!app.is_running());
|
||||
}
|
||||
|
||||
// #[test]
|
||||
// fn state_matches() {
|
||||
// let mut app = App::new(music_hoard_init(vec![]), mb_api());
|
||||
// assert!(app.is_running());
|
||||
#[test]
|
||||
fn state_fetch() {
|
||||
let mut app = App::new(music_hoard_init(vec![]), mb_api(), events());
|
||||
assert!(app.is_running());
|
||||
|
||||
// let (_, rx) = mpsc::channel();
|
||||
// app = AppMachine::app_matches(app.unwrap_browse().inner, rx);
|
||||
let (_, rx) = mpsc::channel();
|
||||
let inner = app.unwrap_browse().inner;
|
||||
let state = AppFetch::new(rx);
|
||||
app = AppMachine { inner, state }.into();
|
||||
|
||||
// let state = app.state();
|
||||
// assert!(matches!(state, AppState::Matches(_)));
|
||||
// app = state;
|
||||
let state = app.state();
|
||||
assert!(matches!(state, AppState::Fetch(_)));
|
||||
app = state;
|
||||
|
||||
// let public = app.get();
|
||||
// assert!(matches!(public.state, AppState::Matches(_)));
|
||||
let public = app.get();
|
||||
assert!(matches!(public.state, AppState::Fetch(_)));
|
||||
|
||||
// let app = app.force_quit();
|
||||
// assert!(!app.is_running());
|
||||
// }
|
||||
let app = app.force_quit();
|
||||
assert!(!app.is_running());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn state_matches() {
|
||||
let mut app = App::new(music_hoard_init(vec![]), mb_api(), events());
|
||||
assert!(app.is_running());
|
||||
|
||||
let (_, rx) = mpsc::channel();
|
||||
let fetch = AppFetch::new(rx);
|
||||
app = AppMachine::matches(app.unwrap_browse().inner, AppMatches::new(None, fetch)).into();
|
||||
|
||||
let state = app.state();
|
||||
assert!(matches!(state, AppState::Matches(_)));
|
||||
app = state;
|
||||
|
||||
let public = app.get();
|
||||
assert!(matches!(public.state, AppState::Matches(_)));
|
||||
|
||||
let app = app.force_quit();
|
||||
assert!(!app.is_running());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn state_error() {
|
||||
|
9
src/tui/ui/fetch.rs
Normal file
9
src/tui/ui/fetch.rs
Normal file
@ -0,0 +1,9 @@
|
||||
use ratatui::widgets::Paragraph;
|
||||
|
||||
pub struct FetchOverlay;
|
||||
|
||||
impl FetchOverlay {
|
||||
pub fn paragraph<'a>() -> Paragraph<'a> {
|
||||
Paragraph::new(" -- fetching --")
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
mod browse;
|
||||
mod display;
|
||||
mod error;
|
||||
mod fetch;
|
||||
mod info;
|
||||
mod matches;
|
||||
mod minibuffer;
|
||||
@ -9,6 +10,7 @@ mod reload;
|
||||
mod style;
|
||||
mod widgets;
|
||||
|
||||
use fetch::FetchOverlay;
|
||||
use ratatui::{layout::Rect, widgets::Paragraph, Frame};
|
||||
|
||||
use musichoard::collection::{album::Album, Collection};
|
||||
@ -125,21 +127,14 @@ impl Ui {
|
||||
.with_width(OverlaySize::Value(39))
|
||||
.with_height(OverlaySize::Value(4))
|
||||
.build(frame.size());
|
||||
|
||||
let reload_text = ReloadOverlay::paragraph();
|
||||
|
||||
UiWidget::render_overlay_widget("Reload", reload_text, area, false, frame);
|
||||
}
|
||||
|
||||
fn render_fetch_overlay(frame: &mut Frame) {
|
||||
let area = OverlayBuilder::default().build(frame.size());
|
||||
UiWidget::render_overlay_widget(
|
||||
"Fetching",
|
||||
Paragraph::new(" -- fetching --"),
|
||||
area,
|
||||
false,
|
||||
frame,
|
||||
)
|
||||
let fetch_text = FetchOverlay::paragraph();
|
||||
UiWidget::render_overlay_widget("Fetching", fetch_text, area, false, frame)
|
||||
}
|
||||
|
||||
fn render_matches_overlay(
|
||||
@ -156,9 +151,7 @@ impl Ui {
|
||||
let area = OverlayBuilder::default()
|
||||
.with_height(OverlaySize::Value(4))
|
||||
.build(frame.size());
|
||||
|
||||
let error_text = ErrorOverlay::paragraph(msg.as_ref());
|
||||
|
||||
UiWidget::render_overlay_widget(title.as_ref(), error_text, area, true, frame);
|
||||
}
|
||||
}
|
||||
@ -267,6 +260,9 @@ mod tests {
|
||||
app.state = AppState::Search("");
|
||||
terminal.draw(|frame| Ui::render(&mut app, frame)).unwrap();
|
||||
|
||||
app.state = AppState::Fetch(());
|
||||
terminal.draw(|frame| Ui::render(&mut app, frame)).unwrap();
|
||||
|
||||
app.state = AppState::Error("get rekt scrub");
|
||||
terminal.draw(|frame| Ui::render(&mut app, frame)).unwrap();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user