Rename app to ui
This commit is contained in:
parent
6d22e430ca
commit
1be636b648
@ -178,7 +178,7 @@ mod tests {
|
||||
Terminal::new(backend).unwrap()
|
||||
}
|
||||
|
||||
pub fn app(collection: Collection) -> MhUi<MockCollectionManager> {
|
||||
pub fn ui(collection: Collection) -> MhUi<MockCollectionManager> {
|
||||
let mut collection_manager = MockCollectionManager::new();
|
||||
|
||||
collection_manager
|
||||
@ -206,8 +206,8 @@ mod tests {
|
||||
let mut handler = MockEventHandler::new();
|
||||
handler
|
||||
.expect_handle_next_event()
|
||||
.return_once(|app: &mut MhUi<MockCollectionManager>| {
|
||||
app.quit();
|
||||
.return_once(|ui: &mut MhUi<MockCollectionManager>| {
|
||||
ui.quit();
|
||||
Ok(())
|
||||
});
|
||||
handler
|
||||
@ -216,19 +216,19 @@ mod tests {
|
||||
#[test]
|
||||
fn run() {
|
||||
let terminal = terminal();
|
||||
let app = app(COLLECTION.to_owned());
|
||||
let ui = ui(COLLECTION.to_owned());
|
||||
|
||||
let listener = listener();
|
||||
let handler = handler();
|
||||
|
||||
let result = Tui::main(terminal, app, handler, listener);
|
||||
let result = Tui::main(terminal, ui, handler, listener);
|
||||
assert!(result.is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn event_error() {
|
||||
let terminal = terminal();
|
||||
let app = app(COLLECTION.to_owned());
|
||||
let ui = ui(COLLECTION.to_owned());
|
||||
|
||||
let listener = listener();
|
||||
|
||||
@ -237,7 +237,7 @@ mod tests {
|
||||
.expect_handle_next_event()
|
||||
.return_once(|_| Err(EventError::Recv));
|
||||
|
||||
let result = Tui::main(terminal, app, handler, listener);
|
||||
let result = Tui::main(terminal, ui, handler, listener);
|
||||
assert!(result.is_err());
|
||||
assert_eq!(
|
||||
result.unwrap_err(),
|
||||
@ -248,7 +248,7 @@ mod tests {
|
||||
#[test]
|
||||
fn listener_error() {
|
||||
let terminal = terminal();
|
||||
let app = app(COLLECTION.to_owned());
|
||||
let ui = ui(COLLECTION.to_owned());
|
||||
|
||||
let error = EventError::Io(io::Error::new(io::ErrorKind::Interrupted, "error"));
|
||||
let listener_handle: thread::JoinHandle<EventError> = thread::spawn(|| error);
|
||||
@ -262,7 +262,7 @@ mod tests {
|
||||
.expect_handle_next_event()
|
||||
.return_once(|_| Err(EventError::Recv));
|
||||
|
||||
let result = Tui::main(terminal, app, handler, listener);
|
||||
let result = Tui::main(terminal, ui, handler, listener);
|
||||
assert!(result.is_err());
|
||||
|
||||
let error = EventError::Io(io::Error::new(io::ErrorKind::Interrupted, "error"));
|
||||
@ -272,7 +272,7 @@ mod tests {
|
||||
#[test]
|
||||
fn listener_panic() {
|
||||
let terminal = terminal();
|
||||
let app = app(COLLECTION.to_owned());
|
||||
let ui = ui(COLLECTION.to_owned());
|
||||
|
||||
let listener_handle: thread::JoinHandle<EventError> = thread::spawn(|| panic!());
|
||||
while !listener_handle.is_finished() {}
|
||||
@ -285,7 +285,7 @@ mod tests {
|
||||
.expect_handle_next_event()
|
||||
.return_once(|_| Err(EventError::Recv));
|
||||
|
||||
let result = Tui::main(terminal, app, handler, listener);
|
||||
let result = Tui::main(terminal, ui, handler, listener);
|
||||
assert!(result.is_err());
|
||||
assert_eq!(result.unwrap_err(), Error::ListenerPanic);
|
||||
}
|
||||
|
174
src/tui/ui.rs
174
src/tui/ui.rs
@ -601,7 +601,7 @@ impl<CM: CollectionManager> Ui for MhUi<CM> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::tests::{MockCollectionManager, COLLECTION};
|
||||
use crate::tui::tests::{app, terminal};
|
||||
use crate::tui::tests::{terminal, ui};
|
||||
|
||||
use super::*;
|
||||
|
||||
@ -758,7 +758,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn app_running() {
|
||||
fn ui_running() {
|
||||
let mut collection_manager = MockCollectionManager::new();
|
||||
|
||||
collection_manager
|
||||
@ -769,15 +769,15 @@ mod tests {
|
||||
.expect_get_collection()
|
||||
.return_const(COLLECTION.to_owned());
|
||||
|
||||
let mut app = MhUi::new(collection_manager).unwrap();
|
||||
assert!(app.is_running());
|
||||
let mut ui = MhUi::new(collection_manager).unwrap();
|
||||
assert!(ui.is_running());
|
||||
|
||||
app.quit();
|
||||
assert!(!app.is_running());
|
||||
ui.quit();
|
||||
assert!(!ui.is_running());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn app_modifiers() {
|
||||
fn ui_modifiers() {
|
||||
let mut collection_manager = MockCollectionManager::new();
|
||||
|
||||
collection_manager
|
||||
@ -788,91 +788,91 @@ mod tests {
|
||||
.expect_get_collection()
|
||||
.return_const(COLLECTION.to_owned());
|
||||
|
||||
let mut app = MhUi::new(collection_manager).unwrap();
|
||||
assert!(app.is_running());
|
||||
let mut ui = MhUi::new(collection_manager).unwrap();
|
||||
assert!(ui.is_running());
|
||||
|
||||
assert_eq!(app.selection.active, Category::Artist);
|
||||
assert_eq!(app.selection.artist.state.selected(), Some(0));
|
||||
assert_eq!(app.selection.artist.album.state.selected(), Some(0));
|
||||
assert_eq!(app.selection.artist.album.track.state.selected(), Some(0));
|
||||
assert_eq!(ui.selection.active, Category::Artist);
|
||||
assert_eq!(ui.selection.artist.state.selected(), Some(0));
|
||||
assert_eq!(ui.selection.artist.album.state.selected(), Some(0));
|
||||
assert_eq!(ui.selection.artist.album.track.state.selected(), Some(0));
|
||||
|
||||
app.increment_selection();
|
||||
assert_eq!(app.selection.active, Category::Artist);
|
||||
assert_eq!(app.selection.artist.state.selected(), Some(1));
|
||||
assert_eq!(app.selection.artist.album.state.selected(), Some(0));
|
||||
assert_eq!(app.selection.artist.album.track.state.selected(), Some(0));
|
||||
ui.increment_selection();
|
||||
assert_eq!(ui.selection.active, Category::Artist);
|
||||
assert_eq!(ui.selection.artist.state.selected(), Some(1));
|
||||
assert_eq!(ui.selection.artist.album.state.selected(), Some(0));
|
||||
assert_eq!(ui.selection.artist.album.track.state.selected(), Some(0));
|
||||
|
||||
app.increment_category();
|
||||
assert_eq!(app.selection.active, Category::Album);
|
||||
assert_eq!(app.selection.artist.state.selected(), Some(1));
|
||||
assert_eq!(app.selection.artist.album.state.selected(), Some(0));
|
||||
assert_eq!(app.selection.artist.album.track.state.selected(), Some(0));
|
||||
ui.increment_category();
|
||||
assert_eq!(ui.selection.active, Category::Album);
|
||||
assert_eq!(ui.selection.artist.state.selected(), Some(1));
|
||||
assert_eq!(ui.selection.artist.album.state.selected(), Some(0));
|
||||
assert_eq!(ui.selection.artist.album.track.state.selected(), Some(0));
|
||||
|
||||
app.increment_selection();
|
||||
assert_eq!(app.selection.active, Category::Album);
|
||||
assert_eq!(app.selection.artist.state.selected(), Some(1));
|
||||
assert_eq!(app.selection.artist.album.state.selected(), Some(1));
|
||||
assert_eq!(app.selection.artist.album.track.state.selected(), Some(0));
|
||||
ui.increment_selection();
|
||||
assert_eq!(ui.selection.active, Category::Album);
|
||||
assert_eq!(ui.selection.artist.state.selected(), Some(1));
|
||||
assert_eq!(ui.selection.artist.album.state.selected(), Some(1));
|
||||
assert_eq!(ui.selection.artist.album.track.state.selected(), Some(0));
|
||||
|
||||
app.increment_category();
|
||||
assert_eq!(app.selection.active, Category::Track);
|
||||
assert_eq!(app.selection.artist.state.selected(), Some(1));
|
||||
assert_eq!(app.selection.artist.album.state.selected(), Some(1));
|
||||
assert_eq!(app.selection.artist.album.track.state.selected(), Some(0));
|
||||
ui.increment_category();
|
||||
assert_eq!(ui.selection.active, Category::Track);
|
||||
assert_eq!(ui.selection.artist.state.selected(), Some(1));
|
||||
assert_eq!(ui.selection.artist.album.state.selected(), Some(1));
|
||||
assert_eq!(ui.selection.artist.album.track.state.selected(), Some(0));
|
||||
|
||||
app.increment_selection();
|
||||
assert_eq!(app.selection.active, Category::Track);
|
||||
assert_eq!(app.selection.artist.state.selected(), Some(1));
|
||||
assert_eq!(app.selection.artist.album.state.selected(), Some(1));
|
||||
assert_eq!(app.selection.artist.album.track.state.selected(), Some(1));
|
||||
ui.increment_selection();
|
||||
assert_eq!(ui.selection.active, Category::Track);
|
||||
assert_eq!(ui.selection.artist.state.selected(), Some(1));
|
||||
assert_eq!(ui.selection.artist.album.state.selected(), Some(1));
|
||||
assert_eq!(ui.selection.artist.album.track.state.selected(), Some(1));
|
||||
|
||||
app.increment_category();
|
||||
assert_eq!(app.selection.active, Category::Track);
|
||||
assert_eq!(app.selection.artist.state.selected(), Some(1));
|
||||
assert_eq!(app.selection.artist.album.state.selected(), Some(1));
|
||||
assert_eq!(app.selection.artist.album.track.state.selected(), Some(1));
|
||||
ui.increment_category();
|
||||
assert_eq!(ui.selection.active, Category::Track);
|
||||
assert_eq!(ui.selection.artist.state.selected(), Some(1));
|
||||
assert_eq!(ui.selection.artist.album.state.selected(), Some(1));
|
||||
assert_eq!(ui.selection.artist.album.track.state.selected(), Some(1));
|
||||
|
||||
app.decrement_selection();
|
||||
assert_eq!(app.selection.active, Category::Track);
|
||||
assert_eq!(app.selection.artist.state.selected(), Some(1));
|
||||
assert_eq!(app.selection.artist.album.state.selected(), Some(1));
|
||||
assert_eq!(app.selection.artist.album.track.state.selected(), Some(0));
|
||||
ui.decrement_selection();
|
||||
assert_eq!(ui.selection.active, Category::Track);
|
||||
assert_eq!(ui.selection.artist.state.selected(), Some(1));
|
||||
assert_eq!(ui.selection.artist.album.state.selected(), Some(1));
|
||||
assert_eq!(ui.selection.artist.album.track.state.selected(), Some(0));
|
||||
|
||||
app.increment_selection();
|
||||
app.decrement_category();
|
||||
assert_eq!(app.selection.active, Category::Album);
|
||||
assert_eq!(app.selection.artist.state.selected(), Some(1));
|
||||
assert_eq!(app.selection.artist.album.state.selected(), Some(1));
|
||||
assert_eq!(app.selection.artist.album.track.state.selected(), Some(1));
|
||||
ui.increment_selection();
|
||||
ui.decrement_category();
|
||||
assert_eq!(ui.selection.active, Category::Album);
|
||||
assert_eq!(ui.selection.artist.state.selected(), Some(1));
|
||||
assert_eq!(ui.selection.artist.album.state.selected(), Some(1));
|
||||
assert_eq!(ui.selection.artist.album.track.state.selected(), Some(1));
|
||||
|
||||
app.decrement_selection();
|
||||
assert_eq!(app.selection.active, Category::Album);
|
||||
assert_eq!(app.selection.artist.state.selected(), Some(1));
|
||||
assert_eq!(app.selection.artist.album.state.selected(), Some(0));
|
||||
assert_eq!(app.selection.artist.album.track.state.selected(), Some(0));
|
||||
ui.decrement_selection();
|
||||
assert_eq!(ui.selection.active, Category::Album);
|
||||
assert_eq!(ui.selection.artist.state.selected(), Some(1));
|
||||
assert_eq!(ui.selection.artist.album.state.selected(), Some(0));
|
||||
assert_eq!(ui.selection.artist.album.track.state.selected(), Some(0));
|
||||
|
||||
app.increment_selection();
|
||||
app.decrement_category();
|
||||
assert_eq!(app.selection.active, Category::Artist);
|
||||
assert_eq!(app.selection.artist.state.selected(), Some(1));
|
||||
assert_eq!(app.selection.artist.album.state.selected(), Some(1));
|
||||
assert_eq!(app.selection.artist.album.track.state.selected(), Some(0));
|
||||
ui.increment_selection();
|
||||
ui.decrement_category();
|
||||
assert_eq!(ui.selection.active, Category::Artist);
|
||||
assert_eq!(ui.selection.artist.state.selected(), Some(1));
|
||||
assert_eq!(ui.selection.artist.album.state.selected(), Some(1));
|
||||
assert_eq!(ui.selection.artist.album.track.state.selected(), Some(0));
|
||||
|
||||
app.decrement_selection();
|
||||
assert_eq!(app.selection.active, Category::Artist);
|
||||
assert_eq!(app.selection.artist.state.selected(), Some(0));
|
||||
assert_eq!(app.selection.artist.album.state.selected(), Some(0));
|
||||
assert_eq!(app.selection.artist.album.track.state.selected(), Some(0));
|
||||
ui.decrement_selection();
|
||||
assert_eq!(ui.selection.active, Category::Artist);
|
||||
assert_eq!(ui.selection.artist.state.selected(), Some(0));
|
||||
assert_eq!(ui.selection.artist.album.state.selected(), Some(0));
|
||||
assert_eq!(ui.selection.artist.album.track.state.selected(), Some(0));
|
||||
|
||||
app.increment_category();
|
||||
app.increment_selection();
|
||||
app.decrement_category();
|
||||
app.decrement_selection();
|
||||
app.decrement_category();
|
||||
assert_eq!(app.selection.active, Category::Artist);
|
||||
assert_eq!(app.selection.artist.state.selected(), Some(0));
|
||||
assert_eq!(app.selection.artist.album.state.selected(), Some(1));
|
||||
assert_eq!(app.selection.artist.album.track.state.selected(), Some(0));
|
||||
ui.increment_category();
|
||||
ui.increment_selection();
|
||||
ui.decrement_category();
|
||||
ui.decrement_selection();
|
||||
ui.decrement_category();
|
||||
assert_eq!(ui.selection.active, Category::Artist);
|
||||
assert_eq!(ui.selection.artist.state.selected(), Some(0));
|
||||
assert_eq!(ui.selection.artist.album.state.selected(), Some(1));
|
||||
assert_eq!(ui.selection.artist.album.track.state.selected(), Some(0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -1031,23 +1031,23 @@ mod tests {
|
||||
#[test]
|
||||
fn empty() {
|
||||
let mut terminal = terminal();
|
||||
let mut app = app(vec![]);
|
||||
let mut ui = ui(vec![]);
|
||||
|
||||
terminal.draw(|frame| app.render(frame)).unwrap();
|
||||
terminal.draw(|frame| ui.render(frame)).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn collection() {
|
||||
let mut terminal = terminal();
|
||||
let mut app = app(COLLECTION.to_owned());
|
||||
let mut ui = ui(COLLECTION.to_owned());
|
||||
|
||||
terminal.draw(|frame| app.render(frame)).unwrap();
|
||||
terminal.draw(|frame| ui.render(frame)).unwrap();
|
||||
|
||||
// Change the track (which has a different track format).
|
||||
app.increment_category();
|
||||
app.increment_category();
|
||||
app.increment_selection();
|
||||
ui.increment_category();
|
||||
ui.increment_category();
|
||||
ui.increment_selection();
|
||||
|
||||
terminal.draw(|frame| app.render(frame)).unwrap();
|
||||
terminal.draw(|frame| ui.render(frame)).unwrap();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user