The charts on both pages can be limited to a from/to year range
("Alle Jahre" resets it); periods overlapping the range are kept whole.
Period toggle, year range and split note are now one shared component
(BillChartToolbar over BillChartFilter). Both pages move into the
"Charts" group of the menu.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
85 lines
2.6 KiB
C#
85 lines
2.6 KiB
C#
using Schaad.Accounting.Models;
|
|
using Shouldly;
|
|
|
|
namespace Schaad.Accounting.Tests;
|
|
|
|
public class BillChartFilterTestShould
|
|
{
|
|
[Fact]
|
|
public void ListEveryYearFromFirstToLastBillWhenGettingYears()
|
|
{
|
|
BillChartFilter.YearsOf([YearlyBill(2025), YearlyBill(2022)]).ShouldBe([2022, 2023, 2024, 2025, 2026]);
|
|
}
|
|
|
|
[Fact]
|
|
public void ReturnNoYearsWhenThereAreNoBills()
|
|
{
|
|
BillChartFilter.YearsOf<ElectricityBill>([]).ShouldBeEmpty();
|
|
}
|
|
|
|
[Fact]
|
|
public void CoverAllYearsWhenNoYearIsSelected()
|
|
{
|
|
var filter = new BillChartFilter();
|
|
|
|
filter.RangeIn([2022, 2023, 2024]).ShouldBe((2022, 2024));
|
|
filter.CoversAll([2022, 2023, 2024]).ShouldBeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void ClampSelectedYearsWhenTheyAreOutsideTheAvailableYears()
|
|
{
|
|
var filter = new BillChartFilter(FromYear: 2019, ToYear: 2030);
|
|
|
|
filter.RangeIn([2022, 2023, 2024]).ShouldBe((2022, 2024));
|
|
}
|
|
|
|
[Fact]
|
|
public void SwapYearsWhenFromIsAfterTo()
|
|
{
|
|
var filter = new BillChartFilter(FromYear: 2024, ToYear: 2022);
|
|
|
|
filter.RangeIn([2021, 2022, 2023, 2024]).ShouldBe((2022, 2024));
|
|
}
|
|
|
|
[Fact]
|
|
public void KeepBillsOverlappingTheRangeWhenGroupingPerBill()
|
|
{
|
|
var filter = new BillChartFilter(BillPeriodKind.Bill, 2024, 2024);
|
|
|
|
var periods = filter.Apply([YearlyBill(2022), YearlyBill(2023), YearlyBill(2024), YearlyBill(2025)]);
|
|
|
|
periods.Select(p => p.Label).ShouldBe(["23/24", "24/25"]);
|
|
}
|
|
|
|
[Fact]
|
|
public void KeepOnlyPeriodsInsideTheRangeWhenGroupingPerHalfYear()
|
|
{
|
|
var filter = new BillChartFilter(BillPeriodKind.HalfYear, 2024, 2024);
|
|
|
|
var periods = filter.Apply([YearlyBill(2023), YearlyBill(2024)]);
|
|
|
|
periods.Select(p => p.Label).ShouldBe(["H1 24", "H2 24"]);
|
|
}
|
|
|
|
[Fact]
|
|
public void KeepEmptyPeriodsInsideTheRangeWhenNoBillCoversThem()
|
|
{
|
|
var filter = new BillChartFilter(BillPeriodKind.Year, 2023, 2025);
|
|
|
|
var periods = filter.Apply([Bill(new DateOnly(2022, 1, 1), new DateOnly(2022, 12, 31)), Bill(new DateOnly(2026, 1, 1), new DateOnly(2026, 12, 31))]);
|
|
|
|
periods.Select(p => p.Label).ShouldBe(["2023", "2024", "2025"]);
|
|
periods.ShouldAllBe(p => p.Bill == null);
|
|
}
|
|
|
|
[Fact]
|
|
public void ReturnNoPeriodsWhenThereAreNoBills()
|
|
{
|
|
new BillChartFilter().Apply<WaterBill>([]).ShouldBeEmpty();
|
|
}
|
|
|
|
private static ElectricityBill YearlyBill(int startYear) => Bill(new DateOnly(startYear, 7, 1), new DateOnly(startYear + 1, 6, 30));
|
|
|
|
private static ElectricityBill Bill(DateOnly from, DateOnly to) => new() { PeriodFrom = from, PeriodTo = to };
|
|
}
|