Lines
100 %
Functions
Branches
use super::*;
use crate::form_render::fixture::assert_fixture;
use rpc::forms::FormOption;
fn usd() -> FormOption {
FormOption {
id: Uuid::from_u128(1),
label: "USD".to_string(),
alias: "USD".to_string(),
path: "USD".to_string(),
commodity: None,
}
fn values(pairs: &[(&str, &str)]) -> FormValues {
let pairs: Vec<(String, String)> = pairs
.iter()
.map(|(name, value)| (name.to_string(), value.to_string()))
.collect();
FormValues::from_pairs(&CONVERT, pairs).expect("decodes")
#[test]
fn the_converted_amount_is_exact_and_named_by_the_target_symbol() {
let references = References {
commodities: vec![usd()],
..References::default()
};
let values = values(&[("to", &Uuid::from_u128(1).to_string())]);
let shown = converted(Rational64::new(3, 8), &values, &references);
assert_eq!(shown.amount, "0.375");
assert_eq!(shown.symbol, "USD");
fn an_unknown_target_leaves_the_symbol_empty() {
let shown = converted(Rational64::new(1, 3), &values(&[]), &References::default());
assert_eq!(shown.amount, "1/3");
assert_eq!(shown.symbol, "");
fn the_browser_fixture_of_the_convert_form_is_up_to_date() {
let html = render(&FormValues::default(), &[], &References::default()).expect("renders");
assert_fixture("commodity_convert.html", &html);