using Avalonia.Controls; using Avalonia.LogicalTree; using StarterNG.Application; using StarterNG.Tests.Fakes; using StarterNG.Views; namespace StarterNG.Tests; /// The starter's questions over its window, answered with the mouse or not at all. [Collection(AvaloniaControls.Name)] public class MessageBoxTests { // The buttons are labelled in the starter's language. static MessageBoxTests() { HeadlessDrawing.Ensure(); if (AppServices.CurrentOrNull is null) { var installation = new TestInstallation(new InMemoryFileSystem()); AppServices.Initialize(installation.Paths, installation.Files, installation.Clock, installation.Environment); } } private static (Window Owner, Window Dialog, Task Answer) Choose() { var owner = new Window(); owner.Show(); var answer = MessageBox.Choose(owner, "Zapisać zmiany przed startem?", "Niezapisane zmiany", "Zapisz", "Nie zapisuj"); Controls.Settle(); return (owner, Assert.Single(owner.OwnedWindows), answer); } // The answer is given once the dialog's closing has gone through the dispatcher. private static bool? Answered(Task answer) { Assert.True(SpinWait.SpinUntil(() => { Controls.Settle(); return answer.IsCompleted; }, TimeSpan.FromSeconds(5))); return answer.Result; } private static Button[] Buttons(Window dialog) => dialog.GetLogicalDescendants().OfType