NeedsDrawTests.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #nullable enable
  2. using UnitTests;
  3. namespace UnitTests.ViewTests;
  4. [Trait ("Category", "Output")]
  5. public class NeedsDrawTests ()
  6. {
  7. [Fact]
  8. [AutoInitShutdown]
  9. public void Frame_Set_After_Initialize_Update_NeededDisplay ()
  10. {
  11. var frame = new FrameView ();
  12. var label = new Label
  13. {
  14. SchemeName = "Menu", X = 0, Y = 0, Text = "This should be the first line."
  15. };
  16. var view = new View
  17. {
  18. X = 0, // don't overcomplicate unit tests
  19. Y = 1,
  20. Height = Dim.Auto (DimAutoStyle.Text),
  21. Width = Dim.Auto (DimAutoStyle.Text),
  22. Text = "Press me!"
  23. };
  24. frame.Add (label, view);
  25. frame.X = Pos.Center ();
  26. frame.Y = Pos.Center ();
  27. frame.Width = 40;
  28. frame.Height = 8;
  29. Toplevel top = new ();
  30. top.Add (frame);
  31. RunState runState = Application.Begin (top);
  32. AutoInitShutdownAttribute.FakeResize (new Size (80,25));
  33. top.SubViewsLaidOut += (s, e) => { Assert.Equal (new (0, 0, 80, 25), top.NeedsDrawRect); };
  34. frame.SubViewsLaidOut += (s, e) => { Assert.Equal (new (0, 0, 40, 8), frame.NeedsDrawRect); };
  35. label.SubViewsLaidOut += (s, e) => { Assert.Equal (new (0, 0, 38, 1), label.NeedsDrawRect); };
  36. view.SubViewsLaidOut += (s, e) => { Assert.Equal (new (0, 0, 13, 1), view.NeedsDrawRect); };
  37. Assert.Equal (new (0, 0, 80, 25), top.Frame);
  38. Assert.Equal (new (20, 8, 40, 8), frame.Frame);
  39. Assert.Equal (
  40. new (20, 8, 60, 16),
  41. new Rectangle (
  42. frame.Frame.Left,
  43. frame.Frame.Top,
  44. frame.Frame.Right,
  45. frame.Frame.Bottom
  46. )
  47. );
  48. Assert.Equal (new (0, 0, 30, 1), label.Frame);
  49. Assert.Equal (new (0, 1, 9, 1), view.Frame); // this proves frame was set
  50. Application.End (runState);
  51. top.Dispose ();
  52. }
  53. }