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:
23
tests/app.rs
23
tests/app.rs
@@ -1,21 +1,24 @@
|
||||
use traxor::app::App;
|
||||
use traxor::{app::App, config::Config};
|
||||
|
||||
#[test]
|
||||
fn test_app_creation() {
|
||||
let app = App::new().unwrap();
|
||||
let config = Config::load().unwrap();
|
||||
let app = App::new(config).unwrap();
|
||||
assert_eq!(app.tabs().len(), 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_app_quit() {
|
||||
let mut app = App::new().unwrap();
|
||||
let config = Config::load().unwrap();
|
||||
let mut app = App::new(config).unwrap();
|
||||
app.quit();
|
||||
assert!(!app.running);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_app_next_tab() {
|
||||
let mut app = App::new().unwrap();
|
||||
let config = Config::load().unwrap();
|
||||
let mut app = App::new(config).unwrap();
|
||||
assert_eq!(app.index(), 0);
|
||||
app.next_tab();
|
||||
assert_eq!(app.index(), 1);
|
||||
@@ -27,7 +30,8 @@ fn test_app_next_tab() {
|
||||
|
||||
#[test]
|
||||
fn test_app_prev_tab() {
|
||||
let mut app = App::new().unwrap();
|
||||
let config = Config::load().unwrap();
|
||||
let mut app = App::new(config).unwrap();
|
||||
assert_eq!(app.index(), 0);
|
||||
app.prev_tab();
|
||||
assert_eq!(app.index(), 2); // Wraps around
|
||||
@@ -37,7 +41,8 @@ fn test_app_prev_tab() {
|
||||
|
||||
#[test]
|
||||
fn test_app_switch_tab() {
|
||||
let mut app = App::new().unwrap();
|
||||
let config = Config::load().unwrap();
|
||||
let mut app = App::new(config).unwrap();
|
||||
assert_eq!(app.index(), 0);
|
||||
app.switch_tab(2);
|
||||
assert_eq!(app.index(), 2);
|
||||
@@ -47,7 +52,8 @@ fn test_app_switch_tab() {
|
||||
|
||||
#[test]
|
||||
fn test_app_toggle_popup() {
|
||||
let mut app = App::new().unwrap();
|
||||
let config = Config::load().unwrap();
|
||||
let mut app = App::new(config).unwrap();
|
||||
assert!(!app.show_help);
|
||||
app.toggle_help();
|
||||
assert!(app.show_help);
|
||||
@@ -57,7 +63,8 @@ fn test_app_toggle_popup() {
|
||||
|
||||
#[test]
|
||||
fn test_app_open_close_popup() {
|
||||
let mut app = App::new().unwrap();
|
||||
let config = Config::load().unwrap();
|
||||
let mut app = App::new(config).unwrap();
|
||||
assert!(!app.show_help);
|
||||
app.open_help();
|
||||
assert!(app.show_help);
|
||||
|
||||
@@ -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