Lines
100 %
Functions
Branches
//! Text typed into a select control that picks no entity is refused at its
//! address and echoed back; it is never submitted as a name.
use axum::http::StatusCode;
use crate::common::list_page::list;
use crate::common::new_page::{input_value, post_form, seeded_ids, seeded_user};
const DATE: &str = "2026-10-27T09:15:42.123456Z";
#[supp_macro::shared_runtime_test]
async fn an_unpicked_cell_is_a_field_error_with_its_text_kept() {
let user = seeded_user().await;
let ids = seeded_ids(&user).await;
let reply = post_form(
&user,
&[
("date", DATE),
("splits", ""),
("splits.0.key", "n1"),
("splits.0.from", &ids.checking),
("label:splits.0.from", "Assets:Checking"),
("splits.0.to", ""),
("label:splits.0.to", "Expenses:Foo"),
("splits.0.from-commodity", &ids.usd),
("label:splits.0.from-commodity", "USD"),
("splits.0.to-commodity", ""),
("label:splits.0.to-commodity", ""),
("splits.0.value", "50"),
],
)
.await;
assert_eq!(
reply.status,
StatusCode::UNPROCESSABLE_ENTITY,
"{}",
reply.body
);
let html = &reply.body;
html.matches("pick an entry from the list").count(),
1,
"{html}"
assert!(!html.contains("is required"), "{html}");
assert_eq!(input_value(html, "label:splits.0.to"), Some("Expenses:Foo"));
assert_eq!(input_value(html, "splits.0.to"), Some(""));
input_value(html, "label:splits.0.from"),
Some("Assets:Checking")
}
async fn an_unpicked_list_filter_is_refused_and_an_empty_one_lists() {
let refused = list(&user, "label%3Aaccount=Bank&account=").await;
let empty = list(&user, "label%3Aaccount=&account=").await;
refused.status,
refused.body
assert!(
refused.body.contains("pick an entry from the list"),
assert_eq!(empty.status, StatusCode::OK, "{}", empty.body);
/// The id of the seeded account labelled `label`.
async fn account_id(user: &web::model::User, label: &str) -> String {
let options = rpc::forms::options(user.id, forms::Source::Accounts)
.await
.unwrap_or_default();
options
.into_iter()
.find(|option| option.label == label)
.map(|option| option.id.to_string())
.unwrap_or_default()
/// A create whose `to` carries `id` while its control shows `shown`.
async fn post_to(user: &web::model::User, id: &str, shown: &str) -> crate::common::new_page::Reply {
let ids = seeded_ids(user).await;
post_form(
user,
("splits.0.to", id),
("label:splits.0.to", shown),
async fn an_id_whose_text_was_retyped_is_refused_and_a_matching_one_kept() {
let food = account_id(&user, "Expenses:Food").await;
let retyped = post_to(&user, &food, "Assets:Checking").await;
let matching = post_to(&user, &food, "Expenses:Food").await;
assert!(!food.is_empty());
retyped.status,
retyped.body
retyped.body.matches("pick an entry from the list").count(),
input_value(&retyped.body, "label:splits.0.to"),
assert_eq!(matching.status, StatusCode::OK, "{}", matching.body);