using Avalonia.Controls;
using Avalonia.LogicalTree;
using StarterNG.Application;
using StarterNG.Domain.Tapes;
using StarterNG.Tests.Fakes;
using StarterNG.Views.Tapes;
namespace StarterNG.Tests;
/// The tapes' window over the tapes of an installation of its own, read as it is opened.
[Collection(AvaloniaControls.Name)]
public class HaslerTapeWindowTests
{
private static readonly DateTime Launched = new(2025, 12, 31, 23, 0, 0, DateTimeKind.Utc);
static HaslerTapeWindowTests() => HeadlessDrawing.Ensure();
private static AppServices Services(InMemoryFileSystem files)
{
var installation = new TestInstallation(files);
installation.Clock.Now = Launched;
return AppServices.Initialize(installation.Paths, installation.Files, installation.Clock, installation.Environment);
}
// The window reads the tapes off the UI thread and shows them on it: what it shows is waited for.
private static void Until(Func shown) =>
Assert.True(SpinWait.SpinUntil(() =>
{
Controls.Settle();
return shown();
}, TimeSpan.FromSeconds(5)));
private static Button Button(Window window, string key) =>
window.GetLogicalDescendants().OfType