ApplicationScreenTests.cs 2.3 KB

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