using Avalonia; using Avalonia.Controls; using Avalonia.Headless.XUnit; using Avalonia.Media; using Avalonia.Styling; using Avalonia.VisualTree; using PostIt.ViewModels; using PostIt.Views; namespace PostIt.Tests; /// /// UI tests for . Mounted inside /// a real via the headless Avalonia /// platform declared in TestApp.cs. /// /// The pattern is the one that UnitTest1.MainPage_Should_Load /// established: a test attribute [AvaloniaFact] (from /// Avalonia.Headless.XUnit) instead of plain [Fact], /// new MainWindow(), window.Show(). The AvaloniaFact /// attribute schedules the test body inside a dispatcher, which /// is the precondition for the headless Window's /// PlatformManager.CreateWindow() to find a registered /// service. A plain [Fact] test that calls /// new Window().Show() throws because the harness has not /// been initialised for that thread. /// /// The session banner's DataContext is not wired in /// these tests: App.OnFrameworkInitializationCompleted is /// not called in a unit test, so we set the DataContext on the /// banner directly. The production code path is exercised /// end-to-end by the manual launch, not here. /// public class SessionStatusBannerTests { [AvaloniaFact] public void Banner_renders_three_buttons_in_the_visual_tree() { var window = new MainWindow(); window.SessionBanner.DataContext = new SessionStatusViewModel(); window.Show(); var buttons = window.SessionBanner.GetVisualDescendants() .OfType