using Avalonia.Controls; using Avalonia.Headless.XUnit; using Avalonia.VisualTree; using JdeScoping.ConfigManager.Ui.Views.Forms; namespace JdeScoping.ConfigManager.Ui.Tests.Views.Forms; /// /// UI tests for form views. /// public class FormViewTests { /// /// Creates a test window to host a UserControl and shows it. /// UserControls must be attached to a Window to have their visual tree built. /// private static Window ShowInTestWindow(Control content) { var window = new Window { Content = content }; window.Show(); return window; } /// /// Verifies that AuthFormView renders with the expected controls. /// [AvaloniaFact] public void AuthFormView_RendersWithCorrectControls() { // Arrange var view = new AuthFormView(); ShowInTestWindow(view); // Assert - AuthFormView contains TextBox for CookieName and NumericUpDown for expiration var textBoxes = view.GetVisualDescendants().OfType().ToList(); textBoxes.Count.ShouldBeGreaterThan(0); var numericUpDowns = view.GetVisualDescendants().OfType().ToList(); numericUpDowns.Count.ShouldBeGreaterThan(0); // Verify header is present var textBlocks = view.GetVisualDescendants().OfType().ToList(); textBlocks.Any(tb => tb.Text == "Authentication Settings").ShouldBeTrue(); textBlocks.Any(tb => tb.Text == "Cookie Settings").ShouldBeTrue(); } /// /// Verifies that DataSyncFormView renders with the expected controls. /// [AvaloniaFact] public void DataSyncFormView_RendersWithCorrectControls() { // Arrange var view = new DataSyncFormView(); ShowInTestWindow(view); // Assert - DataSyncFormView contains CheckBox for Enabled and multiple NumericUpDowns var checkBoxes = view.GetVisualDescendants().OfType().ToList(); checkBoxes.Count.ShouldBeGreaterThan(0); var numericUpDowns = view.GetVisualDescendants().OfType().ToList(); numericUpDowns.Count.ShouldBeGreaterThanOrEqualTo(6); // Check Interval, Timeout, Max Parallelism, Batch Size, Bulk Copy Batch Size, Lookback Multiplier, Purge Retention // Verify section headers var textBlocks = view.GetVisualDescendants().OfType().ToList(); textBlocks.Any(tb => tb.Text == "Data Sync Settings").ShouldBeTrue(); textBlocks.Any(tb => tb.Text == "Sync Intervals").ShouldBeTrue(); textBlocks.Any(tb => tb.Text == "Performance").ShouldBeTrue(); textBlocks.Any(tb => tb.Text == "Data Retention").ShouldBeTrue(); } /// /// Verifies that ConnectionStringsFormView renders with a DataGrid. /// [AvaloniaFact] public void ConnectionStringsFormView_RendersDataGrid() { // Arrange var view = new ConnectionStringsFormView(); ShowInTestWindow(view); // Assert - ConnectionStringsFormView contains a DataGrid for connections var dataGrid = view.FindDescendantOfType(); dataGrid.ShouldNotBeNull(); // Verify header is present var textBlocks = view.GetVisualDescendants().OfType().ToList(); textBlocks.Any(tb => tb.Text == "Connection Strings").ShouldBeTrue(); textBlocks.Any(tb => tb.Text == "Connections").ShouldBeTrue(); } /// /// Verifies that ConnectionStringsFormView has Add and Delete buttons. /// [AvaloniaFact] public void ConnectionStringsFormView_HasAddAndDeleteButtons() { // Arrange var view = new ConnectionStringsFormView(); ShowInTestWindow(view); // Assert var buttons = view.GetVisualDescendants().OfType