Skip to content

Commit 0362587

Browse files
committed
Added unit tests
1 parent 88f3d05 commit 0362587

File tree

3 files changed

+68
-52
lines changed

3 files changed

+68
-52
lines changed

Terminal.Gui/Application/Application.Run.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ public static void LayoutAndDraw (bool forceDraw = false)
508508
if (ClearScreenNextIteration)
509509
{
510510
forceDraw = true;
511+
ClearScreenNextIteration = false;
511512
}
512513
if (forceDraw)
513514
{
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using Xunit.Abstractions;
2+
3+
namespace Terminal.Gui.ApplicationTests.NavigationTests;
4+
5+
public class ApplicationScreenTests (ITestOutputHelper output)
6+
{
7+
[Fact]
8+
public void ClearScreenNextIteration_Resets_To_False_After_LayoutAndDraw ()
9+
{
10+
// Arrange
11+
Application.Init ();
12+
13+
// Act
14+
Application.ClearScreenNextIteration = true;
15+
Application.LayoutAndDraw ();
16+
17+
// Assert
18+
Assert.False (Application.ClearScreenNextIteration);
19+
20+
// Cleanup
21+
Application.ResetState (true);
22+
}
23+
24+
[Fact]
25+
[SetupFakeDriver]
26+
public void ClearContents_Called_When_Top_Frame_Changes ()
27+
{
28+
// Arrange
29+
Application.Init ();
30+
Application.Top = new Toplevel ();
31+
Application.TopLevels.Push (Application.Top);
32+
33+
int clearedContentsRaised = 0;
34+
35+
Application.Driver!.ClearedContents += (e, a) => clearedContentsRaised++;
36+
37+
// Act
38+
Application.LayoutAndDraw ();
39+
40+
// Assert
41+
Assert.Equal (0, clearedContentsRaised);
42+
43+
// Act
44+
Application.Top.SetNeedsLayout ();
45+
Application.LayoutAndDraw ();
46+
47+
// Assert
48+
Assert.Equal (0, clearedContentsRaised);
49+
50+
// Act
51+
Application.Top.X = 1;
52+
Application.LayoutAndDraw ();
53+
54+
// Assert
55+
Assert.Equal (1, clearedContentsRaised);
56+
57+
// Act
58+
Application.Top.Width = 10;
59+
Application.LayoutAndDraw ();
60+
61+
// Assert
62+
Assert.Equal (2, clearedContentsRaised);
63+
64+
// Cleanup
65+
Application.ResetState (true);
66+
}
67+
}

bench.json

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)