Lines
0 %
Functions
Branches
100 %
//! Re-picking a commodity and the fills that outlive their pick.
mod common;
use common::{
FIXTURE, cell, focus, mount, open, press, reference, set_reference, type_text, until,
};
use wasm_bindgen::JsValue;
use wasm_bindgen_test::*;
use web_sys::{HtmlFormElement, HtmlInputElement};
wasm_bindgen_test_configure!(run_in_browser);
fn to_amount_disabled(form: &HtmlFormElement) -> Result<bool, JsValue> {
Ok(cell(form, "splits.1.to-amount")?.disabled())
}
/// Pick `text` from the already cached options without yielding to the event loop.
fn pick_now(input: &HtmlInputElement, text: &str) -> Result<(), JsValue> {
type_text(input, text)?;
focus(input)?;
press(input, "Enter")
/// The to-commodity as a loaded cell carries it: the text in both inputs.
fn load_to_commodity(form: &HtmlFormElement, text: &str) -> Result<HtmlInputElement, JsValue> {
set_reference(form, "splits.1.to-commodity", text, text)?;
let to = cell(form, "splits.1.to-commodity")?;
common::fire(&to, "change")?;
Ok(to)
#[wasm_bindgen_test]
async fn re_picking_the_from_commodity_hides_the_to_amount() -> Result<(), JsValue> {
let (host, form) = mount(FIXTURE)?;
let to = load_to_commodity(&form, "EUR")?;
until(|| !to_amount_disabled(&form).unwrap_or(true)).await?;
open(&to, "usd").await?;
press(&to, "Enter")?;
assert_eq!(to.value(), "USD");
assert_eq!(
reference(&form, "splits.1.to-commodity")?.value(),
"com-usd"
);
assert!(to_amount_disabled(&form)?);
host.remove();
Ok(())
async fn an_id_and_a_name_of_one_commodity_are_the_same() -> Result<(), JsValue> {
let to = reference(&form, "splits.1.to-commodity")?;
to.set_value("com-usd");
until(|| to_amount_disabled(&form).unwrap_or(false)).await?;
to.set_value("com-eur");
assert!(!to_amount_disabled(&form)?);
async fn a_superseded_account_pick_does_not_fill_its_commodity() -> Result<(), JsValue> {
let from = cell(&form, "splits.1.from")?;
let commodity = cell(&form, "splits.1.from-commodity")?;
open(&from, "wallet").await?;
common::fire(&from, "focusout")?;
set_reference(&form, "splits.1.from-commodity", "", "")?;
pick_now(&from, "cash:usd")?;
pick_now(&from, "wallet")?;
until(|| commodity.value() == "EUR").await?;
common::tick().await?;
assert_eq!(from.value(), "Assets:Wallet");
assert_eq!(commodity.value(), "EUR");
async fn a_superseded_pick_leaves_the_commodity_empty_when_the_last_has_none() -> Result<(), JsValue>
{
pick_now(&from, "food")?;
assert_eq!(from.value(), "Expenses:Food");
assert_eq!(commodity.value(), "");