LayoutTests.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using Xunit.Abstractions;
  2. namespace Terminal.Gui.LayoutTests;
  3. public class LayoutTests (ITestOutputHelper _output) : TestsAllViews
  4. {
  5. [Theory]
  6. [SetupFakeDriver] // Required for spinner view that wants to register timeouts
  7. [MemberData (nameof (AllViewTypes))]
  8. public void AllViews_Layout_Does_Not_Draw (Type viewType)
  9. {
  10. // Required for spinner view that wants to register timeouts
  11. Application.MainLoop = new MainLoop (new FakeMainLoop (Application.Driver));
  12. var view = (View)CreateInstanceIfNotGeneric (viewType);
  13. if (view == null)
  14. {
  15. _output.WriteLine ($"Ignoring {viewType} - It's a Generic");
  16. return;
  17. }
  18. if (view is IDesignable designable)
  19. {
  20. designable.EnableForDesign ();
  21. }
  22. var drawContentCount = 0;
  23. view.DrawingContent += (s, e) => drawContentCount++;
  24. var layoutStartedCount = 0;
  25. view.SubviewLayout += (s, e) => layoutStartedCount++;
  26. var layoutCompleteCount = 0;
  27. view.SubviewsLaidOut += (s, e) => layoutCompleteCount++;
  28. view.SetNeedsLayout ();
  29. view.SetNeedsDraw();
  30. view.Layout ();
  31. Assert.Equal (0, drawContentCount);
  32. Assert.Equal (1, layoutStartedCount);
  33. Assert.Equal (1, layoutCompleteCount);
  34. }
  35. }