Files
Terminal.Gui/Tests/UnitTests/Views/FrameViewTests.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

108 lines
3.0 KiB
C#

using UnitTests;
using Xunit.Abstractions;
namespace Terminal.Gui.ViewsTests;
public class FrameViewTests (ITestOutputHelper output)
{
[Fact]
public void Constructors_Defaults ()
{
var fv = new FrameView ();
Assert.Equal (string.Empty, fv.Title);
Assert.Equal (string.Empty, fv.Text);
Assert.Equal (LineStyle.Single, fv.BorderStyle);
fv = new() { Title = "Test" };
Assert.Equal ("Test", fv.Title);
Assert.Equal (string.Empty, fv.Text);
Assert.Equal (LineStyle.Single, fv.BorderStyle);
fv = new()
{
X = 1,
Y = 2,
Width = 10,
Height = 20,
Title = "Test"
};
Assert.Equal ("Test", fv.Title);
Assert.Equal (string.Empty, fv.Text);
fv.BeginInit ();
fv.EndInit ();
Assert.Equal (LineStyle.Single, fv.BorderStyle);
Assert.Equal (new (1, 2, 10, 20), fv.Frame);
}
[Fact]
[AutoInitShutdown]
public void Draw_Defaults ()
{
((FakeDriver)Application.Driver!).SetBufferSize (10, 10);
var fv = new FrameView ();
Assert.Equal (string.Empty, fv.Title);
Assert.Equal (string.Empty, fv.Text);
var top = new Toplevel ();
top.Add (fv);
Application.Begin (top);
Assert.Equal (new (0, 0, 0, 0), fv.Frame);
DriverAssert.AssertDriverContentsWithFrameAre (@"", output);
fv.Height = 5;
fv.Width = 5;
Assert.Equal (new (0, 0, 5, 5), fv.Frame);
Application.LayoutAndDraw ();
DriverAssert.AssertDriverContentsWithFrameAre (
@"
┌───┐
│ │
│ │
│ │
└───┘",
output
);
fv.X = 1;
fv.Y = 2;
Assert.Equal (new (1, 2, 5, 5), fv.Frame);
Application.LayoutAndDraw ();
DriverAssert.AssertDriverContentsWithFrameAre (
@"
┌───┐
│ │
│ │
│ │
└───┘",
output
);
fv.X = -1;
fv.Y = -2;
Assert.Equal (new (-1, -2, 5, 5), fv.Frame);
Application.LayoutAndDraw ();
DriverAssert.AssertDriverContentsWithFrameAre (
@"
───┘",
output
);
fv.X = 7;
fv.Y = 8;
Assert.Equal (new (7, 8, 5, 5), fv.Frame);
Application.LayoutAndDraw ();
DriverAssert.AssertDriverContentsWithFrameAre (
@"
┌──
│ ",
output
);
top.Dispose ();
}
}