ApplicationScreenTests.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using Xunit.Abstractions;
  2. namespace Terminal.Gui.ApplicationTests;
  3. public class ApplicationScreenTests
  4. {
  5. public ApplicationScreenTests (ITestOutputHelper output)
  6. {
  7. ConsoleDriver.RunningUnitTests = true;
  8. }
  9. [Fact]
  10. public void ClearScreenNextIteration_Resets_To_False_After_LayoutAndDraw ()
  11. {
  12. // Arrange
  13. Application.ResetState (true);
  14. Application.Init ();
  15. // Act
  16. Application.ClearScreenNextIteration = true;
  17. Application.LayoutAndDraw ();
  18. // Assert
  19. Assert.False (Application.ClearScreenNextIteration);
  20. // Cleanup
  21. Application.ResetState (true);
  22. }
  23. [Fact]
  24. public void ClearContents_Called_When_Top_Frame_Changes ()
  25. {
  26. // Arrange
  27. Application.Init (new FakeDriver ());
  28. Application.Top = new ();
  29. Application.TopLevels.Push (Application.Top);
  30. var clearedContentsRaised = 0;
  31. Application.Driver!.ClearedContents += OnClearedContents;
  32. // Act
  33. Application.LayoutAndDraw ();
  34. // Assert
  35. Assert.Equal (1, clearedContentsRaised);
  36. // Act
  37. Application.Top.SetNeedsLayout ();
  38. Application.LayoutAndDraw ();
  39. // Assert
  40. Assert.Equal (1, clearedContentsRaised);
  41. // Act
  42. Application.Top.X = 1;
  43. Application.LayoutAndDraw ();
  44. // Assert
  45. Assert.Equal (2, clearedContentsRaised);
  46. // Act
  47. Application.Top.Width = 10;
  48. Application.LayoutAndDraw ();
  49. // Assert
  50. Assert.Equal (3, clearedContentsRaised);
  51. // Cleanup
  52. Application.Top.Dispose ();
  53. Application.Top = null;
  54. Application.Driver!.ClearedContents -= OnClearedContents;
  55. Application.Shutdown ();
  56. Application.ResetState (true);
  57. return;
  58. void OnClearedContents (object e, EventArgs a) { clearedContentsRaised++; }
  59. }
  60. [Fact]
  61. public void Screen_Changes_OnSizeChanged_Without_Call_Application_Init ()
  62. {
  63. // Arrange
  64. Application.ResetState (true);
  65. Assert.Null (Application.Driver);
  66. Application.Driver = new FakeDriver { Rows = 25, Cols = 25 };
  67. Application.SubscribeDriverEvents ();
  68. Assert.Equal (new (0, 0, 25, 25), Application.Screen);
  69. // Act
  70. ((FakeDriver)Application.Driver)!.SetBufferSize (120, 30);
  71. // Assert
  72. Assert.Equal (new (0, 0, 120, 30), Application.Screen);
  73. // Cleanup
  74. Application.ResetState (true);
  75. }
  76. }