Fixes #2485 ++ - Wizard v2 architecture modernization with Padding-based layout (#4510)

* Initial plan

* Fix Wizard v2 architecture issues - ScrollBar API, event handlers, key bindings

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Implement issue #4155 - Put nav buttons in bottom Padding, Help in right Padding

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Address code review feedback - Extract helper method, improve null checks

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Fix disposal issue - Ensure _helpTextView is always disposed

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Refactor & improvements. WIP

* Tweaking layout

* Wizard tweaks

* Added View.GetSubViews that optinoally gets subviews of adornments

* Refactor Wizard API: modern events, layout, and design

- Replaced custom event args with standard .NET event args (CancelEventArgs, ValueChangingEventArgs, etc.)
- Removed Finished event; use Accepting for wizard completion
- Updated Cancelled, MovingBack, MovingNext to use CancelEventArgs
- Refactored UICatalog scenarios and tests to new event model
- Improved WizardStep sizing and wizard auto-resizing to content
- Enhanced IDesignable for Wizard and WizardStep with richer design-time UI
- Simplified help text padding logic in WizardStep
- Removed obsolete code and modernized code style throughout
- Improves API consistency, usability, and .NET idiomatic usage

* Fixes #4515 - Navigating into and out of Adornments does not work

* WIP. QUite broken.

* All fixed?

* Tweaks.

* Exclude Margin subviews from drawing; add shadow tests

Update Margin adornment to skip drawing subviews that are themselves Margin views, preventing unsupported nested Margin rendering. Add unit tests to verify that opaque-shadowed buttons in Margin are not drawn, while Border and Padding still support shadow rendering. Update test class to use output helper and assert driver output.

* Final code cleanup and test improvements.

* Update Margin.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update View.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update View.Hierarchy.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update View.Hierarchy.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Refactor: code style, formatting, and minor logic cleanup

- Standardized spacing and formatting for method signatures and object initializations.
- Converted simple methods and properties to expression-bodied members for conciseness.
- Replaced named arguments with positional arguments for consistency.
- Improved XML documentation formatting for readability.
- Simplified logic in event handlers (e.g., Wizard Back button).
- Removed redundant checks where properties are guaranteed to exist.
- Fixed minor bugs related to padding, height calculation, and event handling.
- Adopted consistent use of `var` for local variables.
- Corrected namespace declarations.
- Refactored methods returning constants to use expression-bodied syntax.
- General code cleanup for clarity and maintainability; no breaking changes.

* api docs

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tig <585482+tig@users.noreply.github.com>
Co-authored-by: Tig <tig@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Copilot
2025-12-21 07:42:04 -07:00
committed by GitHub
parent af0efb3c64
commit 4145b984ba
29 changed files with 3507 additions and 1380 deletions

View File

@@ -1,21 +1,24 @@
using Xunit.Abstractions;
using UnitTests;
using Xunit.Abstractions;
namespace ViewBaseTests.Adornments;
public class AdornmentSubViewTests ()
public class AdornmentSubViewTests (ITestOutputHelper output)
{
private readonly ITestOutputHelper _output = output;
[Fact]
public void Setting_Thickness_Causes_Adornment_SubView_Layout ()
{
var view = new View ();
var subView = new View ();
view.Margin!.Add (subView);
view.Padding!.Add (subView);
view.BeginInit ();
view.EndInit ();
var raised = false;
subView.SubViewLayout += LayoutStarted;
view.Margin.Thickness = new Thickness (1, 2, 3, 4);
view.Padding.Thickness = new (1, 2, 3, 4);
view.Layout ();
Assert.True (raised);
@@ -27,12 +30,12 @@ public class AdornmentSubViewTests ()
}
[Theory]
[InlineData (0, 0, false)] // Margin has no thickness, so false
[InlineData (0, 1, false)] // Margin has no thickness, so false
[InlineData (0, 0, false)] // Padding has no thickness, so false
[InlineData (0, 1, false)] // Padding has no thickness, so false
[InlineData (1, 0, true)]
[InlineData (1, 1, true)]
[InlineData (2, 1, true)]
public void Adornment_WithSubView_Finds (int viewMargin, int subViewMargin, bool expectedFound)
public void Adornment_WithSubView_Finds (int viewPadding, int subViewPadding, bool expectedFound)
{
IApplication? app = Application.Create ();
Runnable<bool> runnable = new ()
@@ -42,9 +45,9 @@ public class AdornmentSubViewTests ()
};
app.Begin (runnable);
runnable.Margin!.Thickness = new Thickness (viewMargin);
runnable.Padding!.Thickness = new (viewPadding);
// Turn of TransparentMouse for the test
runnable.Margin!.ViewportSettings = ViewportSettingsFlags.None;
runnable.Padding!.ViewportSettings = ViewportSettingsFlags.None;
var subView = new View ()
{
@@ -53,16 +56,16 @@ public class AdornmentSubViewTests ()
Width = 5,
Height = 5
};
subView.Margin!.Thickness = new Thickness (subViewMargin);
subView.Padding!.Thickness = new (subViewPadding);
// Turn of TransparentMouse for the test
subView.Margin!.ViewportSettings = ViewportSettingsFlags.None;
subView.Padding!.ViewportSettings = ViewportSettingsFlags.None;
runnable.Margin!.Add (subView);
runnable.Padding!.Add (subView);
runnable.Layout ();
var foundView = runnable.GetViewsUnderLocation (new Point (0, 0), ViewportSettingsFlags.None).LastOrDefault ();
View? foundView = runnable.GetViewsUnderLocation (new (0, 0), ViewportSettingsFlags.None).LastOrDefault ();
bool found = foundView == subView || foundView == subView.Margin;
bool found = foundView == subView || foundView == subView.Padding;
Assert.Equal (expectedFound, found);
}
@@ -92,4 +95,84 @@ public class AdornmentSubViewTests ()
Assert.Equal (runnable.Padding, runnable.GetViewsUnderLocation (new Point (0, 0), ViewportSettingsFlags.None).LastOrDefault ());
}
[Fact]
public void Button_With_Opaque_ShadowStyle_In_Border_Should_Draw_Shadow ()
{
// Arrange
using IApplication app = Application.Create ();
app.Init ("fake");
app.Driver?.SetScreenSize (1, 4);
app.Driver!.Force16Colors = true;
using Runnable window = new ();
window.Width = Dim.Fill ();
window.Height = Dim.Fill ();
window.Text = @"XXXXXX";
window.SetScheme (new (new Attribute (Color.Black, Color.White)));
// Setup padding with some thickness so we have space for the button
window.Border!.Thickness = new (0, 3, 0, 0);
// Add a button with a transparent shadow to the Padding adornment
Button buttonInBorder = new ()
{
X = 0,
Y = 0,
Text = "B",
NoDecorations = true,
NoPadding = true,
ShadowStyle = ShadowStyle.Opaque,
};
window.Border.Add (buttonInBorder);
app.Begin (window);
DriverAssert.AssertDriverOutputIs ("""
\x1b[30m\x1b[107mB \x1b[97m\x1b[40mX
""",
_output,
app.Driver);
}
[Fact]
public void Button_With_Opaque_ShadowStyle_In_Padding_Should_Draw_Shadow ()
{
// Arrange
using IApplication app = Application.Create ();
app.Init ("fake");
app.Driver?.SetScreenSize (1, 4);
app.Driver!.Force16Colors = true;
using Runnable window = new ();
window.Width = Dim.Fill ();
window.Height = Dim.Fill ();
window.Text = @"XXXXXX";
window.SetScheme (new (new Attribute (Color.Black, Color.White)));
// Setup padding with some thickness so we have space for the button
window.Padding!.Thickness = new (0, 3, 0, 0);
// Add a button with a transparent shadow to the Padding adornment
Button buttonInPadding = new ()
{
X = 0,
Y = 0,
Text = "B",
NoDecorations = true,
NoPadding = true,
ShadowStyle = ShadowStyle.Opaque,
};
window.Padding.Add (buttonInPadding);
app.Begin (window);
DriverAssert.AssertDriverOutputIs ("""
\x1b[97m\x1b[40mB\x1b[30m\x1b[107m \x1b[97m\x1b[40mX
""",
_output,
app.Driver);
}
}

