AllViewsDrawTests.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using Xunit.Abstractions;
  2. namespace Terminal.Gui.LayoutTests;
  3. public class AllViewsDrawTests (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_Draw_Does_Not_Layout (Type viewType)
  9. {
  10. Application.ResetState (true);
  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. _output.WriteLine ($"Testing {viewType}");
  20. if (view is IDesignable designable)
  21. {
  22. designable.EnableForDesign ();
  23. }
  24. var drawCompleteCount = 0;
  25. view.DrawComplete += (s, e) => drawCompleteCount++;
  26. var layoutStartedCount = 0;
  27. view.SubviewLayout += (s, e) => layoutStartedCount++;
  28. var layoutCompleteCount = 0;
  29. view.SubviewsLaidOut += (s, e) => layoutCompleteCount++;
  30. view.SetNeedsLayout ();
  31. view.Layout ();
  32. Assert.Equal (0, drawCompleteCount);
  33. Assert.Equal (1, layoutStartedCount);
  34. Assert.Equal (1, layoutCompleteCount);
  35. if (view.Visible)
  36. {
  37. view.SetNeedsDraw ();
  38. view.Draw ();
  39. Assert.Equal (1, drawCompleteCount);
  40. Assert.Equal (1, layoutStartedCount);
  41. Assert.Equal (1, layoutCompleteCount);
  42. }
  43. }
  44. }