using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Automation.Peers; using Microsoft.UI.Xaml.Automation.Provider; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Media; namespace XFEWarframe.Desktop.Editing; /// Runs only from the opt-in, isolated --verify-ui harness. internal static class DialogVerification { internal static int CompletedCount { get; private set; } internal static IEnumerable Children(DependencyObject root) where T : DependencyObject { if (root is T match) yield return match; for (var i = 0; i < VisualTreeHelper.GetChildrenCount(root); i++) foreach (var item in Children(VisualTreeHelper.GetChild(root, i))) yield return item; } internal static async Task RunAsync(FormDialogButton launcher, Action? fill = null, string buttonName = "CloseButton") { if (launcher.Form is null) throw new InvalidOperationException("Missing dialog form."); if (launcher.CornerRadius.TopLeft != 8 || launcher.MinHeight != 40) throw new InvalidOperationException("The form button did not inherit the shared Fluent style."); if (VisualTreeHelper.GetParent(launcher.Form) is not null) throw new InvalidOperationException("A form is still displayed inline."); var operation = launcher.OpenAsync(); for (var i = 0; i < 200 && launcher.ActiveDialog?.IsLoaded != true && !operation.IsCompleted; i++) await Task.Delay(10); if (operation.IsCompleted) await operation; var dialog = launcher.ActiveDialog ?? throw new InvalidOperationException("The form dialog did not open."); dialog.UpdateLayout(); fill?.Invoke(launcher.Form); dialog.UpdateLayout(); // InfoBar also templates a CloseButton; invoke the dialog's visible command, not that hidden child. var button = Children