View File

@@ -0,0 +1,25 @@
#nullable enable
using UnitTests;
using Xunit.Abstractions;
namespace ViewBaseTests.Adornments;
public class PaddingTests (ITestOutputHelper output)
{
[Fact]
public void Constructor_Defaults ()
{
View view = new () { Height = 3, Width = 3 };
Assert.True (view.Padding!.CanFocus);
Assert.Equal (TabBehavior.NoStop, view.Padding.TabStop);
Assert.Empty (view.Padding!.KeyBindings.GetBindings ());
}
[Fact]
public void Thickness_Is_Empty_By_Default ()
{
View view = new () { Height = 3, Width = 3 };
Assert.Equal (Thickness.Empty, view.Padding!.Thickness);
}
}

View File

@@ -210,7 +210,6 @@ public class GetViewsUnderLocationForRootTests
}
[Theory]
[InlineData ("Margin")]
[InlineData ("Border")]
[InlineData ("Padding")]
public void Returns_Subview_Of_Adornment (string adornmentType)
@@ -271,7 +270,6 @@ public class GetViewsUnderLocationForRootTests
[Theory]
[InlineData ("Margin")]
[InlineData ("Border")]
[InlineData ("Padding")]
public void Returns_OnlyParentsSuperView_Of_Adornment_If_TransparentMouse (string adornmentType)

View File

