Redesign the stats panel after the developer's feedback on v1 and add limit forecasts, daily week use and token-based estimates (D7, D8). - Panel: a fixed header with range and provider controls, limit tiles with pace chips, meters and forecasts, week use per day, token KPIs and charts, one burn-up chart per limit window with past instances, and a sortable breakdown whose "Other" row expands. One tooltip component for every chart, tile and table. - Core (D7): average and recent-rate forecasts, the reach date whenever use is over pace, days of a long window with even pace and daily budget, window instances derived from resets with a 15-minute tolerance, and estimates from price-weighted tokens where samples are missing. Forecasts start at 10 % of a window, or as soon as it is ahead, so a Codex week far ahead right after its reset warns too. - Settings, popups and the version (1.1.0) follow the new design. Closes #5 Closes #7
126 lines
5.5 KiB
C#
126 lines
5.5 KiB
C#
using System.Globalization;
|
|
using Xunit;
|
|
|
|
namespace FinalToken.App.Tests;
|
|
|
|
public sealed class FormattingTests
|
|
{
|
|
[Theory]
|
|
[InlineData(6000000000, "6 B")]
|
|
[InlineData(2000000000, "2 B")]
|
|
[InlineData(1500000000, "1,5 B")]
|
|
[InlineData(600000000, "600 M")]
|
|
[InlineData(82500, "82,5 K")]
|
|
[InlineData(0, "0")]
|
|
public void AxisNumbersDropTrailingZerosWithoutChangingCompactValues(double value, string expected)
|
|
{
|
|
var previous = CultureInfo.CurrentCulture;
|
|
try
|
|
{
|
|
CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("de-DE");
|
|
Assert.Equal(expected, Display.Axis(value));
|
|
Assert.Equal("2,00 B", Display.Compact(2000000000));
|
|
}
|
|
finally { CultureInfo.CurrentCulture = previous; }
|
|
}
|
|
[Theory]
|
|
[InlineData(292950000, "293 M")]
|
|
[InlineData(2300000000, "2,30 B")]
|
|
[InlineData(966690000, "967 M")]
|
|
[InlineData(82500, "82,5 K")]
|
|
[InlineData(999950, "1,00 M")]
|
|
[InlineData(0, "0")]
|
|
public void CompactNumbersUseThreeSignificantDigits(double value, string expected)
|
|
{
|
|
var previous = CultureInfo.CurrentCulture;
|
|
try { CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("de-DE"); Assert.Equal(expected, Display.Compact(value)); }
|
|
finally { CultureInfo.CurrentCulture = previous; }
|
|
}
|
|
[Theory]
|
|
[InlineData(FinalToken.Core.PaceState.Ahead, true)]
|
|
[InlineData(FinalToken.Core.PaceState.OnTrack, false)]
|
|
[InlineData(FinalToken.Core.PaceState.Behind, false)]
|
|
[InlineData(FinalToken.Core.PaceState.Unknown, false)]
|
|
public void ForecastWarningFollowsState(FinalToken.Core.PaceState state, bool warning)
|
|
{
|
|
var text = Display.Forecast(new(2026, 10, 18, 14, 43, 0, TimeSpan.Zero), state);
|
|
Assert.Equal(warning, text.Contains('⚠'));
|
|
Assert.StartsWith(warning ? "⚠ 100 % on " : "At this pace 100 % on ", text);
|
|
}
|
|
[Theory]
|
|
[InlineData(1)]
|
|
[InlineData(1.25)]
|
|
[InlineData(2)]
|
|
public void DenseBarEdgesMeetOnPhysicalPixelsWithoutGaps(double scaling)
|
|
{
|
|
var first = UsageChart.BarBounds(50.13, 100, 3.17, 40, scaling);
|
|
var next = UsageChart.BarBounds(53.30, 100, 3.17, 40, scaling);
|
|
Assert.Equal(first.Right, next.Left, 6);
|
|
Assert.Equal(Math.Round(first.Left * scaling), first.Left * scaling, 6);
|
|
Assert.Equal(Math.Round(first.Right * scaling), first.Right * scaling, 6);
|
|
}
|
|
[Fact]
|
|
public void DailyChartLabelAndTooltipUseTheBucketsLocalDate()
|
|
{
|
|
var zone = TimeZoneInfo.CreateCustomTimeZone("Fixture+02", TimeSpan.FromHours(2), "Fixture", "Fixture");
|
|
var day = FinalToken.Core.CalendarDays.Start(new DateTimeOffset(2026, 10, 14, 12, 0, 0, TimeSpan.Zero), zone);
|
|
Assert.Equal("10-14", Display.ChartDateLabel(day, TimeSpan.FromDays(1)));
|
|
Assert.Equal(day.DateTime.ToString("d"), Display.ChartTimestamp(day, TimeSpan.FromDays(1)));
|
|
}
|
|
[Theory]
|
|
[InlineData(null)]
|
|
[InlineData("")]
|
|
[InlineData("custom-config")]
|
|
public void LinuxAutostartHonorsConfigHome(string? configHome)
|
|
{
|
|
var home = Path.Combine(Path.GetTempPath(), "fixture-home");
|
|
var config = string.IsNullOrEmpty(configHome) ? null : Path.Combine(Path.GetTempPath(), configHome);
|
|
Assert.Equal(Path.Combine(config ?? Path.Combine(home, ".config"), "autostart", "finaltoken.desktop"), OsStartup.LinuxAutostartPath(config, home));
|
|
}
|
|
[Theory]
|
|
[InlineData("de-DE")]
|
|
[InlineData("en-US")]
|
|
public void FutureProjectionIncludesLocalDateInUsersCulture(string culture)
|
|
{
|
|
var clock = new FixedClock();
|
|
var projection = new DateTimeOffset(2026, 10, 16, 6, 24, 0, TimeSpan.Zero);
|
|
var userCulture = CultureInfo.GetCultureInfo(culture);
|
|
Assert.Equal(new DateTime(2026, 10, 16, 8, 24, 0).ToString("g", userCulture), Display.Projection(projection, clock, userCulture));
|
|
}
|
|
[Fact]
|
|
public void TodaysProjectionUsesLocalTimeOnly()
|
|
{
|
|
Assert.Equal("23:24", Display.Projection(new(2026, 10, 14, 21, 24, 0, TimeSpan.Zero), new FixedClock(), CultureInfo.GetCultureInfo("de-DE")));
|
|
}
|
|
[Fact]
|
|
public void ProjectionDateChangesAtLocalMidnight()
|
|
{
|
|
Assert.Equal("15.10.2026 00:24", Display.Projection(new(2026, 10, 14, 22, 24, 0, TimeSpan.Zero), new FixedClock(), CultureInfo.GetCultureInfo("de-DE")));
|
|
}
|
|
[Theory]
|
|
[InlineData(0, new double[] { 0 })]
|
|
[InlineData(1, new double[] { 0, 1 })]
|
|
[InlineData(2, new double[] { 0, 1, 2 })]
|
|
[InlineData(3, new double[] { 0, 1, 2, 3 })]
|
|
public void SmallChartTicksAreDistinctIntegers(double maximum, double[] expected)
|
|
=> Assert.Equal(expected, UsageChart.AxisTicks(maximum));
|
|
[Theory]
|
|
[InlineData(5, new double[] { 0, 2, 4, 6 })]
|
|
[InlineData(17, new double[] { 0, 5, 10, 15, 20 })]
|
|
[InlineData(123456, new double[] { 0, 50000, 100000, 150000 })]
|
|
public void LargerChartTicksUseRoundedStepsAndCoverMaximum(double maximum, double[] expected)
|
|
=> Assert.Equal(expected, UsageChart.AxisTicks(maximum));
|
|
[Fact]
|
|
public void PercentTicksKeepQuarterMarksAndEmptyPercentChartHasOnlyZero()
|
|
{
|
|
Assert.Equal([0d, 25, 50, 75, 100], UsageChart.AxisTicks(3, true));
|
|
Assert.Equal([0d], UsageChart.AxisTicks(0, true));
|
|
}
|
|
|
|
private sealed class FixedClock : TimeProvider
|
|
{
|
|
public override DateTimeOffset GetUtcNow() => new(2026, 10, 14, 18, 0, 0, TimeSpan.Zero);
|
|
public override TimeZoneInfo LocalTimeZone { get; } = TimeZoneInfo.CreateCustomTimeZone("Fixture+02", TimeSpan.FromHours(2), "Fixture", "Fixture");
|
|
}
|
|
}
|