ApplicationScreenTests.cs 2.2 KB

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