1
use num_rational::Rational64;
2
use server::command::report::view::{AmountView, BreakdownPeriodView, BreakdownRowView};
3

            
4
use super::*;
5

            
6
8
fn row(tag: &str, amount: i64) -> BreakdownRowView {
7
8
    BreakdownRowView {
8
8
        tag_value: tag.to_string(),
9
8
        is_uncategorized: false,
10
8
        amounts: vec![AmountView {
11
8
            commodity_symbol: "USD".to_string(),
12
8
            amount: Rational64::new(amount, 1),
13
8
        }],
14
8
    }
15
8
}
16

            
17
4
fn period(label: &str) -> BreakdownPeriodView {
18
4
    BreakdownPeriodView {
19
4
        label: label.to_string(),
20
4
        rows: vec![row("food", 400), row("rent", 1200)],
21
4
    }
22
4
}
23

            
24
3
fn breakdown(periods: &[BreakdownPeriodView], kind: ChartKind) -> ChartSpec {
25
3
    breakdown_chart(periods, BreakdownChartOpts { kind, top_n: 10 }).expect("chart")
26
3
}
27

            
28
#[test]
29
1
fn a_flat_category_breakdown_is_horizontal() {
30
1
    let spec = breakdown(&[period("")], ChartKind::Bar);
31
1
    assert_eq!(spec.kind, ChartKind::HBar);
32
1
}
33

            
34
#[test]
35
1
fn a_category_breakdown_by_period_stays_vertical() {
36
1
    let spec = breakdown(&[period("2026-01"), period("2026-02")], ChartKind::Bar);
37
1
    assert_eq!(spec.kind, ChartKind::Bar);
38
1
}
39

            
40
#[test]
41
1
fn an_explicit_other_shape_is_kept_for_a_flat_breakdown() {
42
1
    let spec = breakdown(&[period("")], ChartKind::Line);
43
1
    assert_eq!(spec.kind, ChartKind::Line);
44
1
}
45

            
46
#[test]
47
1
fn balance_and_activity_are_not_horizontal() {
48
1
    let balance = balance_chart(
49
1
        &[],
50
1
        BalanceChartOpts {
51
1
            kind: ChartKind::Bar,
52
1
            top_n: 10,
53
1
            sort_order: SortOrder::MagnitudeDesc,
54
1
        },
55
1
    );
56
1
    let activity = activity_chart(
57
1
        &[],
58
1
        ActivityChartOpts {
59
1
            kind: ChartKind::Bar,
60
1
            include_net: true,
61
1
        },
62
1
    );
63
1
    assert_eq!(balance.kind, ChartKind::Bar);
64
1
    assert_eq!(activity.kind, ChartKind::Bar);
65
1
}