Lines
100 %
Functions
Branches
use super::*;
use num_rational::Rational64;
use server::command::report::view::BreakdownRowView;
fn row(name: &str, amounts: &[(&str, i64)]) -> BreakdownRowView {
BreakdownRowView {
tag_value: name.to_string(),
is_uncategorized: false,
amounts: amounts
.iter()
.map(|(s, v)| AmountView {
commodity_symbol: (*s).to_string(),
amount: Rational64::from_integer(*v),
})
.collect(),
}
fn labels(cards: &[SummaryCard]) -> Vec<&str> {
cards
.filter(|c| !c.highlight)
.map(|c| c.label.as_str())
.collect()
#[test]
fn top_cards_follow_the_report_row_order() {
let periods = vec![BreakdownPeriodView {
label: String::new(),
rows: vec![row("small", &[("USD", 1)]), row("big", &[("USD", 100)])],
}];
assert_eq!(labels(&breakdown_summary(&periods, 2)), ["small", "big"]);
assert_eq!(labels(&breakdown_summary(&periods, 1)), ["small"]);
fn cards_sum_a_category_across_periods_in_first_seen_order() {
let period = |rows| BreakdownPeriodView {
rows,
};
let periods = vec![
period(vec![row("a", &[("USD", 60)]), row("b", &[("USD", -50)])]),
period(vec![row("b", &[("USD", -40)])]),
];
let cards = breakdown_summary(&periods, 2);
assert_eq!(labels(&cards), ["a", "b"]);
assert_eq!(cards[2].amounts[0].amount, Rational64::from_integer(-90));