Files
Terminal.Gui/Tests/UnitTestsParallelizable/ViewBase/Adornment/AdornmentSubViewTests.cs
Copilot 4145b984ba 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>
2025-12-21 07:42:04 -07:00

179 lines
5.4 KiB
C#

using UnitTests;
using Xunit.Abstractions;
namespace ViewBaseTests.Adornments;
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.Padding!.Add (subView);
view.BeginInit ();
view.EndInit ();
var raised = false;
subView.SubViewLayout += LayoutStarted;
view.Padding.Thickness = new (1, 2, 3, 4);
view.Layout ();
Assert.True (raised);
return;
void LayoutStarted (object? sender, LayoutEventArgs e)
{
raised = true;
}
}
[Theory]
[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 viewPadding, int subViewPadding, bool expectedFound)
{
IApplication? app = Application.Create ();
Runnable<bool> runnable = new ()
{
Width = 10,
Height = 10
};
app.Begin (runnable);
runnable.Padding!.Thickness = new (viewPadding);
// Turn of TransparentMouse for the test
runnable.Padding!.ViewportSettings = ViewportSettingsFlags.None;
var subView = new View ()
{
X = 0,
Y = 0,
Width = 5,
Height = 5
};
subView.Padding!.Thickness = new (subViewPadding);
// Turn of TransparentMouse for the test
subView.Padding!.ViewportSettings = ViewportSettingsFlags.None;
runnable.Padding!.Add (subView);
runnable.Layout ();
View? foundView = runnable.GetViewsUnderLocation (new (0, 0), ViewportSettingsFlags.None).LastOrDefault ();
bool found = foundView == subView || foundView == subView.Padding;
Assert.Equal (expectedFound, found);
}
[Fact]
public void Adornment_WithNonVisibleSubView_Finds_Adornment ()
{
IApplication? app = Application.Create ();
Runnable<bool> runnable = new ()
{
Width = 10,
Height = 10
};
app.Begin (runnable);
runnable.Padding!.Thickness = new Thickness (1);
var subView = new View ()
{
X = 0,
Y = 0,
Width = 1,
Height = 1,
Visible = false
};
runnable.Padding.Add (subView);
runnable.Layout ();
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);
}
}