NeedsDrawTests.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #nullable enable
  2. using UnitTests;
  3. namespace Terminal.Gui.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. ColorScheme = Colors.ColorSchemes ["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. top.SubViewsLaidOut += (s, e) => { Assert.Equal (new (0, 0, 80, 25), top._needsDrawRect); };
  33. frame.SubViewsLaidOut += (s, e) => { Assert.Equal (new (0, 0, 40, 8), frame._needsDrawRect); };
  34. label.SubViewsLaidOut += (s, e) => { Assert.Equal (new (0, 0, 38, 1), label._needsDrawRect); };
  35. view.SubViewsLaidOut += (s, e) => { Assert.Equal (new (0, 0, 13, 1), view._needsDrawRect); };
  36. Assert.Equal (new (0, 0, 80, 25), top.Frame);
  37. Assert.Equal (new (20, 8, 40, 8), frame.Frame);
  38. Assert.Equal (
  39. new (20, 8, 60, 16),
  40. new Rectangle (
  41. frame.Frame.Left,
  42. frame.Frame.Top,
  43. frame.Frame.Right,
  44. frame.Frame.Bottom
  45. )
  46. );
  47. Assert.Equal (new (0, 0, 30, 1), label.Frame);
  48. Assert.Equal (new (0, 1, 9, 1), view.Frame); // this proves frame was set
  49. Application.End (runState);
  50. top.Dispose ();
  51. }
  52. }