mirror of
https://github.com/kristoferssolo/traxor.git
synced 2026-02-04 06:42:04 +00:00
test: fix errors
This commit is contained in:
@@ -1,86 +1,122 @@
|
||||
use crossterm::event::{KeyCode, KeyEvent};
|
||||
use traxor::{app::action::Action, app::App, config::Config, handler::get_action};
|
||||
use traxor::{app::App, app::action::Action, config::Config, handler::get_action};
|
||||
|
||||
#[test]
|
||||
fn test_get_action_quit() {
|
||||
#[tokio::test]
|
||||
async fn test_get_action_quit() {
|
||||
let config = Config::load().unwrap();
|
||||
let app = App::new(config).unwrap();
|
||||
let mut app = App::new(config).unwrap();
|
||||
assert_eq!(
|
||||
get_action(KeyEvent::from(KeyCode::Char('q')), &app),
|
||||
get_action(KeyEvent::from(KeyCode::Char('q')), &mut app)
|
||||
.await
|
||||
.unwrap(),
|
||||
Some(Action::Quit)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_action_navigation() {
|
||||
#[tokio::test]
|
||||
async fn test_get_action_navigation() {
|
||||
let config = Config::load().unwrap();
|
||||
let app = App::new(config).unwrap();
|
||||
let mut app = App::new(config).unwrap();
|
||||
assert_eq!(
|
||||
get_action(KeyEvent::from(KeyCode::Char('l')), &app),
|
||||
get_action(KeyEvent::from(KeyCode::Char('l')), &mut app)
|
||||
.await
|
||||
.unwrap(),
|
||||
Some(Action::NextTab)
|
||||
);
|
||||
assert_eq!(
|
||||
get_action(KeyEvent::from(KeyCode::Char('h')), &app),
|
||||
get_action(KeyEvent::from(KeyCode::Char('h')), &mut app)
|
||||
.await
|
||||
.unwrap(),
|
||||
Some(Action::PrevTab)
|
||||
);
|
||||
assert_eq!(
|
||||
get_action(KeyEvent::from(KeyCode::Char('j')), &app),
|
||||
get_action(KeyEvent::from(KeyCode::Char('j')), &mut app)
|
||||
.await
|
||||
.unwrap(),
|
||||
Some(Action::NextTorrent)
|
||||
);
|
||||
assert_eq!(
|
||||
get_action(KeyEvent::from(KeyCode::Char('k')), &app),
|
||||
get_action(KeyEvent::from(KeyCode::Char('k')), &mut app)
|
||||
.await
|
||||
.unwrap(),
|
||||
Some(Action::PrevTorrent)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_action_switch_tab() {
|
||||
#[tokio::test]
|
||||
async fn test_get_action_switch_tab() {
|
||||
let config = Config::load().unwrap();
|
||||
let app = App::new(config).unwrap();
|
||||
let mut app = App::new(config).unwrap();
|
||||
assert_eq!(
|
||||
get_action(KeyEvent::from(KeyCode::Char('1')), &app),
|
||||
get_action(KeyEvent::from(KeyCode::Char('1')), &mut app)
|
||||
.await
|
||||
.unwrap(),
|
||||
Some(Action::SwitchTab(0))
|
||||
);
|
||||
assert_eq!(
|
||||
get_action(KeyEvent::from(KeyCode::Char('2')), &app),
|
||||
get_action(KeyEvent::from(KeyCode::Char('2')), &mut app)
|
||||
.await
|
||||
.unwrap(),
|
||||
Some(Action::SwitchTab(1))
|
||||
);
|
||||
assert_eq!(
|
||||
get_action(KeyEvent::from(KeyCode::Char('3')), &app),
|
||||
get_action(KeyEvent::from(KeyCode::Char('3')), &mut app)
|
||||
.await
|
||||
.unwrap(),
|
||||
Some(Action::SwitchTab(2))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_action_torrent_actions() {
|
||||
#[tokio::test]
|
||||
async fn test_get_action_torrent_actions() {
|
||||
let config = Config::load().unwrap();
|
||||
let app = App::new(config).unwrap();
|
||||
let mut app = App::new(config).unwrap();
|
||||
assert_eq!(
|
||||
get_action(KeyEvent::from(KeyCode::Enter), &app),
|
||||
get_action(KeyEvent::from(KeyCode::Enter), &mut app)
|
||||
.await
|
||||
.unwrap(),
|
||||
Some(Action::ToggleTorrent)
|
||||
);
|
||||
assert_eq!(
|
||||
get_action(KeyEvent::from(KeyCode::Char('a')), &app),
|
||||
get_action(KeyEvent::from(KeyCode::Char('a')), &mut app)
|
||||
.await
|
||||
.unwrap(),
|
||||
Some(Action::ToggleAll)
|
||||
);
|
||||
assert_eq!(
|
||||
get_action(KeyEvent::from(KeyCode::Char('d')), &app),
|
||||
get_action(KeyEvent::from(KeyCode::Char('d')), &mut app)
|
||||
.await
|
||||
.unwrap(),
|
||||
Some(Action::Delete(false))
|
||||
);
|
||||
assert_eq!(
|
||||
get_action(KeyEvent::from(KeyCode::Char('D')), &app),
|
||||
get_action(KeyEvent::from(KeyCode::Char('D')), &mut app)
|
||||
.await
|
||||
.unwrap(),
|
||||
Some(Action::Delete(true))
|
||||
);
|
||||
assert_eq!(
|
||||
get_action(KeyEvent::from(KeyCode::Char(' ')), &app),
|
||||
get_action(KeyEvent::from(KeyCode::Char(' ')), &mut app)
|
||||
.await
|
||||
.unwrap(),
|
||||
Some(Action::Select)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_action_unhandled() {
|
||||
#[tokio::test]
|
||||
async fn test_get_action_unhandled() {
|
||||
let config = Config::load().unwrap();
|
||||
let app = App::new(config).unwrap();
|
||||
assert_eq!(get_action(KeyEvent::from(KeyCode::Char('x')), &app), None);
|
||||
assert_eq!(get_action(KeyEvent::from(KeyCode::F(1)), &app), None);
|
||||
let mut app = App::new(config).unwrap();
|
||||
assert_eq!(
|
||||
get_action(KeyEvent::from(KeyCode::Char('x')), &mut app)
|
||||
.await
|
||||
.unwrap(),
|
||||
None
|
||||
);
|
||||
assert_eq!(
|
||||
get_action(KeyEvent::from(KeyCode::F(1)), &mut app)
|
||||
.await
|
||||
.unwrap(),
|
||||
None
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user