@@ -0,0 +1,586 @@
namespace ViewBaseTests.Navigation;
/// <summary>
/// Tests for navigation into and out of Adornments (Padding, Border, Margin).
/// These tests prove that navigation to/from adornments is broken and need to be fixed.
/// </summary>
public class AdornmentNavigationTests
{
#region Padding Navigation Tests
[Fact]
[Trait ("Category", "Adornment")]
[Trait ("Category", "Navigation")]
public void AdvanceFocus_Into_Padding_With_Focusable_SubView ()
{
// Setup: View with a focusable subview in Padding
View view = new ()
{
Id = "view",
Width = 10,
Height = 10,
CanFocus = true
};
view.Padding!.Thickness = new Thickness (1);
View paddingButton = new ()
{
Id = "paddingButton",
CanFocus = true,
TabStop = TabBehavior.TabStop,
X = 0,
Y = 0,
Width = 5,
Height = 1
};
view.Padding.Add (paddingButton);
View contentButton = new ()
{
Id = "contentButton",
CanFocus = true,
TabStop = TabBehavior.TabStop,
X = 0,
Y = 0,
Width = 5,
Height = 1
};
view.Add (contentButton);
view.BeginInit ();
view.EndInit ();
// Test: Advance focus should navigate to content first
view.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
// Expected: contentButton should have focus
// This test documents the expected behavior for navigation into padding
Assert.True (contentButton.HasFocus, "Content view should receive focus first");
Assert.False (paddingButton.HasFocus, "Padding subview should not have focus yet");
// Test: Advance focus again should go to padding
view.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
// Expected: paddingButton should now have focus
// This will likely FAIL, proving the bug exists
Assert.True (paddingButton.HasFocus, "Padding subview should receive focus after content");
Assert.False (contentButton.HasFocus, "Content view should no longer have focus");
view.Dispose ();
}
[Fact]
[Trait ("Category", "Adornment")]
[Trait ("Category", "Navigation")]
public void AdvanceFocus_Out_Of_Padding_To_Content ()
{
// Setup: View with focusable padding that has focus
View view = new ()
{
Id = "view",
Width = 10,
Height = 10,
CanFocus = true
};
view.Padding!.Thickness = new Thickness (1);
View paddingButton = new ()
{
Id = "paddingButton",
CanFocus = true,
TabStop = TabBehavior.TabStop,
X = 0,
Y = 0,
Width = 5,
Height = 1
};
view.Padding.Add (paddingButton);
View contentButton = new ()
{
Id = "contentButton",
CanFocus = true,
TabStop = TabBehavior.TabStop,
X = 0,
Y = 0,
Width = 5,
Height = 1
};
view.Add (contentButton);
view.BeginInit ();
view.EndInit ();
// Set focus to padding button
paddingButton.SetFocus ();
Assert.True (paddingButton.HasFocus, "Setup: Padding button should have focus");
// Test: Advance focus should navigate from padding to content
view.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
// Expected: Should navigate to content
// This will likely FAIL, proving the bug exists
Assert.True (contentButton.HasFocus, "Content view should receive focus after padding");
Assert.False (paddingButton.HasFocus, "Padding button should no longer have focus");
view.Dispose ();
}
[Fact]
[Trait ("Category", "Adornment")]
[Trait ("Category", "Navigation")]
public void AdvanceFocus_Backward_Into_Padding ()
{
// Setup: View with focusable subviews in both content and padding
View view = new ()
{
Id = "view",
Width = 10,
Height = 10,
CanFocus = true
};
view.Padding!.Thickness = new Thickness (1);
View paddingButton = new ()
{
Id = "paddingButton",
CanFocus = true,
TabStop = TabBehavior.TabStop,
X = 0,
Y = 0,
Width = 5,
Height = 1
};
view.Padding.Add (paddingButton);
View contentButton = new ()
{
Id = "contentButton",
CanFocus = true,
TabStop = TabBehavior.TabStop,
X = 0,
Y = 0,
Width = 5,
Height = 1
};
view.Add (contentButton);
view.BeginInit ();
view.EndInit ();
// Set focus to content
contentButton.SetFocus ();
Assert.True (contentButton.HasFocus, "Setup: Content button should have focus");
// Test: Advance focus backward should go to padding
view.AdvanceFocus (NavigationDirection.Backward, TabBehavior.TabStop);
// Expected: Should navigate to padding
// This will likely FAIL, proving the bug exists
Assert.True (paddingButton.HasFocus, "Padding button should receive focus when navigating backward");
Assert.False (contentButton.HasFocus, "Content button should no longer have focus");
view.Dispose ();
}
[Fact]
[Trait ("Category", "Adornment")]
[Trait ("Category", "Navigation")]
public void Padding_CanFocus_True_TabStop_TabStop_Should_Be_In_FocusChain ()
{
// Setup: View with focusable Padding
View view = new ()
{
Id = "view",
Width = 10,
Height = 10,
CanFocus = true
};
view.Padding!.Thickness = new (1);
view.Padding.CanFocus = true;
view.Padding.TabStop = TabBehavior.TabStop;
view.BeginInit ();
view.EndInit ();
// Test: Get focus chain
View [] focusChain = view.GetFocusChain (NavigationDirection.Forward, TabBehavior.TabStop);
// Expected: Padding should be in the focus chain
// This should pass based on the GetFocusChain code
Assert.Contains (view.Padding, focusChain);
view.Dispose ();
}
#endregion
#region Border Navigation Tests
[Fact]
[Trait ("Category", "Adornment")]
[Trait ("Category", "Navigation")]
public void AdvanceFocus_Into_Border_With_Focusable_SubView ()
{
// Setup: View with a focusable subview in Border
View view = new ()
{
Id = "view",
Width = 10,
Height = 10,
CanFocus = true
};
view.Border!.Thickness = new Thickness (1);
View borderButton = new ()
{
Id = "borderButton",
CanFocus = true,
TabStop = TabBehavior.TabGroup,
X = 0,
Y = 0,
Width = 5,
Height = 1
};
view.Border.Add (borderButton);
View contentButton = new ()
{
Id = "contentButton",
CanFocus = true,
TabStop = TabBehavior.TabGroup,
X = 0,
Y = 0,
Width = 5,
Height = 1
};
view.Add (contentButton);
view.BeginInit ();
view.EndInit ();
// Test: Advance focus should navigate between content and border
view.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabGroup);
// Expected: One of them should have focus
var hasFocus = contentButton.HasFocus || borderButton.HasFocus;
Assert.True (hasFocus, "Either content or border button should have focus");
// Advance again
view.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabGroup);
// Expected: The other one should now have focus
// This will likely FAIL, proving the bug exists
if (contentButton.HasFocus)
{
// If content has focus now, border should have had it before
Assert.False (borderButton.HasFocus, "Only one should have focus at a time");
}
else
{
Assert.True (borderButton.HasFocus, "Border should have focus if content doesn't");
}
view.Dispose ();
}
[Fact]
[Trait ("Category", "Adornment")]
[Trait ("Category", "Navigation")]
public void Border_CanFocus_True_TabStop_TabGroup_Should_NOT_Be_In_FocusChain ()
{
// Setup: View with focusable Border (default TabStop is TabGroup for Border)
View view = new ()
{
Id = "view",
Width = 10,
Height = 10,
CanFocus = true
};
view.Border!.Thickness = new Thickness (1);
view.Border.CanFocus = true;
view.BeginInit ();
view.EndInit ();
// Test: Get focus chain for TabGroup
View [] focusChain = view.GetFocusChain (NavigationDirection.Forward, TabBehavior.TabGroup);
// Expected: Border should be in the focus chain
Assert.DoesNotContain (view.Border, focusChain);
view.Dispose ();
}
#endregion
#region Margin Navigation Tests
[Fact]
[Trait ("Category", "Adornment")]
[Trait ("Category", "Navigation")]
public void Margin_CanFocus_True_Should_NOT_Be_In_FocusChain ()
{
// Setup: View with focusable Margin
View view = new ()
{
Id = "view",
Width = 10,
Height = 10,
CanFocus = true
};
view.Margin!.Thickness = new Thickness (1);
view.Margin.CanFocus = true;
view.Margin.TabStop = TabBehavior.TabStop;
view.BeginInit ();
view.EndInit ();
// Test: Get focus chain
View [] focusChain = view.GetFocusChain (NavigationDirection.Forward, TabBehavior.TabStop);
// Expected: Margin should be in the focus chain
Assert.DoesNotContain (view.Margin, focusChain);
view.Dispose ();
}
#endregion
#region Mixed Scenarios
[Fact]
[Trait ("Category", "Adornment")]
[Trait ("Category", "Navigation")]
public void AdvanceFocus_Nested_Views_With_Adornment_SubViews ()
{
// Setup: Nested views where parent has adornment subviews
View parent = new ()
{
Id = "parent",
Width = 30,
Height = 30,
CanFocus = true
};
parent.Padding!.Thickness = new Thickness (2);
View parentPaddingButton = new ()
{
Id = "parentPaddingButton",
CanFocus = true,
TabStop = TabBehavior.TabStop,
X = 0,
Y = 0,
Width = 8,
Height = 1
};
parent.Padding.Add (parentPaddingButton);
View child = new ()
{
Id = "child",
Width = 10,
Height = 10,
CanFocus = true,
TabStop = TabBehavior.TabStop
};
parent.Add (child);
child.Padding!.Thickness = new Thickness (1);
View childPaddingButton = new ()
{
Id = "childPaddingButton",
CanFocus = true,
TabStop = TabBehavior.TabStop,
X = 0,
Y = 0,
Width = 5,
Height = 1
};
child.Padding.Add (childPaddingButton);
parent.BeginInit ();
parent.EndInit ();
// Test: Advance focus should navigate through parent padding, child, and child padding
parent.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
// Track which views receive focus
List<string> focusedIds = new ();
// Navigate multiple times to test nested navigation (extra iteration to allow for wrapping)
for (var i = 0; i < 5; i++)
{
if (parentPaddingButton.HasFocus)
{
focusedIds.Add ("parentPaddingButton");
}
else if (child.HasFocus)
{
focusedIds.Add ("child");
}
else if (childPaddingButton.HasFocus)
{
focusedIds.Add ("childPaddingButton");
}
parent.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
}
// Expected: Navigation should reach all elements including adornment subviews
// This will likely show incomplete navigation, proving the bug exists
Assert.True (
focusedIds.Count > 0,
"At least some navigation should occur (this test documents current behavior)"
);
parent.Dispose ();
}
#endregion
#region TabGroup Behavior Tests
#endregion
#region Edge Cases
[Fact]
[Trait ("Category", "Adornment")]
[Trait ("Category", "Navigation")]
public void AdvanceFocus_Padding_With_No_Thickness_Should_Not_Participate ()
{
// Setup: View with Padding that has no thickness but has subviews
View view = new ()
{
Id = "view",
Width = 10,
Height = 10,
CanFocus = true
};
// Padding has default Thickness.Empty
View paddingButton = new ()
{
Id = "paddingButton",
CanFocus = true,
TabStop = TabBehavior.TabStop,
X = 0,
Y = 0,
Width = 5,
Height = 1
};
view.Padding!.Add (paddingButton);
View contentButton = new ()
{
Id = "contentButton",
CanFocus = true,
TabStop = TabBehavior.TabStop,
X = 0,
Y = 0,
Width = 5,
Height = 1
};
view.Add (contentButton);
view.BeginInit ();
view.EndInit ();
// Test: Navigate - should only focus content since Padding has no thickness
view.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
Assert.True (contentButton.HasFocus, "Content should get focus");
view.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
// Expected: Should wrap back to content, not go to padding
Assert.True (contentButton.HasFocus, "Should stay in content when Padding has no thickness");
Assert.False (paddingButton.HasFocus, "Padding button should not receive focus");
view.Dispose ();
}
[Fact]
[Trait ("Category", "Adornment")]
[Trait ("Category", "Navigation")]
public void AdvanceFocus_Disabled_Adornment_SubView_Should_Be_Skipped ()
{
// Setup: View with disabled subview in Padding
View view = new ()
{
Id = "view",
Width = 10,
Height = 10,
CanFocus = true
};
view.Padding!.Thickness = new Thickness (1);
View paddingButton = new ()
{
Id = "paddingButton",
CanFocus = true,
TabStop = TabBehavior.TabStop,
Enabled = false, // Disabled
X = 0,
Y = 0,
Width = 5,
Height = 1
};
view.Padding.Add (paddingButton);
View contentButton = new ()
{
Id = "contentButton",
CanFocus = true,
TabStop = TabBehavior.TabStop,
X = 0,
Y = 0,
Width = 5,
Height = 1
};
view.Add (contentButton);
view.BeginInit ();
view.EndInit ();
// Test: Navigate - disabled padding button should be skipped
view.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
Assert.True (contentButton.HasFocus, "Content should get focus");
view.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
// Expected: Should wrap back to content, skipping disabled padding button
Assert.True (contentButton.HasFocus, "Should skip disabled padding button");
Assert.False (paddingButton.HasFocus, "Disabled padding button should not receive focus");
view.Dispose ();
}
#endregion
}

