using Avalonia; using Avalonia.Controls; using Avalonia.Interactivity; using Avalonia.Styling; using Avalonia.Threading; using Avalonia.VisualTree; using FinalToken.Core; using FinalToken.Core.StreamDeck; using Xunit; namespace FinalToken.App.Tests; internal static class HiddenWindowViews { // Called by the shared headless fixture on its dedicated UI thread. public static void Verify(Action save) { var clock = new FixedClock(); var now = clock.GetUtcNow(); var all = new LimitWindow(Provider.Claude, "week (all models)", "Current week (all models)", 60, now.AddDays(3), TimeSpan.FromDays(7), now, "fixture"); var fable = all with { Id = "week (fable)", Label = "Current week (Fable)", UsedPercent = 30 }; var codex = all with { Provider = Provider.Codex, Id = "codex:primary", Label = "Week", UsedPercent = 40 }; var session = new HiddenLimitWindow("session", TimeSpan.FromHours(5), "Current session"); var snapshot = new Snapshot { MadeAt = now, RefreshInterval = TimeSpan.FromMinutes(1), Providers = [new(Provider.Claude, ProviderStatus.Available, null, [View(all), View(fable)], new(Total: 100), null, new(Total: 500), now.AddDays(-4), all.Id), new(Provider.Codex, ProviderStatus.Available, null, [View(codex)], new(Total: 200), null, new(Total: 800), now.AddDays(-4), codex.Id)] }; var initial = new Settings { Claude = new() { HiddenWindows = [HiddenLimitWindow.For(fable), session] }, Codex = new() { HiddenWindows = [HiddenLimitWindow.For(codex with { Id = "codex:secondary" })] } }; Settings? saved = null; var settings = new SettingsWindow(initial, new(PluginInstallState.NoHostFound), value => { saved = value; return Task.CompletedTask; }, snapshot: snapshot); settings.Show(); Dispatcher.UIThread.RunJobs(); Assert.NotNull(settings.Icon); var choices = settings.GetVisualDescendants().OfType().Where(c => c.Content is string text && text.StartsWith("Show ", StringComparison.Ordinal)).ToArray(); Assert.Equal(["Show Current week (all models)", "Show Current week (Fable)", "Show Current session", "Show Week"], choices.Select(c => c.Content as string)); Assert.True(choices[0].IsChecked); Assert.All(choices.Skip(1), c => Assert.False(c.IsChecked)); var viewport = settings.GetVisualDescendants().OfType().First(); foreach (var theme in new[] { ThemeVariant.Dark, ThemeVariant.Light }) { settings.RequestedThemeVariant = theme; Dispatcher.UIThread.RunJobs(); var title = settings.GetVisualDescendants().OfType().Single(t => t.Text == "Providers"); viewport.Offset = new Vector(0, viewport.Offset.Y + title.TranslatePoint(default, viewport)!.Value.Y - 16); save(settings, $"hidden-settings-providers-{theme}.png"); } choices[0].IsChecked = false; choices[1].IsChecked = true; choices[2].IsChecked = true; settings.GetVisualDescendants().OfType