Files
Terminal.Gui/Tests/UnitTests/View/Draw/NeedsDrawTests.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

68 lines
2.0 KiB
C#

#nullable enable
using UnitTests;
namespace Terminal.Gui.ViewTests;
[Trait ("Category", "Output")]
public class NeedsDrawTests ()
{
[Fact]
[AutoInitShutdown]
public void Frame_Set_After_Initialize_Update_NeededDisplay ()
{
var frame = new FrameView ();
var label = new Label
{
ColorScheme = Colors.ColorSchemes ["Menu"], X = 0, Y = 0, Text = "This should be the first line."
};
var view = new View
{
X = 0, // don't overcomplicate unit tests
Y = 1,
Height = Dim.Auto (DimAutoStyle.Text),
Width = Dim.Auto (DimAutoStyle.Text),
Text = "Press me!"
};
frame.Add (label, view);
frame.X = Pos.Center ();
frame.Y = Pos.Center ();
frame.Width = 40;
frame.Height = 8;
Toplevel top = new ();
top.Add (frame);
RunState runState = Application.Begin (top);
top.SubViewsLaidOut += (s, e) => { Assert.Equal (new (0, 0, 80, 25), top._needsDrawRect); };
frame.SubViewsLaidOut += (s, e) => { Assert.Equal (new (0, 0, 40, 8), frame._needsDrawRect); };
label.SubViewsLaidOut += (s, e) => { Assert.Equal (new (0, 0, 38, 1), label._needsDrawRect); };
view.SubViewsLaidOut += (s, e) => { Assert.Equal (new (0, 0, 13, 1), view._needsDrawRect); };
Assert.Equal (new (0, 0, 80, 25), top.Frame);
Assert.Equal (new (20, 8, 40, 8), frame.Frame);
Assert.Equal (
new (20, 8, 60, 16),
new Rectangle (
frame.Frame.Left,
frame.Frame.Top,
frame.Frame.Right,
frame.Frame.Bottom
)
);
Assert.Equal (new (0, 0, 30, 1), label.Frame);
Assert.Equal (new (0, 1, 9, 1), view.Frame); // this proves frame was set
Application.End (runState);
top.Dispose ();
}
}