LayoutTests.cs 1.3 KB

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