Lines
90.22 %
Functions
86.67 %
Branches
100 %
//! A loaded or picked cell keeps the entity it carries: retyped text the
//! wasm never saw is refused by the server, and tabbing through a loaded
//! cell after its name moved to another entity does not rebind it, even
//! when its text was edited and put back.
use std::time::Duration;
use anyhow::{Result, anyhow, ensure};
use server::command::account::SetAccountTag;
use server::command::{CmdResult, FinanceEntity, account::CreateAccount};
use uuid::Uuid;
use super::checks::check_page;
use super::driver::{BACKSPACE, TAB};
use super::harness::{Harness, with_harness};
use super::page::{Pick, login, open, pick, reference, reply_id, submit, visible};
use super::rows::{Split, fill_splits, named};
use super::store::snapshot;
/// Creates Suica → JR through the page and opens its edit page.
async fn edit_page(h: &Harness) -> Result<Uuid> {
login(h).await?;
open(h, "/transaction/new").await?;
fill_splits(h, &[Split::plain("Suica", "JR", "199")]).await?;
let reply = submit(h).await?;
ensure!(reply.contains("created with ID"), "{reply}");
let id = reply_id(&reply)?;
open(h, &format!("/transaction/{id}/edit")).await?;
Ok(id)
}
async fn retyped_without_wasm(h: &Harness) -> Result<()> {
let id = edit_page(h).await?;
let before = snapshot(h, id).await?;
pick(h, "splits.0.to", "McD", named("McDonalds"), 0, Pick::Mouse).await?;
h.driver
.run(
"document.querySelector('input[name=\"label:splits.0.to\"]').value = 'Wallet';",
vec![],
)
.await?;
ensure!(
reply.contains("pick an entry from the list"),
"a retyped cell was saved: {reply}"
);
let (shown, _) = reference(h, "splits.0.to").await?;
ensure!(shown == "Wallet", "the typed text is lost: {shown:?}");
check_page(h, "edit-retyped-refused", &[422]).await?;
let after = snapshot(h, id).await?;
ensure!(after == before, "the refused edit changed the transaction");
Ok(())
#[supp_macro::shared_runtime_test]
async fn a_retyped_cell_the_wasm_never_saw_is_refused() -> Result<()> {
with_harness(|h| Box::pin(retyped_without_wasm(h))).await
async fn rename_jr_and_reuse_its_name(h: &Harness) -> Result<Uuid> {
SetAccountTag::new()
.user_id(h.tenant.id)
.account_id(h.account("JR"))
.tag_name("name".to_string())
.tag_value("JR East".to_string())
.run()
.await
.map_err(|e| anyhow!("{e:?}"))?;
let created = CreateAccount::new()
.name("JR".to_string())
match created {
Some(CmdResult::Entity(FinanceEntity::Account(account))) => Ok(account.id),
other => Err(anyhow!("expected an account, got {other:?}")),
async fn tab_through_after_reuse(h: &Harness) -> Result<()> {
let (_, loaded) = reference(h, "splits.0.to").await?;
let impostor = rename_jr_and_reuse_its_name(h).await?;
let to = visible(h, "splits.0.to").await?;
h.driver.click(&to).await?;
.type_into(&to, &format!("x{BACKSPACE}{TAB}"))
tokio::time::sleep(Duration::from_secs(1)).await;
let (_, carried) = reference(h, "splits.0.to").await?;
carried == loaded,
"tabbing rebound the cell from {loaded:?} to {carried:?}"
let stale = submit(h).await?;
stale.contains("pick an entry from the list"),
"a stale label was saved: {stale}"
snapshot(h, id).await? == before,
"the refused edit changed the transaction"
let (shown, reloaded) = reference(h, "splits.0.to").await?;
shown == "JR East" && reloaded == loaded,
"{shown:?} {reloaded:?}"
ensure!(reply.contains("updated with ID"), "{reply}");
!after
.iter()
.any(|fact| fact.contains(&impostor.to_string())),
"the edit moved the split to the account that took the name: {after:#?}"
ensure!(after == before, "{before:#?}\n{after:#?}");
async fn tabbing_through_a_loaded_cell_keeps_its_entity_after_a_rename() -> Result<()> {
with_harness(|h| Box::pin(tab_through_after_reuse(h))).await