WindowTests.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. using System;
  2. using Xunit;
  3. using Xunit.Abstractions;
  4. using GraphViewTests = Terminal.Gui.Views.GraphViewTests;
  5. // Alias Console to MockConsole so we don't accidentally use Console
  6. using Console = Terminal.Gui.FakeConsole;
  7. namespace Terminal.Gui.Core {
  8. public class WindowTests {
  9. readonly ITestOutputHelper output;
  10. public WindowTests (ITestOutputHelper output)
  11. {
  12. this.output = output;
  13. }
  14. [Fact]
  15. public void New_Initializes ()
  16. {
  17. // Parameterless
  18. var r = new Window ();
  19. Assert.NotNull (r);
  20. Assert.Null (r.Title);
  21. Assert.Equal (LayoutStyle.Computed, r.LayoutStyle);
  22. Assert.Equal ("Window()({X=0,Y=0,Width=0,Height=0})", r.ToString ());
  23. Assert.True (r.CanFocus);
  24. Assert.False (r.HasFocus);
  25. Assert.Equal (new Rect (0, 0, 0, 0), r.Bounds);
  26. Assert.Equal (new Rect (0, 0, 0, 0), r.Frame);
  27. Assert.Null (r.Focused);
  28. Assert.NotNull (r.ColorScheme);
  29. Assert.Equal (Dim.Fill (0), r.Width);
  30. Assert.Equal (Dim.Fill (0), r.Height);
  31. // FIXED: Pos needs equality implemented
  32. Assert.Equal (Pos.At (0), r.X);
  33. Assert.Equal (Pos.At (0), r.Y);
  34. Assert.False (r.IsCurrentTop);
  35. Assert.Empty (r.Id);
  36. Assert.NotEmpty (r.Subviews);
  37. Assert.False (r.WantContinuousButtonPressed);
  38. Assert.False (r.WantMousePositionReports);
  39. Assert.Null (r.SuperView);
  40. Assert.Null (r.MostFocused);
  41. Assert.Equal (TextDirection.LeftRight_TopBottom, r.TextDirection);
  42. // Empty Rect
  43. r = new Window (Rect.Empty, "title");
  44. Assert.NotNull (r);
  45. Assert.Equal ("title", r.Title);
  46. Assert.Equal (LayoutStyle.Absolute, r.LayoutStyle);
  47. Assert.Equal ("Window()({X=0,Y=0,Width=0,Height=0})", r.ToString ());
  48. Assert.True (r.CanFocus);
  49. Assert.False (r.HasFocus);
  50. Assert.Equal (new Rect (0, 0, 0, 0), r.Bounds);
  51. Assert.Equal (new Rect (0, 0, 0, 0), r.Frame);
  52. Assert.Null (r.Focused);
  53. Assert.NotNull (r.ColorScheme);
  54. Assert.NotNull (r.Width); // All view Dim are initialized now,
  55. Assert.NotNull (r.Height); // avoiding Dim errors.
  56. Assert.NotNull (r.X); // All view Pos are initialized now,
  57. Assert.NotNull (r.Y); // avoiding Pos errors.
  58. Assert.False (r.IsCurrentTop);
  59. Assert.Empty (r.Id);
  60. Assert.NotEmpty (r.Subviews);
  61. Assert.False (r.WantContinuousButtonPressed);
  62. Assert.False (r.WantMousePositionReports);
  63. Assert.Null (r.SuperView);
  64. Assert.Null (r.MostFocused);
  65. Assert.Equal (TextDirection.LeftRight_TopBottom, r.TextDirection);
  66. // Rect with values
  67. r = new Window (new Rect (1, 2, 3, 4), "title");
  68. Assert.Equal ("title", r.Title);
  69. Assert.NotNull (r);
  70. Assert.Equal (LayoutStyle.Absolute, r.LayoutStyle);
  71. Assert.Equal ("Window()({X=1,Y=2,Width=3,Height=4})", r.ToString ());
  72. Assert.True (r.CanFocus);
  73. Assert.False (r.HasFocus);
  74. Assert.Equal (new Rect (0, 0, 3, 4), r.Bounds);
  75. Assert.Equal (new Rect (1, 2, 3, 4), r.Frame);
  76. Assert.Null (r.Focused);
  77. Assert.NotNull (r.ColorScheme);
  78. Assert.NotNull (r.Width);
  79. Assert.NotNull (r.Height);
  80. Assert.NotNull (r.X);
  81. Assert.NotNull (r.Y);
  82. Assert.False (r.IsCurrentTop);
  83. Assert.Empty (r.Id);
  84. Assert.NotEmpty (r.Subviews);
  85. Assert.False (r.WantContinuousButtonPressed);
  86. Assert.False (r.WantMousePositionReports);
  87. Assert.Null (r.SuperView);
  88. Assert.Null (r.MostFocused);
  89. Assert.Equal (TextDirection.LeftRight_TopBottom, r.TextDirection);
  90. r.Dispose();
  91. }
  92. [Fact]
  93. public void Set_Title_Fires_TitleChanging ()
  94. {
  95. var r = new Window ();
  96. Assert.Null (r.Title);
  97. string expectedAfter = null;
  98. string expectedDuring = null;
  99. bool cancel = false;
  100. r.TitleChanging += (args) => {
  101. Assert.Equal (expectedDuring, args.NewTitle);
  102. args.Cancel = cancel;
  103. };
  104. r.Title = expectedDuring = expectedAfter = "title";
  105. Assert.Equal (expectedAfter, r.Title.ToString());
  106. r.Title = expectedDuring = expectedAfter = "a different title";
  107. Assert.Equal (expectedAfter, r.Title.ToString ());
  108. // Now setup cancelling the change and change it back to "title"
  109. cancel = true;
  110. r.Title = expectedDuring = "title";
  111. Assert.Equal (expectedAfter, r.Title.ToString ());
  112. r.Dispose ();
  113. }
  114. [Fact]
  115. public void Set_Title_Fires_TitleChanged ()
  116. {
  117. var r = new Window ();
  118. Assert.Null (r.Title);
  119. string expected = null;
  120. r.TitleChanged += (args) => {
  121. Assert.Equal (r.Title, args.NewTitle);
  122. };
  123. expected = "title";
  124. r.Title = expected;
  125. Assert.Equal (expected, r.Title.ToString ());
  126. expected = "another title";
  127. r.Title = expected;
  128. Assert.Equal (expected, r.Title.ToString ());
  129. r.Dispose ();
  130. }
  131. }
  132. }