Files
Terminal.Gui/Tests/UnitTests/Views/AllViewsTests.cs
Tig acb5979e6c Cleans up/Refactors View.Subviews (#3962)
* Subview clean up

* New Add/Remove event pattern

* Using Logging

* cleanup

* Subview -> SubView

* Test code cleanup. Killed many warnings.

* Fix tznind feedback

* Refactored AllViewTest helpers

* Moved keyboard tests to parallel

* Moved mouse tests to parallel

* Moved view tests to parallel

* Test code cleanup. Killed many warnings.

* dupe test

* Some mouse tests can't run in parallel because MouseGrabView

* Made SpinnerView more testable

* Moved more tests

* SubViews to IReadOnlyCollection<View>

* SubViews to IReadOnlyCollection<View> 2

* scrollbar tests

* shortcut tests

* Use InternalSubViews vs. _subviews

* Nuked View.IsAdded.
Added View.SuperViewChanged.

* API doc updats

* Unit Test tweak

* Unit Test tweak
2025-03-08 15:42:17 -07:00

66 lines
2.0 KiB
C#

using System.Reflection;
using UnitTests;
using Xunit.Abstractions;
namespace Terminal.Gui.ViewsTests;
public class AllViewsTests (ITestOutputHelper output) : TestsAllViews
{
// TODO: Update all these tests to use AllViews like AllViews_Center_Properly does
[Theory]
[MemberData (nameof (AllViewTypes))]
[SetupFakeDriver] // Required for spinner view that wants to register timeouts
public void AllViews_Center_Properly (Type viewType)
{
// Required for spinner view that wants to register timeouts
Application.MainLoop = new (new FakeMainLoop (Application.Driver));
var view = CreateInstanceIfNotGeneric (viewType);
// See https://github.com/gui-cs/Terminal.Gui/issues/3156
if (view == null)
{
output.WriteLine ($"Ignoring {viewType} - It's a Generic");
Application.Shutdown ();
return;
}
if (view is IDesignable designable)
{
designable.EnableForDesign ();
}
view.X = Pos.Center ();
view.Y = Pos.Center ();
// Ensure the view has positive dimensions
view.Width = 10;
view.Height = 10;
var frame = new View { X = 0, Y = 0, Width = 50, Height = 50 };
frame.Add (view);
frame.BeginInit ();
frame.EndInit ();
frame.LayoutSubViews ();
// What's the natural width/height?
int expectedX = (frame.Frame.Width - view.Frame.Width) / 2;
int expectedY = (frame.Frame.Height - view.Frame.Height) / 2;
Assert.True (
view.Frame.Left == expectedX,
$"{view} did not center horizontally. Expected: {expectedX}. Actual: {view.Frame.Left}"
);
Assert.True (
view.Frame.Top == expectedY,
$"{view} did not center vertically. Expected: {expectedY}. Actual: {view.Frame.Top}"
);
Application.Shutdown ();
}
}