app: date far projections and give charts distinct axis ticks
The popup showed only the time of a projection two days away, which read as today; the popup and the panel now share one formatter that adds the date unless the projection is today. Chart axes used max/4 steps, which repeated labels for small or empty ranges; they now use whole 1, 2 or 5 steps and an empty chart shows only 0. Refs #1
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
using System.Globalization;
|
||||
using Xunit;
|
||||
|
||||
namespace FinalToken.App.Tests;
|
||||
|
||||
public sealed class FormattingTests
|
||||
{
|
||||
[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");
|
||||
}
|
||||
}
|
||||
@@ -82,16 +82,26 @@ public sealed class HeadlessTests
|
||||
var chartWindow = new Window { Content = chart, Width = 400, Height = 180 };
|
||||
chartWindow.Show();
|
||||
using (chartWindow.CaptureRenderedFrame()) { }
|
||||
chartWindow.MouseMove(new Point(65, 30));
|
||||
chartWindow.MouseMove(new Point(65, 80));
|
||||
Assert.Contains(123456.ToString("N0"), ToolTip.GetTip(chart)?.ToString()); chartWindow.Close();
|
||||
var polishShots = Path.Combine(root.Parent!.FullName, "runs", "shots", "w1");
|
||||
Directory.CreateDirectory(polishShots);
|
||||
var emptyChart = new Window { Content = Ui.Card(Ui.Stack(Ui.Text("Tokens per hour", 19), new UsageChart())), Width = 620, Height = 260,
|
||||
RequestedThemeVariant = ThemeVariant.Light };
|
||||
emptyChart.Show(); Save(emptyChart, "chart-empty.png", polishShots); emptyChart.Close();
|
||||
var time = new DateTimeOffset(2026, 10, 14, 12, 0, 0, TimeSpan.Zero);
|
||||
var smallChart = new Window { Content = Ui.Card(Ui.Stack(Ui.Text("Tokens per hour", 19), new UsageChart
|
||||
{ Values = [new(time, "Claude", 1), new(time.AddHours(1), "Claude", 2), new(time.AddHours(2), "Claude", 3)] })),
|
||||
Width = 620, Height = 260, RequestedThemeVariant = ThemeVariant.Light };
|
||||
smallChart.Show(); Save(smallChart, "chart-max-3.png", polishShots); smallChart.Close();
|
||||
Thread.Sleep(8200); Dispatcher.UIThread.RunJobs();
|
||||
Assert.False(first.IsVisible); Assert.False(second.IsVisible);
|
||||
completion.SetResult();
|
||||
void Save(Window window, string name)
|
||||
void Save(Window window, string name, string? destination = null)
|
||||
{
|
||||
Dispatcher.UIThread.RunJobs();
|
||||
using var bitmap = window.CaptureRenderedFrame(); Assert.NotNull(bitmap);
|
||||
using var output = File.Create(Path.Combine(shots, name)); bitmap.Save(output, PngBitmapEncoderOptions.Default);
|
||||
using var output = File.Create(Path.Combine(destination ?? shots, name)); bitmap.Save(output, PngBitmapEncoderOptions.Default);
|
||||
Assert.True(output.Length > 2000);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user