Lines
100 %
Functions
Branches
//! The status line: a fetch error is cleared by a user action or by a success of the view
//! that failed; the error of a mutation by a user action only.
use crate::app::App;
use crate::event::{Intent, apply};
use crate::form::Form;
use crate::modal::Modal;
use crate::route::{Route, RouteCtx};
use crate::view::{Tab, ViewId};
const OK: &str = r#"(:id 7 :value "nil")"#;
const FAILED: &str = r#"(:id 7 :error (:code db :message "down"))"#;
fn expect(app: &mut App, id: i64, target: ViewId, ctx: RouteCtx) {
app.pending_routes.insert(
id,
Route {
target: Some(app.window_of(target)),
ctx,
},
);
}
fn expect_mutation(app: &mut App, id: i64, view: ViewId) {
expect(app, id, view, RouteCtx::Mutation { refresh: view });
#[test]
fn a_success_of_the_same_view_clears_its_fetch_error() {
let mut app = crate::test_support::app();
let convert = RouteCtx::ConvertQuery {
amount_str: "1".into(),
from_label: "a".into(),
to_label: "b".into(),
};
expect(&mut app, 7, ViewId::Transactions, convert);
app.route_reply(7, FAILED);
assert!(!app.status.is_empty());
expect(&mut app, 8, ViewId::Transactions, RouteCtx::None);
app.route_reply(8, &OK.replace('7', "8"));
assert_eq!(app.status, "");
fn no_reply_clears_the_error_of_a_failed_mutation() {
for ctx in [
RouteCtx::DeleteTransaction { id: "x".into() },
RouteCtx::Mutation {
refresh: ViewId::Transactions,
] {
expect(&mut app, 7, ViewId::Transactions, ctx);
let shown = app.status.clone();
assert!(shown.contains("failed"), "{shown}");
assert_eq!(app.status, shown);
fn a_success_of_another_view_keeps_the_error() {
expect_mutation(&mut app, 7, ViewId::Transactions);
expect(&mut app, 8, ViewId::Commodities, RouteCtx::None);
fn expect_dialog_mutation(app: &mut App, id: i64) {
target: None,
ctx: RouteCtx::Mutation {
fn a_dialog_error_survives_the_success_of_a_view() {
expect_dialog_mutation(&mut app, 7);
assert!(shown.starts_with("mutation failed"), "{shown}");
fn a_dialog_success_keeps_the_error_of_a_view() {
expect_dialog_mutation(&mut app, 8);
fn a_failed_reply_after_a_later_success_in_one_drain_survives() {
expect_mutation(&mut app, 5, ViewId::Transactions);
expect(&mut app, 6, ViewId::Commodities, RouteCtx::None);
app.route_reply(5, &FAILED.replace('7', "5"));
app.route_reply(6, &OK.replace('7', "6"));
assert!(app.status.starts_with("mutation failed"), "{}", app.status);
fn a_list_action_clears_the_error() {
app.switch_tab(Tab::Accounts);
app.set_status("mutation failed: down");
apply(&mut app, Intent::RefreshTab);
fn submitting_a_form_clears_the_error() {
app.overlays.push(Modal::Form(Form::config_set()));
app.set_status("submit failed: name is required");
apply(&mut app, Intent::Submit);
assert!(!app.status.starts_with("mutation"));
assert_ne!(app.status, "submit failed: name is required");
fn editing_a_form_after_a_failed_submit_keeps_the_error() {
for intent in [
Intent::InsertChar('x'),
Intent::DeleteBackward,
Intent::MoveLeft,
Intent::NextWindow,
Intent::SelectNext,
apply(&mut app, intent);
assert_eq!(app.status, "submit failed: name is required", "{intent:?}");
fn switching_tabs_clears_the_error() {
app.set_status("can't edit this transaction: reconciled");
app.switch_tab(Tab::Config);
fn a_palette_command_replaces_the_previous_error() {
app.set_status("command error: boom");
apply(&mut app, Intent::OpenCommandLine);
"nonsense"
.chars()
.for_each(|c| apply(&mut app, Intent::InsertChar(c)));
assert_eq!(app.status, "unknown command: nonsense");