using Avalonia.Controls;
using Avalonia.Headless.XUnit;
using Avalonia.VisualTree;
using JdeScoping.ConfigManager.Views.Dialogs;
namespace JdeScoping.ConfigManager.Tests.Views.Dialogs;
///
/// UI tests for dialog views.
///
public class DialogViewTests
{
///
/// Verifies that NewStoreDialog renders with the expected input fields.
///
[AvaloniaFact]
public void NewStoreDialogView_RendersInputFields()
{
// Arrange & Act
var dialog = new NewStoreDialog();
dialog.Show();
// Assert - NewStoreDialog contains TextBoxes for store path and key file path
var textBoxes = dialog.GetVisualDescendants().OfType().ToList();
textBoxes.Count.ShouldBeGreaterThanOrEqualTo(2); // Store path and Key file path
// Verify section headers
var textBlocks = dialog.GetVisualDescendants().OfType().ToList();
textBlocks.Any(tb => tb.Text == "Store Location").ShouldBeTrue();
textBlocks.Any(tb => tb.Text == "Key File").ShouldBeTrue();
}
///
/// Verifies that NewStoreDialog has Browse and Generate buttons for key file.
///
[AvaloniaFact]
public void NewStoreDialogView_HasBrowseAndGenerateButtons()
{
// Arrange & Act
var dialog = new NewStoreDialog();
dialog.Show();
// Assert
var buttons = dialog.GetVisualDescendants().OfType().ToList();
var buttonContents = buttons.Select(b => b.Content?.ToString()).ToList();
buttonContents.ShouldContain("Browse...");
buttonContents.ShouldContain("Generate");
}
///
/// Verifies that NewStoreDialog has Create and Cancel buttons.
///
[AvaloniaFact]
public void NewStoreDialogView_HasCreateAndCancelButtons()
{
// Arrange & Act
var dialog = new NewStoreDialog();
dialog.Show();
// Assert
var buttons = dialog.GetVisualDescendants().OfType().ToList();
var buttonContents = buttons.Select(b => b.Content?.ToString()).ToList();
buttonContents.ShouldContain("Create");
buttonContents.ShouldContain("Cancel");
}
///
/// Verifies that NewStoreDialog has the correct title.
///
[AvaloniaFact]
public void NewStoreDialogView_HasCorrectTitle()
{
// Arrange & Act
var dialog = new NewStoreDialog();
dialog.Show();
// Assert
dialog.Title.ShouldBe("Create New Secure Store");
}
///
/// Verifies that NewStoreDialog has the expected size constraints.
///
[AvaloniaFact]
public void NewStoreDialogView_HasExpectedSize()
{
// Arrange & Act
var dialog = new NewStoreDialog();
dialog.Show();
// Assert - Width=550, Height=350, MinWidth=450, MinHeight=300
dialog.Width.ShouldBe(550);
dialog.Height.ShouldBe(350);
dialog.MinWidth.ShouldBe(450);
dialog.MinHeight.ShouldBe(300);
}
///
/// Verifies that UnlockStoreDialog renders with key file input field.
///
[AvaloniaFact]
public void UnlockStoreDialogView_RendersKeyFileField()
{
// Arrange & Act
var dialog = new UnlockStoreDialog();
dialog.Show();
// Assert - UnlockStoreDialog contains TextBoxes for store path (read-only) and key file path
var textBoxes = dialog.GetVisualDescendants().OfType().ToList();
textBoxes.Count.ShouldBeGreaterThanOrEqualTo(2); // Store path and Key file path
// Verify section headers
var textBlocks = dialog.GetVisualDescendants().OfType().ToList();
textBlocks.Any(tb => tb.Text == "Store File").ShouldBeTrue();
textBlocks.Any(tb => tb.Text == "Key File").ShouldBeTrue();
}
///
/// Verifies that UnlockStoreDialog has a Browse button for key file.
///
[AvaloniaFact]
public void UnlockStoreDialogView_HasBrowseButton()
{
// Arrange & Act
var dialog = new UnlockStoreDialog();
dialog.Show();
// Assert
var buttons = dialog.GetVisualDescendants().OfType().ToList();
var buttonContents = buttons.Select(b => b.Content?.ToString()).ToList();
buttonContents.ShouldContain("Browse...");
}
///
/// Verifies that UnlockStoreDialog has Unlock and Cancel buttons.
///
[AvaloniaFact]
public void UnlockStoreDialogView_HasUnlockAndCancelButtons()
{
// Arrange & Act
var dialog = new UnlockStoreDialog();
dialog.Show();
// Assert
var buttons = dialog.GetVisualDescendants().OfType().ToList();
var buttonContents = buttons.Select(b => b.Content?.ToString()).ToList();
buttonContents.ShouldContain("Unlock");
buttonContents.ShouldContain("Cancel");
}
///
/// Verifies that UnlockStoreDialog has the correct title.
///
[AvaloniaFact]
public void UnlockStoreDialogView_HasCorrectTitle()
{
// Arrange & Act
var dialog = new UnlockStoreDialog();
dialog.Show();
// Assert
dialog.Title.ShouldBe("Unlock Secure Store");
}
///
/// Verifies that UnlockStoreDialog has the expected size constraints.
///
[AvaloniaFact]
public void UnlockStoreDialogView_HasExpectedSize()
{
// Arrange & Act
var dialog = new UnlockStoreDialog();
dialog.Show();
// Assert - Width=500, Height=320, MinWidth=400, MinHeight=280
dialog.Width.ShouldBe(500);
dialog.Height.ShouldBe(320);
dialog.MinWidth.ShouldBe(400);
dialog.MinHeight.ShouldBe(280);
}
///
/// Verifies that NewStoreDialog is not resizable.
///
[AvaloniaFact]
public void NewStoreDialogView_IsNotResizable()
{
// Arrange & Act
var dialog = new NewStoreDialog();
dialog.Show();
// Assert
dialog.CanResize.ShouldBeFalse();
}
///
/// Verifies that UnlockStoreDialog is not resizable.
///
[AvaloniaFact]
public void UnlockStoreDialogView_IsNotResizable()
{
// Arrange & Act
var dialog = new UnlockStoreDialog();
dialog.Show();
// Assert
dialog.CanResize.ShouldBeFalse();
}
///
/// Verifies that NewStoreDialog contains a ScrollViewer.
///
[AvaloniaFact]
public void NewStoreDialogView_ContainsScrollViewer()
{
// Arrange & Act
var dialog = new NewStoreDialog();
dialog.Show();
// Assert
var scrollViewer = dialog.FindDescendantOfType();
scrollViewer.ShouldNotBeNull();
}
///
/// Verifies that UnlockStoreDialog contains a ScrollViewer.
///
[AvaloniaFact]
public void UnlockStoreDialogView_ContainsScrollViewer()
{
// Arrange & Act
var dialog = new UnlockStoreDialog();
dialog.Show();
// Assert
var scrollViewer = dialog.FindDescendantOfType();
scrollViewer.ShouldNotBeNull();
}
}