1
use super::*;
2
use crate::form_render::fixture::assert_fixture;
3
use rpc::forms::FormOption;
4

            
5
2
fn usd() -> FormOption {
6
2
    FormOption {
7
2
        id: Uuid::from_u128(1),
8
2
        label: "USD".to_string(),
9
2
        alias: "USD".to_string(),
10
2
        path: "USD".to_string(),
11
2
        commodity: None,
12
2
    }
13
2
}
14

            
15
4
fn values(pairs: &[(&str, &str)]) -> FormValues {
16
4
    let pairs: Vec<(String, String)> = pairs
17
4
        .iter()
18
2
        .map(|(name, value)| (name.to_string(), value.to_string()))
19
        .collect();
20
4
    FormValues::from_pairs(&CONVERT, pairs).expect("decodes")
21
4
}
22

            
23
#[test]
24
2
fn the_converted_amount_is_exact_and_named_by_the_target_symbol() {
25
2
    let references = References {
26
2
        commodities: vec![usd()],
27
2
        ..References::default()
28
2
    };
29
2
    let values = values(&[("to", &Uuid::from_u128(1).to_string())]);
30
2
    let shown = converted(Rational64::new(3, 8), &values, &references);
31
2
    assert_eq!(shown.amount, "0.375");
32
2
    assert_eq!(shown.symbol, "USD");
33
2
}
34

            
35
#[test]
36
2
fn an_unknown_target_leaves_the_symbol_empty() {
37
2
    let shown = converted(Rational64::new(1, 3), &values(&[]), &References::default());
38
2
    assert_eq!(shown.amount, "1/3");
39
2
    assert_eq!(shown.symbol, "");
40
2
}
41

            
42
#[test]
43
2
fn the_browser_fixture_of_the_convert_form_is_up_to_date() {
44
2
    let html = render(&FormValues::default(), &[], &References::default()).expect("renders");
45
2
    assert_fixture("commodity_convert.html", &html);
46
2
}