AllViewsDrawTests.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using UnitTests;
  2. using Xunit.Abstractions;
  3. namespace Terminal.Gui.LayoutTests;
  4. public class AllViewsDrawTests (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_Draw_Does_Not_Layout (Type viewType)
  10. {
  11. Application.ResetState (true);
  12. // Required for spinner view that wants to register timeouts
  13. Application.MainLoop = new MainLoop (new FakeMainLoop (Application.Driver));
  14. var view = (View)CreateInstanceIfNotGeneric (viewType);
  15. if (view == null)
  16. {
  17. output.WriteLine ($"Ignoring {viewType} - It's a Generic");
  18. return;
  19. }
  20. output.WriteLine ($"Testing {viewType}");
  21. if (view is IDesignable designable)
  22. {
  23. designable.EnableForDesign ();
  24. }
  25. var drawCompleteCount = 0;
  26. view.DrawComplete += (s, e) => drawCompleteCount++;
  27. var layoutStartedCount = 0;
  28. view.SubViewLayout += (s, e) => layoutStartedCount++;
  29. var layoutCompleteCount = 0;
  30. view.SubViewsLaidOut += (s, e) => layoutCompleteCount++;
  31. view.SetNeedsLayout ();
  32. view.Layout ();
  33. Assert.Equal (0, drawCompleteCount);
  34. Assert.Equal (1, layoutStartedCount);
  35. Assert.Equal (1, layoutCompleteCount);
  36. if (view.Visible)
  37. {
  38. view.SetNeedsDraw ();
  39. view.Draw ();
  40. Assert.Equal (1, drawCompleteCount);
  41. Assert.Equal (1, layoutStartedCount);
  42. Assert.Equal (1, layoutCompleteCount);
  43. }
  44. }
  45. }