FrameViewTests.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using UnitTests;
  2. using Xunit.Abstractions;
  3. namespace Terminal.Gui.ViewsTests;
  4. public class FrameViewTests (ITestOutputHelper output)
  5. {
  6. [Fact]
  7. public void Constructors_Defaults ()
  8. {
  9. var fv = new FrameView ();
  10. Assert.Equal (string.Empty, fv.Title);
  11. Assert.Equal (string.Empty, fv.Text);
  12. Assert.Equal (LineStyle.Single, fv.BorderStyle);
  13. fv = new() { Title = "Test" };
  14. Assert.Equal ("Test", fv.Title);
  15. Assert.Equal (string.Empty, fv.Text);
  16. Assert.Equal (LineStyle.Single, fv.BorderStyle);
  17. fv = new()
  18. {
  19. X = 1,
  20. Y = 2,
  21. Width = 10,
  22. Height = 20,
  23. Title = "Test"
  24. };
  25. Assert.Equal ("Test", fv.Title);
  26. Assert.Equal (string.Empty, fv.Text);
  27. fv.BeginInit ();
  28. fv.EndInit ();
  29. Assert.Equal (LineStyle.Single, fv.BorderStyle);
  30. Assert.Equal (new (1, 2, 10, 20), fv.Frame);
  31. }
  32. [Fact]
  33. [AutoInitShutdown]
  34. public void Draw_Defaults ()
  35. {
  36. ((FakeDriver)Application.Driver!).SetBufferSize (10, 10);
  37. var fv = new FrameView ();
  38. Assert.Equal (string.Empty, fv.Title);
  39. Assert.Equal (string.Empty, fv.Text);
  40. var top = new Toplevel ();
  41. top.Add (fv);
  42. Application.Begin (top);
  43. Assert.Equal (new (0, 0, 0, 0), fv.Frame);
  44. DriverAssert.AssertDriverContentsWithFrameAre (@"", output);
  45. fv.Height = 5;
  46. fv.Width = 5;
  47. Assert.Equal (new (0, 0, 5, 5), fv.Frame);
  48. Application.LayoutAndDraw ();
  49. DriverAssert.AssertDriverContentsWithFrameAre (
  50. @"
  51. ┌───┐
  52. │ │
  53. │ │
  54. │ │
  55. └───┘",
  56. output
  57. );
  58. fv.X = 1;
  59. fv.Y = 2;
  60. Assert.Equal (new (1, 2, 5, 5), fv.Frame);
  61. Application.LayoutAndDraw ();
  62. DriverAssert.AssertDriverContentsWithFrameAre (
  63. @"
  64. ┌───┐
  65. │ │
  66. │ │
  67. │ │
  68. └───┘",
  69. output
  70. );
  71. fv.X = -1;
  72. fv.Y = -2;
  73. Assert.Equal (new (-1, -2, 5, 5), fv.Frame);
  74. Application.LayoutAndDraw ();
  75. DriverAssert.AssertDriverContentsWithFrameAre (
  76. @"
  77. ───┘",
  78. output
  79. );
  80. fv.X = 7;
  81. fv.Y = 8;
  82. Assert.Equal (new (7, 8, 5, 5), fv.Frame);
  83. Application.LayoutAndDraw ();
  84. DriverAssert.AssertDriverContentsWithFrameAre (
  85. @"
  86. ┌──
  87. │ ",
  88. output
  89. );
  90. top.Dispose ();
  91. }
  92. }