The headless forecast test failed from 2026-10-16 on because the panel read the real clock while its fixture fixes the time. - App: PanelWindow takes an optional TimeProvider (the system clock by default) and passes it to the pace bar, burn-up, peak and usage charts and every forecast label. The burn-up chart uses the panel's render time as now. - Tests: headless panels run on a fixed clock at fixture time, with a check before, at and after the forecast start. App and Core tests with fixed-date Claude events pin HistoryStore's clock, so the 60-day retention cannot drop them later. Closes #11
128 lines
5.6 KiB
C#
128 lines
5.6 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, new FixedClock());
|
|
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));
|
|
}
|
|
|
|
}
|
|
|
|
internal sealed class FixedClock(DateTimeOffset? now = null) : TimeProvider
|
|
{
|
|
public DateTimeOffset UtcNow { get; set; } = now ?? new(2026, 10, 14, 18, 0, 0, TimeSpan.Zero);
|
|
public override DateTimeOffset GetUtcNow() => UtcNow;
|
|
public override TimeZoneInfo LocalTimeZone { get; } = TimeZoneInfo.CreateCustomTimeZone("Fixture+02", TimeSpan.FromHours(2), "Fixture", "Fixture");
|
|
}
|