Lines
98.9 %
Functions
100 %
Branches
use super::*;
#[tokio::test]
async fn submit_echoes_the_form_in_the_console_and_sends_its_frame() {
let mut app = crate::test_support::app();
let sent = app.attach_echo();
let console = app.window_of(ViewId::Console);
app.submit_console_form(console, "(x)".to_string());
tokio::task::yield_now().await;
assert!(app.console().scrollback.iter().any(|l| l == "> (x)"));
assert_eq!(sent.frames(), ["(:id 1 :stream 1 :form (x))"]);
}
async fn a_frame_nobody_awaits_goes_to_the_status() {
let (eval, replies) = ConsoleEval::scripted();
app.console_eval = Some(eval);
assert!(replies.try_send("((((".to_string()).is_ok());
app.drain_eval();
assert_eq!(app.status, "((((");
async fn each_reply_settles_its_own_route_whatever_the_order() {
app.submit_console_form(console, "(a)".to_string());
app.submit_console_form(console, "(b)".to_string());
assert_eq!(app.pending_routes.len(), 2);
assert!(replies.try_send("(:id 2 :value 2)".to_string()).is_ok());
assert_eq!(app.pending_routes.keys().copied().collect::<Vec<_>>(), [1]);
assert!(replies.try_send("(:id 1 :value 1)".to_string()).is_ok());
assert!(app.pending_routes.is_empty());
#[test]
fn submit_without_eval_reports_not_connected_in_status() {
assert_eq!(app.status, "console not connected");
fn drain_without_eval_is_noop() {
assert!(app.console().scrollback.is_empty());
async fn submit_without_console_ids_reports_it_in_status() {
app.attach_echo();
app.break_console();
assert_eq!(app.status, crate::tabs::nms_eval::UNAVAILABLE);
fn a_multi_line_notice_shows_its_first_line_and_a_log_hint() {
app.notify(vec!["first".to_string(), "second".to_string()]);
assert_eq!(app.status, "first … (see log)");
fn an_empty_notice_leaves_the_status_alone() {
app.set_status("kept");
app.notify(Vec::new());
assert_eq!(app.status, "kept");
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn a_reader_error_reply_clears_the_console_route() {
app.attach_console(
ConsoleEval::connect(
&tokio::runtime::Handle::current(),
rpc::ScriptCtx::new(sqlx::types::Uuid::nil()),
rpc::Session::new,
)
.expect("session"),
);
app.pending_routes.clear();
app.submit_console_form(console, "(+ 1".to_string());
assert_eq!(app.pending_routes.len(), 1);
for _ in 0..200 {
if app.pending_routes.is_empty() {
break;
tokio::time::sleep(std::time::Duration::from_millis(20)).await;
app.submit_console_form(console, "(+ 2 2)".to_string());
assert!(
app.console().scrollback.iter().any(|l| l == "4"),
"{:?}",
app.console().scrollback
fn a_console_reply_lands_in_the_submitting_console_only() {
let first = app.window_of(ViewId::Console);
let second = app.open_new_window(View::Console(ConsoleState::new()));
let route = |target| Route {
target: Some(target),
ctx: RouteCtx::None,
};
app.pending_routes.insert(7, route(first));
app.pending_routes.insert(8, route(second));
app.route_reply(8, "(:id 8 :value 42)");
app.win::<ConsoleState>(first)
.is_some_and(|c| c.scrollback.is_empty())
app.win::<ConsoleState>(second)
.is_some_and(|c| !c.scrollback.is_empty())
app.route_reply(7, "(:id 7 :value 43)");
fn submitting_from_the_older_console_echoes_there_not_in_the_recent_one() {
app.submit_console_form(first, "(x)".to_string());
.is_some_and(|c| c.scrollback.iter().any(|l| l == "> (x)"))
fn a_reply_for_a_closed_console_is_dropped() {
app.pending_routes.insert(
9,
Route {
target: Some(second),
},
app.close_window(second);
app.route_reply(9, "(:id 9 :value 1)");
assert!(app.status.is_empty());
fn switching_away_from_console_clears_focus() {
app.focus_console();
app.switch_tab(Tab::Accounts);
!app.console_input_focused(),
"leaving console must drop its input focus"
app.next_window();
"next_window off console must drop focus"
fn refresh_tab_goes_idle_and_keeps_the_selection() {
app.accounts_mut().state = Fetch::Loaded(vec![ListRow {
id: None,
cells: vec!["foo".into()],
}]);
app.accounts_mut().selected = 2;
app.refresh_windows(Tab::Accounts);
assert_eq!(app.accounts().state, Fetch::Idle);
assert_eq!(app.accounts().selected, 2);
fn switch_tab_to_reports_does_not_trigger_fetch() {
let app = crate::test_support::app();
assert!(matches!(app.accounts().state, Fetch::Idle));
assert!(matches!(app.transactions().state, Fetch::Idle));
assert!(matches!(app.commodities().state, Fetch::Idle));
fn refresh_tab_while_loading_is_noop() {
app.accounts_mut().state = Fetch::Loading { id: 7 };
// A fetch is in flight — refresh must not reset it or submit again.
assert!(matches!(app.accounts().state, Fetch::Loading { id: 7 }));