Lines
100 %
Functions
Branches
//! The cua preset, the default, and the always-on `global` scope.
use super::DEFAULT_KEYMAP;
use super::tests::{alt, ctrl, key, press, type_text};
use crate::app::App;
use crate::form::FormKind;
use crate::modal::Modal;
use crate::tabs::fetch::Fetch;
use crate::view::Tab;
use ratatui::crossterm::event::KeyCode;
fn scripts_app() -> App {
let mut app = crate::test_support::app();
app.switch_tab(Tab::Scripts);
app
}
#[test]
fn cua_is_the_default_preset() {
assert_eq!(DEFAULT_KEYMAP, "cua");
assert_eq!(crate::test_support::app().keys.indicator(), "cua");
fn f1_opens_help() {
press(&mut app, key(KeyCode::F(1)));
assert!(crate::test_support::help_open(&app));
fn alt_x_quits() {
press(&mut app, alt(KeyCode::Char('x')));
press(&mut app, key(KeyCode::Char('y')));
assert!(app.should_quit);
fn insert_opens_the_new_row_form() {
let mut app = scripts_app();
press(&mut app, key(KeyCode::Insert));
assert!(matches!(
app.overlays.top(),
Some(Modal::Form(form)) if form.kind == FormKind::ScriptCreate
));
fn f4_and_f8_act_on_the_selected_row() {
for code in [KeyCode::F(4), KeyCode::F(8)] {
press(&mut app, key(code));
assert_eq!(app.status, "no script selected", "{code:?}");
fn the_letter_commands_stay() {
press(&mut app, key(KeyCode::Char('2')));
assert_eq!(app.front_kind(), Some(Tab::Transactions));
fn global_never_steals_text_in_the_console_prompt() {
app.focus_console();
type_text(&mut app, "x q:?1 ");
assert_eq!(app.console().input.buffer(), "x q:?1 ");
assert!(!app.should_quit);
assert!(app.overlays.is_empty());
fn global_never_steals_text_in_the_command_line() {
app.open_command_line();
type_text(&mut app, "xq?");
assert_eq!(app.cmdline.editor.buffer(), "xq?");
fn alt_x() -> ratatui::crossterm::event::KeyEvent {
alt(KeyCode::Char('x'))
fn top_is_form(app: &App) -> bool {
matches!(app.overlays.top(), Some(Modal::Form(_)))
fn f1_and_alt_x_act_in_the_console_prompt() {
press(&mut app, key(KeyCode::Esc));
press(&mut app, alt_x());
fn f1_and_alt_x_act_on_the_command_line() {
assert!(app.cmdline.active);
fn f1_opens_help_over_a_form_and_alt_x_leaves_the_form_open() {
app.set_status("kept".to_string());
assert!(top_is_form(&app));
assert_eq!(app.windows_of(crate::view::ViewId::Viewer), 1);
fn f1_over_a_help_window_opens_the_help_of_that_window() {
assert_eq!(app.windows_of(crate::view::ViewId::Viewer), 2);
fn ctrl_arrow(code: KeyCode) -> ratatui::crossterm::event::KeyEvent {
ratatui::crossterm::event::KeyEvent::new(code, ratatui::crossterm::event::KeyModifiers::CONTROL)
fn f2_submits_the_form() {
app.set_status(String::new());
press(&mut app, key(KeyCode::F(2)));
assert_eq!(app.status, "console not connected");
fn f3_and_f7_act_on_transactions() {
app.switch_tab(Tab::Transactions);
press(&mut app, key(KeyCode::F(3)));
assert_eq!(app.status, "no transaction selected");
press(&mut app, key(KeyCode::F(7)));
assert!(app.overlays.top().is_some() || app.status != "no transaction selected");
#[tokio::test]
async fn control_r_reloads_a_list_and_the_reports_tab() {
app.attach_echo();
app.scripts_mut().state = Fetch::Loaded(());
assert!(matches!(app.scripts().state, Fetch::Loaded(_)));
press(&mut app, ctrl(KeyCode::Char('r')));
assert!(matches!(app.scripts().state, Fetch::Loading { .. }));
app.switch_tab(Tab::Reports);
assert_eq!(app.status, "no report run yet");
fn delete_and_ctrl_arrows_edit_a_line() {
type_text(&mut app, "ab cd");
press(&mut app, ctrl_arrow(KeyCode::Left));
type_text(&mut app, "x");
assert_eq!(app.cmdline.editor.buffer(), "ab xcd");
press(&mut app, key(KeyCode::Home));
press(&mut app, key(KeyCode::Delete));
assert_eq!(app.cmdline.editor.buffer(), "b xcd");
press(&mut app, ctrl_arrow(KeyCode::Right));
type_text(&mut app, "y");
assert_eq!(app.cmdline.editor.buffer(), "b yxcd");
fn delete_and_ctrl_arrows_edit_the_console_prompt() {
assert_eq!(app.console().input.buffer(), "ab d");
assert_eq!(app.console().input.buffer(), "b d");
fn edit_row_dispatches_by_tab_from_every_key() {
let tabs = [
(Tab::Config, "no config key selected"),
(Tab::Tags, "no tag selected"),
(Tab::Templates, "no template selected"),
(Tab::Scripts, "no script selected"),
(Tab::Transactions, "no transaction selected"),
];
for (tab, status) in tabs {
for code in [KeyCode::Char('e'), KeyCode::F(4), KeyCode::Enter] {
if tab == Tab::Transactions && code == KeyCode::Enter {
continue;
app.switch_tab(tab);
assert_eq!(app.status, status, "{tab:?} {code:?}");
fn edit_row_on_reports_edits_the_last_report() {
for code in [KeyCode::Char('e'), KeyCode::F(4)] {
assert_eq!(app.status, "no report run yet", "{code:?}");