Files
Terminal.Gui/UnitTests/Application/ApplicationScreenTests.cs
Tig df9549e0a2 Tons of V2 API doc fixes (#3932)
* Tons of API doc updates

* tweaked scenario

* try to fix unit test crash in ubuntu action

* try to fix unit test crash in ubuntu action2
2025-02-27 17:00:47 -07:00

92 lines
2.3 KiB
C#

using Xunit.Abstractions;
namespace Terminal.Gui.ApplicationTests;
public class ApplicationScreenTests (ITestOutputHelper output)
{
[Fact]
public void ClearScreenNextIteration_Resets_To_False_After_LayoutAndDraw ()
{
// Arrange
Application.ResetState (true);
Application.Init ();
// Act
Application.ClearScreenNextIteration = true;
Application.LayoutAndDraw ();
// Assert
Assert.False (Application.ClearScreenNextIteration);
// Cleanup
Application.ResetState (true);
}
[Fact]
public void ClearContents_Called_When_Top_Frame_Changes ()
{
// Arrange
Application.Init (new FakeDriver ());
Application.Top = new Toplevel ();
Application.TopLevels.Push (Application.Top);
int clearedContentsRaised = 0;
Application.Driver!.ClearedContents += (e, a) => clearedContentsRaised++;
// Act
Application.LayoutAndDraw ();
// Assert
Assert.Equal (1, clearedContentsRaised);
// Act
Application.Top.SetNeedsLayout ();
Application.LayoutAndDraw ();
// Assert
Assert.Equal (1, clearedContentsRaised);
// Act
Application.Top.X = 1;
Application.LayoutAndDraw ();
// Assert
Assert.Equal (2, clearedContentsRaised);
// Act
Application.Top.Width = 10;
Application.LayoutAndDraw ();
// Assert
Assert.Equal (3, clearedContentsRaised);
// Cleanup
Application.Top.Dispose ();
Application.Top = null;
Application.Shutdown ();
Application.ResetState (true);
}
[Fact]
public void Screen_Changes_OnSizeChanged_Without_Call_Application_Init ()
{
// Arrange
Application.ResetState (true);
Assert.Null (Application.Driver);
Application.Driver = new FakeDriver { Rows = 25, Cols = 25 };
Application.SubscribeDriverEvents ();
Assert.Equal (new (0, 0, 25, 25), Application.Screen);
// Act
(((FakeDriver)Application.Driver)!).SetBufferSize (120, 30);
// Assert
Assert.Equal (new (0, 0, 120, 30), Application.Screen);
// Cleanup
Application.ResetState (true);
}
}