Lines
99.11 %
Functions
100 %
Branches
//! A late reply never opens, fills or switches over a dialog that is already open.
use super::edit::options_wire;
use crate::app::App;
use crate::event::{Intent, apply};
use crate::form::Form;
use crate::modal::Modal;
use crate::route::{FormOptionsSource, RouteCtx};
use crate::tabs::fetch::Fetch;
use crate::tabs::nms_eval::double::Sent;
use crate::view::{Tab, ViewId};
use crate::widgets::Widget;
const CASH: &str = "550e8400-e29b-41d4-a716-446655440081";
const BANK: &str = "550e8400-e29b-41d4-a716-446655440082";
const USD: &str = "550e8400-e29b-41d4-a716-446655440083";
const DROPPED: &str = "another dialog is open";
fn connected() -> (App, Sent) {
let mut app = crate::test_support::app();
let sent = app.attach_echo();
(app, sent)
}
fn run(app: &mut App, command: &str) {
apply(app, Intent::OpenCommandLine);
command
.chars()
.for_each(|c| apply(app, Intent::InsertChar(c)));
apply(app, Intent::Submit);
fn pending_id(app: &App, wanted: fn(&RouteCtx) -> bool) -> i64 {
app.pending_routes
.iter()
.find_map(|(id, route)| wanted(&route.ctx).then_some(*id))
.unwrap_or_default()
fn lookup_id(app: &App) -> i64 {
pending_id(app, |ctx| matches!(ctx, RouteCtx::Lookup { .. }))
fn account_options_id(app: &App) -> i64 {
pending_id(app, |ctx| {
matches!(
ctx,
RouteCtx::FormOptions {
source: FormOptionsSource::FormAccounts,
..
)
})
fn transaction_form(app: &App) -> &Form {
match app.overlays.top() {
Some(Modal::Form(form)) if form.is_transaction() => form,
other => panic!("the transaction form expected on top, got {other:?}"),
fn split_account_options(app: &App) -> usize {
transaction_form(app)
.fields
.find_map(|field| match &field.widget {
Widget::Splits(splits) => Some(splits.rows()[0].from.options().len()),
_ => None,
fn deliver_accounts_to_the_open_form(app: &mut App) {
let id = account_options_id(app);
assert!(id > 0, "the open form fetched its account options");
app.route_reply(
id,
&options_wire(&[(CASH, "Assets:Cash"), (BANK, "Assets:Bank")]),
);
#[tokio::test]
async fn a_merge_lookup_under_a_new_transaction_form_is_dropped() {
let (mut app, _) = connected();
run(&mut app, "account merge from=Assets:Cash");
let lookup = lookup_id(&app);
run(&mut app, "transaction create");
app.route_reply(lookup, &options_wire(&[(CASH, "Assets:Cash")]));
assert!(app.status.contains(DROPPED), "{}", app.status);
assert!(app.status.starts_with("merge dropped"), "{}", app.status);
deliver_accounts_to_the_open_form(&mut app);
assert_eq!(split_account_options(&app), 3, "(none) + both accounts");
app.overlays.pop();
assert!(app.overlays.is_empty(), "no merge form opened");
async fn a_late_report_lookup_keeps_the_open_forms_options() {
run(&mut app, "reports activity target=usd");
app.route_reply(lookup, &options_wire(&[(USD, "USD")]));
assert!(app.status.starts_with("report dropped"), "{}", app.status);
assert!(matches!(app.reports().state, Fetch::Idle));
assert_eq!(split_account_options(&app), 3);
async fn a_filter_reply_under_help_applies_the_filter_without_switching_tab() {
app.switch_tab(Tab::Accounts);
run(&mut app, "transaction list account=Assets:Cash");
let query = pending_id(&app, |ctx| {
matches!(ctx, RouteCtx::TransactionFilter { .. })
});
assert!(query > 0, "the filter query is in flight");
crate::test_support::open_overlay(&mut app);
app.route_reply(query, r#"(:id 1 :value (:ROWS () :HAS-MORE nil :TOTAL 0))"#);
assert_eq!(app.front_kind(), Some(Tab::Accounts));
assert_eq!(app.transactions().filter().text("account"), Some(CASH));
async fn a_balance_lookup_under_help_prints_without_switching_tab() {
run(&mut app, "account balance account=Assets:Cash");
assert!(
.values()
.any(|route| route.target == Some(app.window_of(ViewId::Console))),
"the balances were requested"
async fn a_report_run_lookup_under_help_runs_without_switching_tab() {
run(&mut app, "reports balance target=usd");
assert!(matches!(app.reports().state, Fetch::Loading { .. }));