mirror of
https://github.com/kristoferssolo/traxor.git
synced 2026-02-04 06:42:04 +00:00
feat(config): add config file
This commit is contained in:
@@ -1,109 +1,86 @@
|
||||
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
|
||||
use traxor::{app::action::Action, handler::get_action};
|
||||
use traxor::{app::action::Action, handler::get_action, app::App, config::Config};
|
||||
|
||||
#[test]
|
||||
fn test_get_action_quit() {
|
||||
assert_eq!(get_action(KeyEvent::from(KeyCode::Esc)), Some(Action::Quit));
|
||||
let config = Config::load().unwrap();
|
||||
let app = App::new(config).unwrap();
|
||||
assert_eq!(
|
||||
get_action(KeyEvent::from(KeyCode::Char('q'))),
|
||||
Some(Action::Quit)
|
||||
);
|
||||
assert_eq!(
|
||||
get_action(KeyEvent::new(KeyCode::Char('c'), KeyModifiers::CONTROL)),
|
||||
Some(Action::Quit)
|
||||
);
|
||||
assert_eq!(
|
||||
get_action(KeyEvent::new(KeyCode::Char('C'), KeyModifiers::CONTROL)),
|
||||
get_action(KeyEvent::from(KeyCode::Char('q')), &app),
|
||||
Some(Action::Quit)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_action_navigation() {
|
||||
let config = Config::load().unwrap();
|
||||
let app = App::new(config).unwrap();
|
||||
assert_eq!(
|
||||
get_action(KeyEvent::from(KeyCode::Char('l'))),
|
||||
get_action(KeyEvent::from(KeyCode::Char('l')), &app),
|
||||
Some(Action::NextTab)
|
||||
);
|
||||
assert_eq!(
|
||||
get_action(KeyEvent::from(KeyCode::Right)),
|
||||
Some(Action::NextTab)
|
||||
);
|
||||
assert_eq!(
|
||||
get_action(KeyEvent::from(KeyCode::Char('h'))),
|
||||
get_action(KeyEvent::from(KeyCode::Char('h')), &app),
|
||||
Some(Action::PrevTab)
|
||||
);
|
||||
assert_eq!(
|
||||
get_action(KeyEvent::from(KeyCode::Left)),
|
||||
Some(Action::PrevTab)
|
||||
);
|
||||
assert_eq!(
|
||||
get_action(KeyEvent::from(KeyCode::Char('j'))),
|
||||
get_action(KeyEvent::from(KeyCode::Char('j')), &app),
|
||||
Some(Action::NextTorrent)
|
||||
);
|
||||
assert_eq!(
|
||||
get_action(KeyEvent::from(KeyCode::Down)),
|
||||
Some(Action::NextTorrent)
|
||||
);
|
||||
assert_eq!(
|
||||
get_action(KeyEvent::from(KeyCode::Char('k'))),
|
||||
Some(Action::PrevTorrent)
|
||||
);
|
||||
assert_eq!(
|
||||
get_action(KeyEvent::from(KeyCode::Up)),
|
||||
get_action(KeyEvent::from(KeyCode::Char('k')), &app),
|
||||
Some(Action::PrevTorrent)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_action_switch_tab() {
|
||||
let config = Config::load().unwrap();
|
||||
let app = App::new(config).unwrap();
|
||||
assert_eq!(
|
||||
get_action(KeyEvent::from(KeyCode::Char('1'))),
|
||||
get_action(KeyEvent::from(KeyCode::Char('1')), &app),
|
||||
Some(Action::SwitchTab(0))
|
||||
);
|
||||
assert_eq!(
|
||||
get_action(KeyEvent::from(KeyCode::Char('2'))),
|
||||
get_action(KeyEvent::from(KeyCode::Char('2')), &app),
|
||||
Some(Action::SwitchTab(1))
|
||||
);
|
||||
assert_eq!(
|
||||
get_action(KeyEvent::from(KeyCode::Char('3'))),
|
||||
get_action(KeyEvent::from(KeyCode::Char('3')), &app),
|
||||
Some(Action::SwitchTab(2))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_action_torrent_actions() {
|
||||
let config = Config::load().unwrap();
|
||||
let app = App::new(config).unwrap();
|
||||
assert_eq!(
|
||||
get_action(KeyEvent::from(KeyCode::Char('t'))),
|
||||
get_action(KeyEvent::from(KeyCode::Enter), &app),
|
||||
Some(Action::ToggleTorrent)
|
||||
);
|
||||
assert_eq!(
|
||||
get_action(KeyEvent::from(KeyCode::Enter)),
|
||||
Some(Action::ToggleTorrent)
|
||||
);
|
||||
assert_eq!(
|
||||
get_action(KeyEvent::from(KeyCode::Menu)),
|
||||
Some(Action::ToggleTorrent)
|
||||
);
|
||||
assert_eq!(
|
||||
get_action(KeyEvent::from(KeyCode::Char('a'))),
|
||||
get_action(KeyEvent::from(KeyCode::Char('a')), &app),
|
||||
Some(Action::ToggleAll)
|
||||
);
|
||||
assert_eq!(
|
||||
get_action(KeyEvent::from(KeyCode::Char('d'))),
|
||||
get_action(KeyEvent::from(KeyCode::Char('d')), &app),
|
||||
Some(Action::Delete(false))
|
||||
);
|
||||
assert_eq!(
|
||||
get_action(KeyEvent::from(KeyCode::Char('D'))),
|
||||
get_action(KeyEvent::from(KeyCode::Char('D')), &app),
|
||||
Some(Action::Delete(true))
|
||||
);
|
||||
assert_eq!(
|
||||
get_action(KeyEvent::from(KeyCode::Char(' '))),
|
||||
get_action(KeyEvent::from(KeyCode::Char(' ')), &app),
|
||||
Some(Action::Select)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_action_unhandled() {
|
||||
assert_eq!(get_action(KeyEvent::from(KeyCode::Char('x'))), None);
|
||||
assert_eq!(get_action(KeyEvent::from(KeyCode::F(1))), None);
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user