Lines
98.99 %
Functions
100 %
Branches
//! Tests for key-event routing.
mod account_merge;
mod completion;
mod config_edit;
mod confirm;
mod convert;
mod create;
mod palette_console;
mod pending;
mod quit;
mod select;
mod split_tag_side;
mod transaction;
mod transaction_create;
use super::*;
use crate::view::ViewId;
use sqlx::types::Uuid;
#[test]
fn quit_now_intent_sets_quit_flag() {
let mut app = crate::test_support::app();
apply(&mut app, Intent::QuitNow);
assert!(app.should_quit);
}
fn select_tab_intent_jumps_directly() {
apply(&mut app, Intent::SelectTab(Tab::Reports));
assert_eq!(app.front_kind(), Some(Tab::Reports));
fn open_command_line_activates_and_accepts_input() {
apply(&mut app, Intent::OpenCommandLine);
assert!(app.cmdline.active);
apply(&mut app, Intent::InsertChar('v'));
apply(&mut app, Intent::InsertChar('x'));
assert_eq!(app.cmdline.editor.buffer(), "vx");
fn submit_command_line_records_buffer_and_closes() {
for c in "version".chars() {
apply(&mut app, Intent::InsertChar(c));
apply(&mut app, Intent::Submit);
assert!(!app.cmdline.active, "command line must close after submit");
// version is an eval leaf — it submits the form and switches to Console.
assert_eq!(app.front_kind(), Some(Tab::Console));
assert!(
app.console()
.scrollback
.iter()
.any(|l| l.contains("(get-version)")),
"form should appear in console scrollback"
);
fn submit_command_line_with_unknown_path_surfaces_error() {
for c in "bogus-cmd".chars() {
assert!(app.status.contains("unknown"));
fn report_modal_accepts_typing_and_focus_cycle() {
// `reports activity` with no dates opens the params modal; the user must be
// able to type into it, Tab to cycle focus, and have the buffers captured.
for c in "reports activity".chars() {
matches!(app.overlays.top(), Some(Modal::Form(_))),
"missing dates should open the report-params modal"
apply(&mut app, Intent::NextField); // Target → From
for c in "2024-01-01".chars() {
apply(&mut app, Intent::NextField); // To
for c in "2024-12-31".chars() {
match app.overlays.top() {
Some(Modal::Form(f)) => {
assert_eq!(f.fields[1].widget.value(), "2024-01-01");
assert_eq!(f.fields[2].widget.value(), "2024-12-31");
other => panic!("expected Form modal, got {other:?}"),
fn submit_config_set_opens_form_modal() {
for c in "config set key=locale value=en".chars() {
assert!(!app.overlays.is_empty());
assert_eq!(f.fields[0].widget.value(), "locale");
assert_eq!(f.fields[1].widget.value(), "en");
fn close_topmost_pops_modal_before_touching_tabs() {
crate::test_support::open_overlay(&mut app);
apply(&mut app, Intent::Quit);
!app.should_quit,
"quit should be swallowed by the modal layer"
apply(&mut app, Intent::CloseTopmost);
assert!(app.overlays.is_empty());
apply(&mut app, Intent::ConfirmYes);
fn console_focus_sets_flag_and_blur_clears_it() {
app.switch_tab(Tab::Console);
apply(&mut app, Intent::ConsoleFocus);
assert!(app.console_input_focused());
apply(&mut app, Intent::ConsoleBlur);
assert!(!app.console_input_focused());
fn console_editing_intents_mutate_input_editor() {
app.focus_console();
apply(&mut app, Intent::InsertChar('('));
apply(&mut app, Intent::InsertChar('a'));
assert_eq!(app.console().input.buffer(), "(a");
apply(&mut app, Intent::DeleteBackward);
assert_eq!(app.console().input.buffer(), "(");
fn console_submit_incomplete_form_keeps_buffering() {
for c in "(list".chars() {
apply(&mut app, Intent::ConsoleSubmit);
assert_eq!(app.console().pending, "(list");
assert!(app.console().input.buffer().is_empty());
#[tokio::test]
async fn console_submit_routes_complete_form_to_echo_eval() {
let sent = app.attach_echo();
for c in "(+ 1 2)".chars() {
tokio::task::yield_now().await;
app.drain_eval();
assert!(app.console().scrollback.iter().any(|l| l == "> (+ 1 2)"));
sent.frames()
.any(|l| l.contains("(:id 1 :stream 1 :form (+ 1 2))"))
fn console_history_keys_navigate_prior_submissions() {
for form in ["(a)", "(b)"] {
for c in form.chars() {
apply(&mut app, Intent::ConsoleHistoryPrev);
assert_eq!(app.console().input.buffer(), "(b)");
assert_eq!(app.console().input.buffer(), "(a)");
apply(&mut app, Intent::ConsoleHistoryNext);
fn console_interrupt_without_eval_does_not_panic() {
apply(&mut app, Intent::ConsoleInterrupt);
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn console_interrupt_intent_reaches_attached_eval() {
use crate::tabs::nms_eval::ConsoleEval;
use rpc::{ScriptCtx, ScriptLimits};
use std::time::Duration;
use tokio::time::sleep;
let ctx = ScriptCtx::new(Uuid::nil()).with_limits(ScriptLimits {
fuel: u64::MAX,
..ScriptLimits::default()
});
let eval = ConsoleEval::connect(&tokio::runtime::Handle::current(), ctx, rpc::Session::new)
.expect("spawn");
app.attach_console(eval);
app.await_ui_config_read().await,
"the theme read was never answered"
for c in "(do ((i 0 (+ i 1))) ((>= i 1073741823) i))".chars() {
sleep(Duration::from_millis(40)).await;
let mut interrupted = false;
for _ in 0..200 {
if app
.console()
.any(|l| l.contains("[error] interrupted:"))
{
interrupted = true;
break;
sleep(Duration::from_millis(20)).await;
assert!(interrupted, "interrupt did not reach the eval");
async fn palette_version_submits_form_and_switches_console() {
app.attach_echo();
assert_eq!(
app.front_kind(),
Some(Tab::Console),
"should switch to Console tab"
"form should appear in scrollback; scrollback: {:?}",
app.console().scrollback
fn palette_config_set_opens_modal_not_console() {
for c in "config set".chars() {
assert!(!app.overlays.is_empty(), "config set should open a modal");
Some(Tab::Config),
"the dialog's window comes to the front"
fn console_cycle_pane_toggles_focus() {
use crate::pane::PaneId;
assert_eq!(app.console().panes.focused(), PaneId::Prompt);
apply(&mut app, Intent::ConsoleCyclePane);
assert_eq!(app.console().panes.focused(), PaneId::Scrollback);
fn console_refocus_resets_pane_to_prompt() {
fn scroll_line_up_down_adjusts_offset() {
for i in 0..20 {
app.console_mut().push_scrollback(format!("line {i}"));
apply(&mut app, Intent::ScrollLineUp);
assert_eq!(app.console().scroll, 1);
assert_eq!(app.console().scroll, 2);
apply(&mut app, Intent::ScrollLineDown);
assert_eq!(app.console().scroll, 0);
fn scroll_page_up_down_moves_by_ten() {
for i in 0..30 {
apply(&mut app, Intent::ScrollPageUp);
assert_eq!(app.console().scroll, 10);
apply(&mut app, Intent::ScrollPageDown);
fn scroll_up_clamped_at_scrollback_len() {
for i in 0..5 {
assert_eq!(app.console().scroll, 5);
fn submit_console_form_resets_scroll() {
app.console_mut().scroll_up(10);
let console = app.window_of(ViewId::Console);
app.submit_console_form(console, "(+ 1 2)".to_string());
fn palette_account_balance_without_an_account_surfaces_error_status() {
for c in "account balance".chars() {
app.status.contains("command error"),
"a missing account should surface error in status; got: {}",
app.status
fn amount_widget_in_form_keeps_every_typed_char() {
use crate::form::{Field, Form, FormKind};
use crate::widgets::{AmountWidget, Widget};
let form = Form {
fields: vec![Field {
key: None,
label: "amount",
widget: Widget::Amount(AmountWidget::default()),
}],
focus: 0,
kind: FormKind::ConfigSet,
..Form::config_set()
};
app.open_dialog_on_front(Modal::Form(form));
apply(&mut app, Intent::InsertChar('5'));
apply(&mut app, Intent::InsertChar(','));
Some(Modal::Form(f)) => assert_eq!(f.fields[0].widget.value(), "a5,"),
_ => panic!("expected form modal"),