Lines
100 %
Functions
Branches
//! The lazy row detail and delete of the list page (plan 0016 W7).
use axum::http::{StatusCode, header};
use crate::common::create_mock_user;
use crate::common::list_page::{add, delete, detail, list};
use crate::common::new_page::seeded_user;
use crate::common::seed::{commodity_with_name, named_account};
use crate::common::tenant::provision_tenant;
#[supp_macro::shared_runtime_test]
async fn the_list_carries_no_splits_but_a_lazy_detail_link() {
let user = seeded_user().await;
let id = add(
&user,
"2020-01-10T10:00:00Z",
"lunch",
"Expenses:Food",
"12.5",
)
.await;
let page = list(&user, "").await;
let body = &page.body;
assert!(!body.contains("<table class=\"splits-table\">"), "{body}");
assert_eq!(body.matches("hx-trigger=\"toggle once\"").count(), 1);
assert!(body.contains(&format!("hx-get=\"/api/transaction/detail/{id}\"")));
assert!(body.contains(&format!("href=\"/transaction/{id}/edit\"")));
assert!(body.contains("12.5"), "{body}");
}
async fn the_detail_fragment_shows_splits_with_exact_amounts_and_tags() {
"1/3",
let reply = detail(&user, &id.to_string()).await;
assert_eq!(reply.status, StatusCode::OK, "{}", reply.body);
let body = &reply.body;
assert!(body.contains("Assets:Checking"), "{body}");
assert!(body.contains("Expenses:Food"), "{body}");
assert_eq!(body.matches("1/3").count(), 2, "{body}");
assert_eq!(body.matches("USD").count(), 2, "{body}");
assert!(body.contains("memo: lunch"), "{body}");
assert!(!body.contains("<html"), "{body}");
async fn the_detail_of_a_missing_or_foreign_id_is_not_found() {
let owner = seeded_user().await;
let stranger = seeded_user().await;
&owner,
"5",
let foreign = detail(&stranger, &id.to_string()).await;
let missing = detail(&owner, &uuid::Uuid::new_v4().to_string()).await;
let malformed = detail(&owner, "nope").await;
assert_eq!(foreign.status, StatusCode::NOT_FOUND);
assert_eq!(missing.status, StatusCode::NOT_FOUND);
assert_eq!(malformed.status, StatusCode::BAD_REQUEST);
async fn a_listed_delete_asks_first_posts_and_redirects_back() {
let id = add(&user, "2020-01-10T10:00:00Z", "lunch", "Expenses:Food", "5").await;
let removed = delete(&user, &id.to_string()).await;
let after = list(&user, "").await;
let again = delete(&user, &id.to_string()).await;
let form = page
.body
.split("class=\"delete-form\"")
.nth(1)
.and_then(|tail| tail.split("</form>").next())
.expect("a delete form");
assert!(form.contains("method=\"post\""), "{form}");
assert!(form.contains(&format!("action=\"/api/transaction/delete/{id}\"")));
assert!(form.contains("onsubmit=\"return confirm("), "{form}");
assert!(removed.status.is_redirection(), "{}", removed.status);
assert_eq!(removed.headers[header::LOCATION], "/transaction/list");
assert!(!after.body.contains("lunch"));
assert_eq!(again.status, StatusCode::NOT_FOUND);
async fn a_split_tag_name_with_two_values_shows_both() {
let server_user = server::user::User { id: user.id };
let splits = server_user
.get_transaction_splits(id)
.await
.expect("splits");
for split in &splits {
server_user
.create_split_tag(split.id, "memo".into(), "second".into(), None)
.expect("second value");
assert!(reply.body.contains("memo: lunch"), "{}", reply.body);
assert!(reply.body.contains("memo: second"), "{}", reply.body);
async fn the_amount_column_shows_the_commodity_symbol_not_its_name() {
let user = create_mock_user();
provision_tenant(user.id).await;
commodity_with_name(user.id, "USD", "US Dollar").await;
named_account(user.id, "Assets:Checking").await;
named_account(user.id, "Expenses:Food").await;
assert!(reply.body.contains("USD"), "{}", reply.body);
assert!(!reply.body.contains("US Dollar"), "{}", reply.body);
assert!(reply.body.contains("Assets:Checking"), "{}", reply.body);