Lines
98.11 %
Functions
100 %
Branches
//! Edit forms load UUID cells: the select shows the option label and
//! submits the id.
use super::edit::{
BANK, CASH, EUR, FOOD, PAYLOAD, USD, deliver_options, options_wire, payload_of, top_form,
wire_of,
};
use crate::app::App;
use crate::route::FormOptionsSource;
use crate::widgets::Widget;
fn open(accounts: &[(&str, &str)]) -> (App, String) {
let payload = PAYLOAD.to_string();
let mut app = crate::test_support::app();
app.form_options_seq.advance();
app.deliver_transaction_edit_reply(
Some(app.window_of(crate::view::ViewId::Transactions)),
&wire_of(&payload),
);
deliver_options(
&mut app,
FormOptionsSource::FormAccounts,
&options_wire(accounts),
let commodities = options_wire(&[(USD, "USD"), (EUR, "EUR")]);
deliver_options(&mut app, FormOptionsSource::FormCommodities, &commodities);
(app, payload)
}
fn from_label(app: &App) -> String {
let Widget::Splits(sw) = &top_form(app).fields[3].widget else {
panic!("field 2 must be Splits");
sw.rows()[0].from.display().to_string()
const ALL: [(&str, &str); 3] = [
(CASH, "Assets:Cash"),
(FOOD, "Expenses:Food"),
(BANK, "Assets:Bank"),
];
#[test]
fn a_loaded_id_shows_its_option_label_and_submits_unchanged() {
let (app, payload) = open(&ALL);
assert_eq!(from_label(&app), "Assets:Cash");
assert_eq!(payload_of(&top_form(&app).values()), payload);
fn a_loaded_id_is_never_shown_before_the_options_arrive() {
let shown = from_label(&app);
assert!(!shown.contains(CASH), "{shown}");
fn a_renamed_entity_shows_its_current_label_and_keeps_its_id() {
let renamed = [
(CASH, "Assets:Wallet"),
(BANK, "Cash ‹550e›"),
let (app, payload) = open(&renamed);
assert_eq!(from_label(&app), "Assets:Wallet");
fn an_id_missing_from_the_options_falls_back_to_the_id_and_submits_unchanged() {
let (app, payload) = open(&ALL[1..]);
assert_eq!(from_label(&app), format!("{CASH} (unchanged)"));