Lines
100 %
Functions
Branches
//! Transaction delete: confirm dispatches `delete-transaction`; the reply
//! refreshes the list or reports the failure.
use crate::app::App;
use crate::event::{Intent, apply};
use crate::modal::{ConfirmAction, Modal};
use crate::route::{Route, RouteCtx};
use crate::tabs::fetch::Fetch;
use crate::view::{Tab, ViewId};
use cli_core::render::ListRow;
const UUID: &str = "550e8400-e29b-41d4-a716-446655440016";
fn delete_route(app: &App) -> Route {
Route {
target: Some(app.window_of(ViewId::Transactions)),
ctx: RouteCtx::Mutation {
refresh: ViewId::Transactions,
},
}
#[tokio::test]
async fn confirm_yes_dispatches_delete_transaction_and_success_reloads_the_list() {
let mut app = crate::test_support::app();
let sent = app.attach_echo();
app.transactions_mut().state = Fetch::Loaded(vec![ListRow {
id: Some(UUID.to_string()),
cells: vec!["2024-06-01".to_string()],
}]);
app.switch_tab(Tab::Transactions);
app.open_dialog_on_front(Modal::Confirm {
focus: None,
prompt: format!("Delete {UUID}?"),
action: ConfirmAction::DeleteTransaction(UUID.to_string()),
});
apply(&mut app, Intent::ConfirmYes);
assert_eq!(app.pending_routes.len(), 1, "the delete is in flight");
tokio::task::yield_now().await;
app.drain_eval();
let echoed = sent.frames().join("\n");
assert!(
echoed.contains(&format!(r#"(delete-transaction "{UUID}")"#)),
"frame: {echoed}"
);
let id = *app.pending_routes.keys().next().expect("route");
app.route_reply(id, &format!(r#"(:id {id} :value "t")"#));
matches!(app.transactions().state, Fetch::Loading { .. }),
"a successful delete reloads the transactions list"
#[test]
fn a_rejected_delete_reports_the_failure() {
app.pending_routes.insert(7, delete_route(&app));
app.route_reply(
7,
r#"(:id 7 :error (:code not-found :message "Transaction not found"))"#,
app.status.contains("Transaction not found"),
"{}",
app.status
async fn single_delete_of_marked_row() -> (crate::app::App, i64) {
app.attach_echo();
assert!(app.transactions_mut().toggle_mark());
(app, id)
async fn a_failed_single_delete_keeps_the_mark() {
let (mut app, id) = single_delete_of_marked_row().await;
assert_eq!(
app.transactions().marked_ids(),
[UUID],
"kept while in flight"
id,
&format!(r#"(:id {id} :error (:code busy :message "try later"))"#),
assert_eq!(app.transactions().marked_ids(), [UUID]);
async fn a_successful_single_delete_drops_the_mark() {
app.route_reply(id, &format!("(:id {id} :value t)"));
assert!(app.transactions().marked_ids().is_empty());