test(configmanager): expand unit test coverage to 451 tests
Add comprehensive tests for services (ConnectionTestService, RuntimeConfigValidation), ViewModels (PipelineEditor, dialogs, transformers), and Avalonia headless UI tests for views and forms.
This commit is contained in:
@@ -0,0 +1,233 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Headless.XUnit;
|
||||
using Avalonia.VisualTree;
|
||||
using JdeScoping.ConfigManager.Views.Forms;
|
||||
|
||||
namespace JdeScoping.ConfigManager.Tests.Views.Forms;
|
||||
|
||||
/// <summary>
|
||||
/// UI tests for form views.
|
||||
/// </summary>
|
||||
public class FormViewTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a test window to host a UserControl and shows it.
|
||||
/// UserControls must be attached to a Window to have their visual tree built.
|
||||
/// </summary>
|
||||
private static Window ShowInTestWindow(Control content)
|
||||
{
|
||||
var window = new Window { Content = content };
|
||||
window.Show();
|
||||
return window;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that AuthFormView renders with the expected controls.
|
||||
/// </summary>
|
||||
[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<TextBox>().ToList();
|
||||
textBoxes.Count.ShouldBeGreaterThan(0);
|
||||
|
||||
var numericUpDowns = view.GetVisualDescendants().OfType<NumericUpDown>().ToList();
|
||||
numericUpDowns.Count.ShouldBeGreaterThan(0);
|
||||
|
||||
// Verify header is present
|
||||
var textBlocks = view.GetVisualDescendants().OfType<TextBlock>().ToList();
|
||||
textBlocks.Any(tb => tb.Text == "Authentication Settings").ShouldBeTrue();
|
||||
textBlocks.Any(tb => tb.Text == "Cookie Settings").ShouldBeTrue();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that DataSyncFormView renders with the expected controls.
|
||||
/// </summary>
|
||||
[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<CheckBox>().ToList();
|
||||
checkBoxes.Count.ShouldBeGreaterThan(0);
|
||||
|
||||
var numericUpDowns = view.GetVisualDescendants().OfType<NumericUpDown>().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<TextBlock>().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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that ConnectionStringsFormView renders with a DataGrid.
|
||||
/// </summary>
|
||||
[AvaloniaFact]
|
||||
public void ConnectionStringsFormView_RendersDataGrid()
|
||||
{
|
||||
// Arrange
|
||||
var view = new ConnectionStringsFormView();
|
||||
ShowInTestWindow(view);
|
||||
|
||||
// Assert - ConnectionStringsFormView contains a DataGrid for connections
|
||||
var dataGrid = view.FindDescendantOfType<DataGrid>();
|
||||
dataGrid.ShouldNotBeNull();
|
||||
|
||||
// Verify header is present
|
||||
var textBlocks = view.GetVisualDescendants().OfType<TextBlock>().ToList();
|
||||
textBlocks.Any(tb => tb.Text == "Connection Strings").ShouldBeTrue();
|
||||
textBlocks.Any(tb => tb.Text == "Connections").ShouldBeTrue();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that ConnectionStringsFormView has Add and Delete buttons.
|
||||
/// </summary>
|
||||
[AvaloniaFact]
|
||||
public void ConnectionStringsFormView_HasAddAndDeleteButtons()
|
||||
{
|
||||
// Arrange
|
||||
var view = new ConnectionStringsFormView();
|
||||
ShowInTestWindow(view);
|
||||
|
||||
// Assert
|
||||
var buttons = view.GetVisualDescendants().OfType<Button>().ToList();
|
||||
|
||||
// Find buttons containing TextBlock with Add/Delete text
|
||||
var buttonTexts = buttons
|
||||
.SelectMany(b => b.GetVisualDescendants().OfType<TextBlock>())
|
||||
.Select(tb => tb.Text)
|
||||
.ToList();
|
||||
|
||||
buttonTexts.ShouldContain("Add");
|
||||
buttonTexts.ShouldContain("Delete");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that LdapFormView renders with server URL list input.
|
||||
/// </summary>
|
||||
[AvaloniaFact]
|
||||
public void LdapFormView_RendersServerList()
|
||||
{
|
||||
// Arrange
|
||||
var view = new LdapFormView();
|
||||
ShowInTestWindow(view);
|
||||
|
||||
// Assert - LdapFormView contains TextBoxes for server URLs, Group DN, Search Base
|
||||
var textBoxes = view.GetVisualDescendants().OfType<TextBox>().ToList();
|
||||
textBoxes.Count.ShouldBeGreaterThanOrEqualTo(3); // Server URLs, Group DN, Search Base, Admin Bypass Users
|
||||
|
||||
// Verify section headers
|
||||
var textBlocks = view.GetVisualDescendants().OfType<TextBlock>().ToList();
|
||||
textBlocks.Any(tb => tb.Text == "LDAP Settings").ShouldBeTrue();
|
||||
textBlocks.Any(tb => tb.Text == "Server Configuration").ShouldBeTrue();
|
||||
textBlocks.Any(tb => tb.Text == "Directory Structure").ShouldBeTrue();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that LdapFormView contains a CheckBox for fake authentication.
|
||||
/// </summary>
|
||||
[AvaloniaFact]
|
||||
public void LdapFormView_HasFakeAuthCheckBox()
|
||||
{
|
||||
// Arrange
|
||||
var view = new LdapFormView();
|
||||
ShowInTestWindow(view);
|
||||
|
||||
// Assert
|
||||
var checkBoxes = view.GetVisualDescendants().OfType<CheckBox>().ToList();
|
||||
checkBoxes.Count.ShouldBeGreaterThan(0);
|
||||
|
||||
// Verify development options section
|
||||
var textBlocks = view.GetVisualDescendants().OfType<TextBlock>().ToList();
|
||||
textBlocks.Any(tb => tb.Text == "Development Options").ShouldBeTrue();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that LdapFormView contains a NumericUpDown for connection timeout.
|
||||
/// </summary>
|
||||
[AvaloniaFact]
|
||||
public void LdapFormView_HasConnectionTimeoutNumericUpDown()
|
||||
{
|
||||
// Arrange
|
||||
var view = new LdapFormView();
|
||||
ShowInTestWindow(view);
|
||||
|
||||
// Assert
|
||||
var numericUpDowns = view.GetVisualDescendants().OfType<NumericUpDown>().ToList();
|
||||
numericUpDowns.Count.ShouldBeGreaterThan(0);
|
||||
|
||||
// Verify timeout label is present
|
||||
var textBlocks = view.GetVisualDescendants().OfType<TextBlock>().ToList();
|
||||
textBlocks.Any(tb => tb.Text == "Connection Timeout (seconds)").ShouldBeTrue();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that AuthFormView contains a ScrollViewer.
|
||||
/// </summary>
|
||||
[AvaloniaFact]
|
||||
public void AuthFormView_ContainsScrollViewer()
|
||||
{
|
||||
// Arrange
|
||||
var view = new AuthFormView();
|
||||
ShowInTestWindow(view);
|
||||
|
||||
// Assert
|
||||
var scrollViewer = view.FindDescendantOfType<ScrollViewer>();
|
||||
scrollViewer.ShouldNotBeNull();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that DataSyncFormView contains a ScrollViewer.
|
||||
/// </summary>
|
||||
[AvaloniaFact]
|
||||
public void DataSyncFormView_ContainsScrollViewer()
|
||||
{
|
||||
// Arrange
|
||||
var view = new DataSyncFormView();
|
||||
ShowInTestWindow(view);
|
||||
|
||||
// Assert
|
||||
var scrollViewer = view.FindDescendantOfType<ScrollViewer>();
|
||||
scrollViewer.ShouldNotBeNull();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that ConnectionStringsFormView contains a ScrollViewer.
|
||||
/// </summary>
|
||||
[AvaloniaFact]
|
||||
public void ConnectionStringsFormView_ContainsScrollViewer()
|
||||
{
|
||||
// Arrange
|
||||
var view = new ConnectionStringsFormView();
|
||||
ShowInTestWindow(view);
|
||||
|
||||
// Assert
|
||||
var scrollViewer = view.FindDescendantOfType<ScrollViewer>();
|
||||
scrollViewer.ShouldNotBeNull();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that LdapFormView contains a ScrollViewer.
|
||||
/// </summary>
|
||||
[AvaloniaFact]
|
||||
public void LdapFormView_ContainsScrollViewer()
|
||||
{
|
||||
// Arrange
|
||||
var view = new LdapFormView();
|
||||
ShowInTestWindow(view);
|
||||
|
||||
// Assert
|
||||
var scrollViewer = view.FindDescendantOfType<ScrollViewer>();
|
||||
scrollViewer.ShouldNotBeNull();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user