View File

@@ -26,6 +26,11 @@ public class AllViewsNavigationTests (ITestOutputHelper output) : TestsAllViews
return;
}
if (view is IDesignable designable)
{
designable.EnableForDesign ();
}
IApplication app = Application.Create ();
app.Begin (new Runnable<bool> () { CanFocus = true });
@@ -45,7 +50,7 @@ public class AllViewsNavigationTests (ITestOutputHelper output) : TestsAllViews
if (view.TabStop == TabBehavior.TabGroup)
{
navKeys = new [] { Key.F6, Key.F6.WithShift };
navKeys = [Key.F6, Key.F6.WithShift];
}
var left = false;
@@ -113,6 +118,11 @@ public class AllViewsNavigationTests (ITestOutputHelper output) : TestsAllViews
return;
}
if (view is IDesignable designable)
{
designable.EnableForDesign ();
}
IApplication app = Application.Create ();
app.Begin (new Runnable<bool> () { CanFocus = true });

View File

@@ -6,16 +6,14 @@ public class SubViewTests
[Fact]
public void SuperViewChanged_Raised_On_Add ()
{
var super = new View { };
var super = new View ();
var sub = new View ();
int superRaisedCount = 0;
int subRaisedCount = 0;
var superRaisedCount = 0;
var subRaisedCount = 0;
super.SuperViewChanged += (s, e) => { superRaisedCount++; };
super.SuperViewChanged += (s, e) =>
{
superRaisedCount++;
};
sub.SuperViewChanged += (s, e) =>
{
if (sub.SuperView is { })
@@ -34,23 +32,21 @@ public class SubViewTests
[Fact]
public void SuperViewChanged_Raised_On_Remove ()
{
var super = new View { };
var super = new View ();
var sub = new View ();
int superRaisedCount = 0;
int subRaisedCount = 0;
var superRaisedCount = 0;
var subRaisedCount = 0;
super.SuperViewChanged += (s, e) => { superRaisedCount++; };
super.SuperViewChanged += (s, e) =>
{
superRaisedCount++;
};
sub.SuperViewChanged += (s, e) =>
{
if (sub.SuperView is null)
{
subRaisedCount++;
}
};
{
if (sub.SuperView is null)
{
subRaisedCount++;
}
};
super.Add (sub);
Assert.True (super.SubViews.Count == 1);
@@ -95,6 +91,13 @@ public class SubViewTests
Assert.Equal (new (1, 1), view.GetContentSize ());
}
[Fact]
public void Add_Margin_Throws ()
{
View view = new ();
Assert.Throws<InvalidOperationException> (() => view.Margin!.Add (new View ()));
}
[Fact]
public void Remove_Does_Not_Impact_ContentSize ()
{
@@ -392,18 +395,12 @@ public class SubViewTests
var view = new View ();
var superView = new View ();
int superViewChangedCount = 0;
int superViewChangingCount = 0;
var superViewChangedCount = 0;
var superViewChangingCount = 0;
view.SuperViewChanged += (s, e) =>
{
superViewChangedCount++;
};
view.SuperViewChanged += (s, e) => { superViewChangedCount++; };
view.SuperViewChanging += (s, e) =>
{
superViewChangingCount++;
};
view.SuperViewChanging += (s, e) => { superViewChangingCount++; };
// Act
superView.Add (view);
@@ -411,7 +408,6 @@ public class SubViewTests
// Assert
Assert.Equal (1, superViewChangingCount);
Assert.Equal (1, superViewChangedCount);
}
[Fact]
@@ -450,7 +446,6 @@ public class SubViewTests
top2.Dispose ();
}
[Fact]
public void Initialized_Event_Comparing_With_Added_Event ()
{
@@ -479,10 +474,10 @@ public class SubViewTests
int tc = 0, wc = 0, v1c = 0, v2c = 0, sv1c = 0;
winAddedToTop.SubViewAdded += (s, e) =>
{
Assert.Equal (e.SuperView!.Frame.Width, winAddedToTop.Frame.Width);
Assert.Equal (e.SuperView.Frame.Height, winAddedToTop.Frame.Height);
};
{
Assert.Equal (e.SuperView!.Frame.Width, winAddedToTop.Frame.Width);
Assert.Equal (e.SuperView.Frame.Height, winAddedToTop.Frame.Height);
};
v1AddedToWin.SubViewAdded += (s, e) =>
{
@@ -503,69 +498,70 @@ public class SubViewTests
};
top.Initialized += (s, e) =>
{
tc++;
Assert.Equal (1, tc);
Assert.Equal (1, wc);
Assert.Equal (1, v1c);
Assert.Equal (1, v2c);
Assert.Equal (1, sv1c);
{
tc++;
Assert.Equal (1, tc);
Assert.Equal (1, wc);
Assert.Equal (1, v1c);
Assert.Equal (1, v2c);
Assert.Equal (1, sv1c);
Assert.True (top.CanFocus);
Assert.True (winAddedToTop.CanFocus);
Assert.False (v1AddedToWin.CanFocus);
Assert.False (v2AddedToWin.CanFocus);
Assert.False (svAddedTov1.CanFocus);
Assert.True (top.CanFocus);
Assert.True (winAddedToTop.CanFocus);
Assert.False (v1AddedToWin.CanFocus);
Assert.False (v2AddedToWin.CanFocus);
Assert.False (svAddedTov1.CanFocus);
top.Layout ();
};
top.Layout ();
};
winAddedToTop.Initialized += (s, e) =>
{
wc++;
Assert.Equal (top.Viewport.Width, winAddedToTop.Frame.Width);
Assert.Equal (top.Viewport.Height, winAddedToTop.Frame.Height);
};
{
wc++;
Assert.Equal (top.Viewport.Width, winAddedToTop.Frame.Width);
Assert.Equal (top.Viewport.Height, winAddedToTop.Frame.Height);
};
v1AddedToWin.Initialized += (s, e) =>
{
v1c++;
{
v1c++;
// Top.Frame: 0, 0, 80, 25; Top.Viewport: 0, 0, 80, 25
// BUGBUG: This is wrong, it should be 78, 23. This test has always been broken.
// in no way should the v1AddedToWin.Frame be the same as the Top.Frame/Viewport
// as it is a subview of winAddedToTop, which has a border!
//Assert.Equal (top.Viewport.Width, v1AddedToWin.Frame.Width);
//Assert.Equal (top.Viewport.Height, v1AddedToWin.Frame.Height);
};
// Top.Frame: 0, 0, 80, 25; Top.Viewport: 0, 0, 80, 25
// BUGBUG: This is wrong, it should be 78, 23. This test has always been broken.
// in no way should the v1AddedToWin.Frame be the same as the Top.Frame/Viewport
// as it is a subview of winAddedToTop, which has a border!
//Assert.Equal (top.Viewport.Width, v1AddedToWin.Frame.Width);
//Assert.Equal (top.Viewport.Height, v1AddedToWin.Frame.Height);
};
v2AddedToWin.Initialized += (s, e) =>
{
v2c++;
{
v2c++;
// Top.Frame: 0, 0, 80, 25; Top.Viewport: 0, 0, 80, 25
// BUGBUG: This is wrong, it should be 78, 23. This test has always been broken.
// in no way should the v2AddedToWin.Frame be the same as the Top.Frame/Viewport
// as it is a subview of winAddedToTop, which has a border!
//Assert.Equal (top.Viewport.Width, v2AddedToWin.Frame.Width);
//Assert.Equal (top.Viewport.Height, v2AddedToWin.Frame.Height);
};
// Top.Frame: 0, 0, 80, 25; Top.Viewport: 0, 0, 80, 25
// BUGBUG: This is wrong, it should be 78, 23. This test has always been broken.
// in no way should the v2AddedToWin.Frame be the same as the Top.Frame/Viewport
// as it is a subview of winAddedToTop, which has a border!
//Assert.Equal (top.Viewport.Width, v2AddedToWin.Frame.Width);
//Assert.Equal (top.Viewport.Height, v2AddedToWin.Frame.Height);
};
svAddedTov1.Initialized += (s, e) =>
{
sv1c++;
{
sv1c++;
// Top.Frame: 0, 0, 80, 25; Top.Viewport: 0, 0, 80, 25
// BUGBUG: This is wrong, it should be 78, 23. This test has always been broken.
// in no way should the svAddedTov1.Frame be the same as the Top.Frame/Viewport
// because sv1AddedTov1 is a subview of v1AddedToWin, which is a subview of
// winAddedToTop, which has a border!
//Assert.Equal (top.Viewport.Width, svAddedTov1.Frame.Width);
//Assert.Equal (top.Viewport.Height, svAddedTov1.Frame.Height);
Assert.False (svAddedTov1.CanFocus);
//Assert.Throws<InvalidOperationException> (() => svAddedTov1.CanFocus = true);
Assert.False (svAddedTov1.CanFocus);
};
// Top.Frame: 0, 0, 80, 25; Top.Viewport: 0, 0, 80, 25
// BUGBUG: This is wrong, it should be 78, 23. This test has always been broken.
// in no way should the svAddedTov1.Frame be the same as the Top.Frame/Viewport
// because sv1AddedTov1 is a subview of v1AddedToWin, which is a subview of
// winAddedToTop, which has a border!
//Assert.Equal (top.Viewport.Width, svAddedTov1.Frame.Width);
//Assert.Equal (top.Viewport.Height, svAddedTov1.Frame.Height);
Assert.False (svAddedTov1.CanFocus);
//Assert.Throws<InvalidOperationException> (() => svAddedTov1.CanFocus = true);
Assert.False (svAddedTov1.CanFocus);
};
v1AddedToWin.Add (svAddedTov1);
winAddedToTop.Add (v1AddedToWin, v2AddedToWin);
@@ -639,7 +635,7 @@ public class SubViewTests
superView.Add (subView1, subView2, subView3);
// Act
var removedViews = superView.RemoveAll ();
IReadOnlyCollection<View> removedViews = superView.RemoveAll ();
// Assert
Assert.Empty (superView.SubViews);
@@ -662,7 +658,7 @@ public class SubViewTests
superView.Add (subView1, subView2, subView3, subView4);
// Act
var removedViews = superView.RemoveAll<Button> ();
IReadOnlyCollection<Button> removedViews = superView.RemoveAll<Button> ();
// Assert
Assert.Equal (3, superView.SubViews.Count);
@@ -683,7 +679,7 @@ public class SubViewTests
superView.Add (subView1, subView2, subView3);
// Act
var removedViews = superView.RemoveAll<Button> ();
IReadOnlyCollection<Button> removedViews = superView.RemoveAll<Button> ();
// Assert
Assert.Equal (2, superView.SubViews.Count);
@@ -700,7 +696,7 @@ public class SubViewTests
var superView = new View ();
var subView = new View ();
var events = new List<string> ();
List<string> events = new ();
subView.SuperViewChanging += (s, e) => { events.Add ("SuperViewChanging"); };
@@ -722,7 +718,7 @@ public class SubViewTests
var superView = new View ();
var subView = new View ();
View? currentValueInEvent = new View (); // Set to non-null to ensure it gets updated
var currentValueInEvent = new View (); // Set to non-null to ensure it gets updated
View? newValueInEvent = null;
subView.SuperViewChanging += (s, e) =>
@@ -749,7 +745,7 @@ public class SubViewTests
superView.Add (subView);
View? currentValueInEvent = null;
View? newValueInEvent = new View (); // Set to non-null to ensure it gets updated
var newValueInEvent = new View (); // Set to non-null to ensure it gets updated
subView.SuperViewChanging += (s, e) =>
{
@@ -770,7 +766,7 @@ public class SubViewTests
{
// Arrange
using IApplication app = Application.Create ();
var runnable = new Runnable<bool> ();
Runnable<bool> runnable = new ();
var subView = new View ();
runnable.Add (subView);
@@ -781,11 +777,11 @@ public class SubViewTests
subView.SuperViewChanging += (s, e) =>
{
Assert.NotNull (s);
// At this point, SuperView is still set, so App should be accessible
appInEvent = (s as View)?.App;
};
Assert.NotNull (runnable.App);
// Act
@@ -804,7 +800,7 @@ public class SubViewTests
{
// Arrange
var superView = new View ();
var events = new List<string> ();
List<string> events = new ();
var subView = new TestViewWithSuperViewEvents (events);
@@ -854,6 +850,7 @@ public class SubViewTests
protected override bool OnSuperViewChanging (ValueChangingEventArgs<View?> args)
{
_events.Add ("OnSuperViewChanging");
return base.OnSuperViewChanging (args);
}
@@ -907,10 +904,7 @@ public class SubViewTests
var subView = new TestViewThatCancelsChange ();
var eventRaised = false;
subView.SuperViewChanging += (s, e) =>
{
eventRaised = true;
};
subView.SuperViewChanging += (s, e) => { eventRaised = true; };
// Act
superView.Add (subView);
@@ -983,4 +977,327 @@ public class SubViewTests
return true; // Always cancel the change
}
}
#region GetSubViews Tests
[Fact]
public void GetSubViews_Returns_Empty_Collection_When_No_SubViews ()
{
// Arrange
View view = new ();
// Act
IReadOnlyCollection<View> result = view.GetSubViews ();
// Assert
Assert.NotNull (result);
Assert.Empty (result);
}
[Fact]
public void GetSubViews_Returns_Direct_SubViews_By_Default ()
{
// Arrange
View superView = new ();
View subView1 = new () { Id = "subView1" };
View subView2 = new () { Id = "subView2" };
View subView3 = new () { Id = "subView3" };
superView.Add (subView1, subView2, subView3);
// Act
IReadOnlyCollection<View> result = superView.GetSubViews ();
// Assert
Assert.NotNull (result);
Assert.Equal (3, result.Count);
Assert.Contains (subView1, result);
Assert.Contains (subView2, result);
Assert.Contains (subView3, result);
}
[Fact]
public void GetSubViews_Does_Not_Include_Adornment_SubViews_By_Default ()
{
// Arrange
View superView = new ();
View subView = new () { Id = "subView" };
superView.Add (subView);
superView.BeginInit ();
superView.EndInit ();
// Add a subview to the Border (e.g., ShadowView)
View borderSubView = new () { Id = "borderSubView" };
superView.Border!.Add (borderSubView);
// Act
IReadOnlyCollection<View> result = superView.GetSubViews ();
// Assert
Assert.Single (result);
Assert.Contains (subView, result);
Assert.DoesNotContain (borderSubView, result);
}
[Fact]
public void GetSubViews_Includes_Border_SubViews_When_IncludeAdornments_Is_True ()
{
// Arrange
View superView = new ();
View subView = new () { Id = "subView" };
superView.Add (subView);
superView.BeginInit ();
superView.EndInit ();
// Add a subview to the Border
View borderSubView = new () { Id = "borderSubView" };
// Thickness matters
superView.Border!.Thickness = new (1);
superView.Border!.Add (borderSubView);
// Act
IReadOnlyCollection<View> result = superView.GetSubViews (includeBorder: true);
// Assert
Assert.Equal (2, result.Count);
Assert.Contains (subView, result);
Assert.Contains (borderSubView, result);
}
[Fact]
public void GetSubViews_Includes_Padding_SubViews_When_IncludeAdornments_Is_True ()
{
// Arrange
View superView = new ();
View subView = new () { Id = "subView" };
superView.Add (subView);
superView.BeginInit ();
superView.EndInit ();
// Add a subview to the Padding
View paddingSubView = new () { Id = "paddingSubView" };
// Thickness matters
superView.Padding!.Thickness = new (1);
superView.Padding!.Add (paddingSubView);
// Act
IReadOnlyCollection<View> result = superView.GetSubViews (includePadding: true);
// Assert
Assert.Equal (2, result.Count);
Assert.Contains (subView, result);
Assert.Contains (paddingSubView, result);
}
[Fact]
public void GetSubViews_Includes_All_Adornment_SubViews_When_IncludeAdornments_Is_True ()
{
// Arrange
View superView = new ();
View subView1 = new () { Id = "subView1" };
View subView2 = new () { Id = "subView2" };
superView.Add (subView1, subView2);
superView.BeginInit ();
superView.EndInit ();
// Add subviews to each adornment
View borderSubView = new () { Id = "borderSubView" };
View paddingSubView = new () { Id = "paddingSubView" };
// Thickness matters
//superView.Margin!.Thickness = new (1);
//superView.Margin!.Add (marginSubView);
superView.Border!.Thickness = new (1);
superView.Border!.Add (borderSubView);
superView.Padding!.Thickness = new (1);
superView.Padding!.Add (paddingSubView);
// Act
IReadOnlyCollection<View> result = superView.GetSubViews (true, true, true);
// Assert
Assert.Equal (4, result.Count);
Assert.Contains (subView1, result);
Assert.Contains (subView2, result);
Assert.Contains (borderSubView, result);
Assert.Contains (paddingSubView, result);
}
[Fact]
public void GetSubViews_Returns_Correct_Order ()
{
// Arrange
View superView = new ();
View subView1 = new () { Id = "subView1" };
View subView2 = new () { Id = "subView2" };
superView.Add (subView1, subView2);
superView.BeginInit ();
superView.EndInit ();
View borderSubView = new () { Id = "borderSubView" };
View paddingSubView = new () { Id = "paddingSubView" };
// Thickness matters
superView.Border!.Thickness = new (1);
superView.Border!.Add (borderSubView);
superView.Padding!.Thickness = new (1);
superView.Padding!.Add (paddingSubView);
// Act
IReadOnlyCollection<View> result = superView.GetSubViews (true, true, true);
List<View> resultList = result.ToList ();
// Assert - Order should be: direct SubViews, Border, Padding
Assert.Equal (4, resultList.Count);
Assert.Equal (subView1, resultList [0]);
Assert.Equal (subView2, resultList [1]);
Assert.Equal (borderSubView, resultList [2]);
Assert.Equal (paddingSubView, resultList [3]);
}
[Fact]
public void GetSubViews_Returns_Snapshot_Safe_For_Modification ()
{
// Arrange
View superView = new ();
View subView1 = new () { Id = "subView1" };
View subView2 = new () { Id = "subView2" };
superView.Add (subView1, subView2);
// Act
IReadOnlyCollection<View> result = superView.GetSubViews ();
// Modify the SuperView's SubViews
View subView3 = new () { Id = "subView3" };
superView.Add (subView3);
// Assert - The snapshot should not include subView3
Assert.Equal (2, result.Count);
Assert.Contains (subView1, result);
Assert.Contains (subView2, result);
Assert.DoesNotContain (subView3, result);
}
[Fact]
public void GetSubViews_Multiple_SubViews_In_Each_Adornment ()
{
// Arrange
View superView = new ();
View subView = new () { Id = "subView" };
superView.Add (subView);
superView.BeginInit ();
superView.EndInit ();
// Add multiple subviews to each adornment
View borderSubView1 = new () { Id = "borderSubView1" };
View borderSubView2 = new () { Id = "borderSubView2" };
View paddingSubView1 = new () { Id = "paddingSubView1" };
View paddingSubView2 = new () { Id = "paddingSubView2" };
// Thickness matters
superView.Border!.Thickness = new (1);
superView.Border!.Add (borderSubView1, borderSubView2);
// Thickness matters
superView.Padding!.Thickness = new (1);
superView.Padding!.Add (paddingSubView1, paddingSubView2);
// Act
IReadOnlyCollection<View> result = superView.GetSubViews (true, true, true);
// Assert
Assert.Equal (5, result.Count);
Assert.Contains (subView, result);
Assert.Contains (borderSubView1, result);
Assert.Contains (borderSubView2, result);
Assert.Contains (paddingSubView1, result);
Assert.Contains (paddingSubView2, result);
}
[Fact]
public void GetSubViews_Works_With_Adornment_Itself ()
{
// Arrange - Test that an Adornment (which is a View) can also have GetSubViews called
View view = new ();
view.BeginInit ();
view.EndInit ();
View paddingSubView = new () { Id = "paddingSubView" };
view.Padding!.Add (paddingSubView);
// Act - Call GetSubViews on the Margin itself
IReadOnlyCollection<View> result = view.Padding.GetSubViews ();
// Assert
Assert.Single (result);
Assert.Contains (paddingSubView, result);
}
[Fact]
public void GetSubViews_Handles_Null_Adornments_Gracefully ()
{
// Arrange - Create an Adornment view which doesn't have its own adornments
View view = new ();
view.BeginInit ();
view.EndInit ();
// Border is an Adornment and doesn't have Margin, Border, Padding
View borderSubView = new () { Id = "borderSubView" };
view.Border!.Add (borderSubView);
// Act - GetSubViews on Border (an Adornment) with includeAdornments
IReadOnlyCollection<View> result = view.Border.GetSubViews (true);
// Assert - Should only return direct subviews, not crash
Assert.Single (result);
Assert.Contains (borderSubView, result);
}
[Fact]
public void GetSubViews_Returns_IReadOnlyCollection ()
{
// Arrange
View superView = new ();
View subView = new () { Id = "subView" };
superView.Add (subView);
// Act
IReadOnlyCollection<View> result = superView.GetSubViews ();
// Assert
Assert.IsAssignableFrom<IReadOnlyCollection<View>> (result);
// Verify Count property is available and single item
Assert.Single (result);
}
[Fact]
public void GetSubViews_Empty_Adornments_Do_Not_Add_Nulls ()
{
// Arrange
View superView = new ();
View subView = new () { Id = "subView" };
superView.Add (subView);
superView.BeginInit ();
superView.EndInit ();
// Don't add any subviews to adornments
// Act
IReadOnlyCollection<View> result = superView.GetSubViews (true);
// Assert - Should only have the direct subview, no nulls
Assert.Single (result);
Assert.Contains (subView, result);
Assert.All (result, Assert.NotNull);
}
}
#endregion GetSubViews Tests

View File

@@ -1833,7 +1833,7 @@ public class TextViewTests
[Fact]
public void Space_Key_Types_Space ()
{
var view = new TextView ();
TextView view = new ();
view.NewKeyDownEvent (Key.Space);

View File

@@ -0,0 +1,479 @@
namespace ViewsTests;
[Collection ("Global Test Setup")]
public class WizardStepTests
{
#region Constructor Tests
[Fact]
public void Constructor_Initializes_Properties ()
{
// Arrange & Act
WizardStep step = new ();
// Assert
Assert.NotNull (step);
Assert.True (step.CanFocus);
Assert.Equal (TabBehavior.TabStop, step.TabStop);
Assert.Equal (LineStyle.None, step.BorderStyle);
Assert.IsType<DimFill> (step.Width);
Assert.IsType<DimFill> (step.Height);
}
[Fact]
public void Constructor_Sets_Default_Button_Text ()
{
// Arrange & Act
WizardStep step = new ();
// Assert
Assert.Equal (string.Empty, step.BackButtonText);
Assert.Equal (string.Empty, step.NextButtonText);
}
#endregion Constructor Tests
#region Title Tests
[Fact]
public void Title_Can_Be_Set ()
{
// Arrange
WizardStep step = new ();
string title = "Test Step";
// Act
step.Title = title;
// Assert
Assert.Equal (title, step.Title);
}
[Fact]
public void Title_Change_Raises_TitleChanged_Event ()
{
// Arrange
WizardStep step = new ();
var eventRaised = false;
string? newTitle = null;
step.TitleChanged += (sender, args) =>
{
eventRaised = true;
newTitle = args.Value;
};
// Act
step.Title = "New Title";
// Assert
Assert.True (eventRaised);
Assert.Equal ("New Title", newTitle);
}
#endregion Title Tests
#region HelpText Tests
[Fact]
public void HelpText_Can_Be_Set ()
{
// Arrange
WizardStep step = new ();
string helpText = "This is help text";
// Act
step.HelpText = helpText;
// Assert
Assert.Equal (helpText, step.HelpText);
}
[Fact]
public void HelpText_Empty_By_Default ()
{
// Arrange & Act
WizardStep step = new ();
// Assert
Assert.Equal (string.Empty, step.HelpText);
}
[Fact]
public void HelpText_Setting_Calls_ShowHide ()
{
// Arrange
WizardStep step = new ();
step.BeginInit ();
step.EndInit ();
// Act - Setting help text should adjust padding
step.HelpText = "Help text content";
// Assert - Padding should have right thickness when help text is present
Assert.True (step.Padding!.Thickness.Right > 0);
}
[Fact]
public void HelpText_Clearing_Removes_Padding ()
{
// Arrange
WizardStep step = new ();
step.BeginInit ();
step.EndInit ();
step.HelpText = "Help text content";
// Act - Clear help text
step.HelpText = string.Empty;
// Assert - Padding right should be 0 when help text is empty
Assert.Equal (0, step.Padding!.Thickness.Right);
}
#endregion HelpText Tests
#region BackButtonText Tests
[Fact]
public void BackButtonText_Can_Be_Set ()
{
// Arrange
WizardStep step = new ();
string buttonText = "Previous";
// Act
step.BackButtonText = buttonText;
// Assert
Assert.Equal (buttonText, step.BackButtonText);
}
[Fact]
public void BackButtonText_Empty_By_Default ()
{
// Arrange & Act
WizardStep step = new ();
// Assert
Assert.Equal (string.Empty, step.BackButtonText);
}
#endregion BackButtonText Tests
#region NextButtonText Tests
[Fact]
public void NextButtonText_Can_Be_Set ()
{
// Arrange
WizardStep step = new ();
string buttonText = "Continue";
// Act
step.NextButtonText = buttonText;
// Assert
Assert.Equal (buttonText, step.NextButtonText);
}
[Fact]
public void NextButtonText_Empty_By_Default ()
{
// Arrange & Act
WizardStep step = new ();
// Assert
Assert.Equal (string.Empty, step.NextButtonText);
}
#endregion NextButtonText Tests
#region SubView Tests
[Fact]
public void Can_Add_SubViews ()
{
// Arrange
WizardStep step = new ();
Label label = new () { Text = "Test Label" };
// Act
step.Add (label);
// Assert
Assert.Contains (label, step.SubViews);
}
[Fact]
public void Can_Add_Multiple_SubViews ()
{
// Arrange
WizardStep step = new ();
Label label1 = new () { Text = "Label 1" };
Label label2 = new () { Text = "Label 2" };
TextField textField = new () { Width = 10 };
// Act
step.Add (label1, label2, textField);
// Assert
Assert.Equal (3, step.SubViews.Count);
Assert.Contains (label1, step.SubViews);
Assert.Contains (label2, step.SubViews);
Assert.Contains (textField, step.SubViews);
}
#endregion SubView Tests
#region Enabled Tests
[Fact]
public void Enabled_True_By_Default ()
{
// Arrange & Act
WizardStep step = new ();
// Assert
Assert.True (step.Enabled);
}
[Fact]
public void Enabled_Can_Be_Set_To_False ()
{
// Arrange
WizardStep step = new ();
// Act
step.Enabled = false;
// Assert
Assert.False (step.Enabled);
}
[Fact]
public void Enabled_Change_Raises_EnabledChanged_Event ()
{
// Arrange
WizardStep step = new ();
var eventRaised = false;
step.EnabledChanged += (sender, args) => { eventRaised = true; };
// Act
step.Enabled = false;
// Assert
Assert.True (eventRaised);
}
#endregion Enabled Tests
#region Visible Tests
[Fact]
public void Visible_True_By_Default ()
{
// Arrange & Act
WizardStep step = new ();
// Assert
Assert.True (step.Visible);
}
[Fact]
public void Visible_Can_Be_Changed ()
{
// Arrange
WizardStep step = new ();
// Act
step.Visible = false;
// Assert
Assert.False (step.Visible);
}
#endregion Visible Tests
#region HelpTextView Tests
[Fact]
public void HelpTextView_Added_To_Padding ()
{
// Arrange
WizardStep step = new ();
step.BeginInit ();
step.EndInit ();
// Act
step.HelpText = "Help content";
// Assert
// The help text view should be in the Padding
Assert.True (step.Padding!.SubViews.Count > 0);
}
[Fact]
public void HelpTextView_Visible_When_HelpText_Set ()
{
// Arrange
WizardStep step = new ();
step.BeginInit ();
step.EndInit ();
// Act
step.HelpText = "Help content";
// Assert
// When help text is set, padding right should be non-zero
Assert.True (step.Padding!.Thickness.Right > 0);
}
[Fact]
public void HelpTextView_Hidden_When_HelpText_Empty ()
{
// Arrange
WizardStep step = new ();
step.BeginInit ();
step.EndInit ();
step.HelpText = "Help content";
// Act
step.HelpText = string.Empty;
// Assert
// When help text is cleared, padding right should be 0
Assert.Equal (0, step.Padding!.Thickness.Right);
}
#endregion HelpTextView Tests
#region Layout Tests
[Fact]
public void Width_Is_Fill_After_Construction ()
{
// Arrange & Act
WizardStep step = new ();
// Assert
Assert.IsType<DimFill> (step.Width);
}
[Fact]
public void Height_Is_Fill_After_Construction ()
{
// Arrange & Act
WizardStep step = new ();
// Assert
Assert.IsType<DimFill> (step.Height);
}
#endregion Layout Tests
#region Focus Tests
[Fact]
public void CanFocus_True_By_Default ()
{
// Arrange & Act
WizardStep step = new ();
// Assert
Assert.True (step.CanFocus);
}
[Fact]
public void TabStop_Is_TabStop_By_Default ()
{
// Arrange & Act
WizardStep step = new ();
// Assert
Assert.Equal (TabBehavior.TabStop, step.TabStop);
}
#endregion Focus Tests
#region BorderStyle Tests
[Fact]
public void BorderStyle_Can_Be_Changed ()
{
// Arrange
WizardStep step = new ();
// Act
step.BorderStyle = LineStyle.Single;
// Assert
Assert.Equal (LineStyle.Single, step.BorderStyle);
}
#endregion BorderStyle Tests
#region Integration Tests
[Fact]
public void Step_With_HelpText_And_SubViews ()
{
// Arrange
WizardStep step = new ()
{
Title = "User Information",
HelpText = "Please enter your details"
};
Label nameLabel = new () { Text = "Name:" };
TextField nameField = new () { X = Pos.Right (nameLabel) + 1, Width = 20 };
step.Add (nameLabel, nameField);
step.BeginInit ();
step.EndInit ();
// Assert
Assert.Equal ("User Information", step.Title);
Assert.Equal ("Please enter your details", step.HelpText);
// SubViews includes the views we added
Assert.Contains (nameLabel, step.SubViews);
Assert.Contains (nameField, step.SubViews);
Assert.True (step.Padding!.Thickness.Right > 0);
}
[Fact]
public void Step_With_Custom_Button_Text ()
{
// Arrange & Act
WizardStep step = new ()
{
Title = "Confirmation",
BackButtonText = "Go Back",
NextButtonText = "Accept"
};
// Assert
Assert.Equal ("Confirmation", step.Title);
Assert.Equal ("Go Back", step.BackButtonText);
Assert.Equal ("Accept", step.NextButtonText);
}
[Fact]
public void Disabled_Step_Maintains_Properties ()
{
// Arrange
WizardStep step = new ()
{
Title = "Optional Step",
HelpText = "This step is optional",
Enabled = false
};
// Assert
Assert.Equal ("Optional Step", step.Title);
Assert.Equal ("This step is optional", step.HelpText);
Assert.False (step.Enabled);
}
#endregion Integration Tests
}

File diff suppressed because it is too large Load Diff